Skip to content

Commit

Permalink
make double click simulator return a promise,
Browse files Browse the repository at this point in the history
- to more easily chain actions in click tests
  • Loading branch information
etpinard committed Mar 23, 2016
1 parent c29e81e commit a7cc9dd
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 76 deletions.
3 changes: 3 additions & 0 deletions test/jasmine/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"env": {
"browser": true,
"jasmine": true
},
"globals": {
"Promise": true
}
}
157 changes: 81 additions & 76 deletions test/jasmine/tests/click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var mouseEvent = require('../assets/mouse_event');
var customMatchers = require('../assets/custom_matchers');


describe('click interactions', function() {
describe('Test click interactions:', function() {
var mock = require('@mocks/14.json'),
gd;

Expand All @@ -26,12 +26,15 @@ describe('click interactions', function() {
mouseEvent('mouseup', x, y);
}

function doubleClick(x, y, cb) {
click(x, y);
setTimeout(function() {
function doubleClick(x, y) {
return new Promise(function(resolve) {
click(x, y);
cb();
}, DBLCLICKDELAY / 2);

setTimeout(function() {
click(x, y);
resolve();
}, DBLCLICKDELAY / 2);
});
}

describe('click events', function() {
Expand Down Expand Up @@ -87,7 +90,7 @@ describe('click interactions', function() {
});

it('should return null', function(done) {
doubleClick(pointPos[0], pointPos[1], function() {
doubleClick(pointPos[0], pointPos[1]).then(function() {
expect(futureData).toBe(null);
done();
});
Expand Down Expand Up @@ -139,12 +142,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
done();
});
});
});
Expand All @@ -156,17 +159,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});

Expand All @@ -177,17 +180,19 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});
});
});

Expand All @@ -196,17 +201,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -217,17 +222,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
});
done();
});
});

Expand All @@ -238,12 +243,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

done();
});
done();
});
});

Expand All @@ -252,17 +257,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -273,17 +278,17 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

Plotly.relayout(gd, update).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
return Plotly.relayout(gd, update);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
});
done();
});
});

Expand All @@ -294,12 +299,12 @@ describe('click interactions', function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(setRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(setRangeY);

doubleClick(blankPos[0], blankPos[1], function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
return doubleClick(blankPos[0], blankPos[1]);
}).then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);

done();
});
done();
});
});

Expand Down

0 comments on commit a7cc9dd

Please sign in to comment.