Skip to content

Commit 5fe96ec

Browse files
committed
Added test to cover #5855
1 parent e9953c1 commit 5fe96ec

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

draftlogs/5856_add.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- Add touch support to slider [[#5856](https://github.com/plotly/plotly.js/pull/5856)]
1+
- Add touch support to `slider` component [[#5856](https://github.com/plotly/plotly.js/pull/5856)],
2+
with thanks to @keul for the contribution!

test/jasmine/assets/touch_event.js

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module.exports = function(type, x, y, opts) {
99
target: el,
1010
clientX: x,
1111
clientY: y,
12+
screenX: x,
13+
screenY: y,
14+
pageX: x,
15+
pageY: y,
1216
radiusX: 2.5,
1317
radiusY: 2.5,
1418
rotationAngle: 10,

test/jasmine/tests/sliders_test.js

+39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Plotly = require('@lib/index');
77
var Lib = require('@src/lib');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var touchEvent = require('../assets/touch_event');
1011

1112
var delay = require('../assets/delay');
1213
var assertPlotSize = require('../assets/custom_assertions').assertPlotSize;
@@ -507,6 +508,44 @@ describe('sliders interactions', function() {
507508
.then(done, done.fail);
508509
});
509510

511+
it('should respond to touch interactions', function(done) {
512+
var firstGroup = gd._fullLayout._infolayer.select('.' + constants.railTouchRectClass);
513+
var firstGrip = gd._fullLayout._infolayer.select('.' + constants.gripRectClass);
514+
var railNode = firstGroup.node();
515+
var gripNode = firstGrip.node();
516+
var touchRect = railNode.getBoundingClientRect();
517+
var gripRect = gripNode.getBoundingClientRect();
518+
519+
var originalFill = gripNode.style.fill;
520+
521+
expect(mockCopy.layout.sliders[0].active).toEqual(2);
522+
523+
// Dispatch start of touch where the grip control is
524+
touchEvent('touchstart', gripRect.left + 5, gripRect.top + 5);
525+
526+
expect(mockCopy.layout.sliders[0].active).toEqual(2);
527+
var touchdownFill = gripNode.style.fill;
528+
expect(touchdownFill).not.toEqual(originalFill);
529+
530+
// Drag to the right side:
531+
touchEvent('touchmove', touchRect.left + touchRect.width - 5, gripRect.top + 5);
532+
533+
var touchmoveFill = gripNode.style.fill;
534+
expect(touchmoveFill).toEqual(touchdownFill);
535+
536+
delay(100)()
537+
.then(function() {
538+
expect(mockCopy.layout.sliders[0].active).toEqual(5);
539+
540+
touchEvent('touchend', touchRect.left + touchRect.width - 5, gripRect.top + 5);
541+
542+
var touchupFill = gripNode.style.fill;
543+
expect(touchupFill).toEqual(originalFill);
544+
expect(mockCopy.layout.sliders[0].active).toEqual(5);
545+
})
546+
.then(done, done.fail);
547+
});
548+
510549
it('should issue events on interaction', function(done) {
511550
var cntStart = 0;
512551
var cntInteraction = 0;

0 commit comments

Comments
 (0)