Skip to content

Commit

Permalink
TST: Add some helper code for #92 integ. tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fedarko committed Jun 20, 2019
1 parent 6934b32 commit 8efb671
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {
chai.assert.equal("21", sampleArray[5].Metadata3);
});
describe("Sample plot filters are properly set", function() {
/* Small helper function. encoding should be "xAxis" or "color",
* and newValue should be whatever the new value you want to set
* is.
*
* If isScale is truthy, this will change the "Scale" instead of
* "Field" selector (and in this case newValue can be "nominal" or
* "quantitative").
*/
async function changeEncoding(encoding, newValue, isScale) {
var fieldName;
if (isScale) {
fieldName = encoding + "Scale";
} else {
fieldName = encoding + "Field";
}
document.getElementById(fieldName).value = newValue;
await document.getElementById(fieldName).onchange();
}
// NOTE: if we get around to removing the redundancy in the
// filters generated when x-axis and color fields are equal,
// these tests will need to be changed accordingly.
Expand All @@ -74,8 +92,7 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {

// Try changing the color field to Metadata2, and verify that
// the filters are updated accordingly
document.getElementById("colorField").value = "Metadata2";
await document.getElementById("colorField").onchange();
await changeEncoding("color", "Metadata2");
chai.assert.equal(
"datum.qurro_balance != null && " +
'datum["Metadata1"] != null && ' +
Expand All @@ -85,8 +102,7 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {

// Try changing the x-axis field to Sample ID, and verify that
// the filters are again updated accordingly
document.getElementById("xAxisField").value = "Sample ID";
await document.getElementById("xAxisField").onchange();
await changeEncoding("xAxis", "Sample ID");
chai.assert.equal(
"datum.qurro_balance != null && " +
'datum["Sample ID"] != null && ' +
Expand All @@ -95,8 +111,7 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {
);
});
it("When x-axis is quantitative and color is categorical", async function() {
document.getElementById("xAxisScale").value = "quantitative";
await document.getElementById("xAxisScale").onchange();
await changeEncoding("xAxis", "quantitative", true);
chai.assert.equal(
"datum.qurro_balance != null && " +
'datum["Metadata1"] != null && ' +
Expand All @@ -106,8 +121,7 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {
);

// Change color field and verify filters updated accordingly
document.getElementById("colorField").value = "Metadata2";
await document.getElementById("colorField").onchange();
await changeEncoding("color", "Metadata2");
chai.assert.equal(
"datum.qurro_balance != null && " +
'datum["Metadata1"] != null && ' +
Expand All @@ -117,8 +131,7 @@ define(["display", "mocha", "chai"], function(display, mocha, chai) {
);

// Change x-axis field and verify filters updated accordingly
document.getElementById("xAxisField").value = "Sample ID";
await document.getElementById("xAxisField").onchange();
await changeEncoding("xAxis", "Sample ID");
chai.assert.equal(
"datum.qurro_balance != null && " +
'datum["Sample ID"] != null && ' +
Expand Down

0 comments on commit 8efb671

Please sign in to comment.