Skip to content

Commit cf52bda

Browse files
committed
Add a test
1 parent 0dadb11 commit cf52bda

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/specs/zoom.drag.spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,60 @@ describe('zoom with drag', function() {
396396
}
397397
});
398398

399+
describe('coordinate handling', function() {
400+
it('handles dragging to the right edge of the chart', function() {
401+
chart = window.acquireChart({
402+
type: 'line',
403+
data,
404+
options: {
405+
scales: {
406+
xScale0: {
407+
id: 'xScale0',
408+
type: 'linear',
409+
min: 0,
410+
max: 4
411+
},
412+
yScale0: {
413+
id: 'yScale0',
414+
type: 'linear',
415+
min: 0,
416+
max: 4,
417+
}
418+
},
419+
plugins: {
420+
zoom: {
421+
zoom: {
422+
drag: {
423+
enabled: true
424+
},
425+
mode: 'xy'
426+
}
427+
}
428+
}
429+
}
430+
}, {
431+
wrapper: {style: 'position: absolute; left: 50px; top: 50px;'}
432+
});
433+
434+
scaleX = chart.scales.xScale0;
435+
scaleY = chart.scales.yScale0;
436+
437+
jasmine.triggerMouseEvent(chart, 'mousedown', {
438+
x: scaleX.getPixelForValue(1.5),
439+
y: scaleY.getPixelForValue(1.2)
440+
});
441+
jasmine.triggerMouseEvent(chart, 'mouseup', {
442+
x: scaleX.getPixelForValue(4) + 5,
443+
y: scaleY.getPixelForValue(1.7)
444+
});
445+
446+
expect(scaleX.options.min).toBeCloseTo(1.5);
447+
expect(scaleX.options.max).toBeCloseTo(4);
448+
expect(scaleY.options.min).toBeCloseTo(1.2);
449+
expect(scaleY.options.max).toBeCloseTo(1.7);
450+
});
451+
});
452+
399453
describe('events', function() {
400454
it('should call onZoomStart, onZoom and onZoomComplete', function(done) {
401455
const startSpy = jasmine.createSpy('start');

0 commit comments

Comments
 (0)