Skip to content

Commit 6f06385

Browse files
committed
Zoom: Add test while scrolling
1 parent e40c326 commit 6f06385

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

test/jasmine/assets/mouse_event.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ module.exports = function(type, x, y, opts) {
1010
fullOpts.buttons = opts.buttons;
1111
}
1212

13-
var el = document.elementFromPoint(x, y);
14-
var ev = new window.MouseEvent(type, fullOpts);
13+
var el = document.elementFromPoint(x, y),
14+
ev;
15+
16+
if(type === 'scroll') {
17+
ev = new window.WheelEvent('wheel', opts);
18+
} else {
19+
ev = new window.MouseEvent(type, fullOpts);
20+
}
21+
1522
el.dispatchEvent(ev);
1623
};

test/jasmine/tests/click_test.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,37 @@ describe('Test click interactions:', function() {
711711
});
712712
});
713713

714+
describe('scroll zoom interactions', function() {
715+
716+
beforeEach(function(done) {
717+
Plotly.plot(gd, mockCopy.data, mockCopy.layout, { scrollZoom: true }).then(done);
718+
});
719+
720+
it('zooms in on scroll up', function() {
721+
722+
var plot = gd._fullLayout._plots.xy.plot;
723+
724+
mouseEvent('mousemove', 400, 250);
725+
mouseEvent('scroll', 400, 250, { deltaX: 0, deltaY: -1000 });
726+
727+
var transform = plot.attr('transform');
728+
729+
console.log(transform);
730+
731+
var mockEl = {
732+
attr: function() {
733+
return transform;
734+
}
735+
};
736+
737+
var translate = Lib.getTranslate(mockEl),
738+
scale = Lib.getScale(mockEl);
739+
740+
expect([translate.x, translate.y]).toBeCloseToArray([62.841, 99.483]);
741+
expect([scale.x, scale.y]).toBeCloseToArray([1.221, 1.221]);
742+
});
743+
});
744+
714745
describe('pan interactions', function() {
715746
beforeEach(function(done) {
716747
mockCopy.layout.dragmode = 'pan';
@@ -745,7 +776,7 @@ describe('Test click interactions:', function() {
745776
mouseEvent('mousedown', start, start);
746777
mouseEvent('mousemove', end, end);
747778

748-
expect(plot.attr('transform')).toBe('translate(250, 280)');
779+
expect(plot.attr('transform')).toBe('translate(250, 280) scale(1, 1)');
749780

750781
mouseEvent('mouseup', end, end);
751782
});

0 commit comments

Comments
 (0)