-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-controller.js
986 lines (986 loc) · 36.4 KB
/
test-controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
/*!*
*
* Copyright (c) Highsoft AS. All rights reserved.
*
*!*/
/* *
*
* Classes
*
* */
/**
* The test controller makes it easy to emulate mouse and touch stuff on the
* chart.
*
* @example
* // Instanciate
* var controller = new TestController(chart);
*
* // Simulate a panning operation
* controller.pan([200, 100], [150, 100], { shiftKey: true });
*/
var TestController = /** @class */ (function () {
/* *
*
* Constructor
*
* */
/**
* The test controller makes it easy to emulate mouse and touch stuff on the
* chart.
*
* @param chart
* Chart to control
*/
function TestController(chart) {
if (!(this instanceof TestController)) {
return new TestController(chart);
}
this.chart = chart;
this.mouseEnterStack = [];
this.positionX = 0;
this.positionY = 0;
this.relatedTarget = null;
this.setPosition();
}
/* *
*
* Static Functions
*
* */
/**
* Mock a TochList element with required internal methods.
*
* @param arr
* The list of touches.
*/
TestController.createTouchList = function (positions) {
positions.item = function (i) {
return this[i];
};
return positions;
};
/**
* Returns all points between a movement.
*
* @param a
* First point as [x, y] tuple.
*
* @param b
* Second point as [x, y] tuple.
*
* @param interval
* The distance between points.
*/
TestController.getPointsBetween = function (a, b, interval) {
if (interval === void 0) { interval = 1; }
var points = [];
var complete = false, x1 = a[0], y1 = a[1], x2 = b[0], y2 = b[1], deltaX, deltaY, distance, ratio, moveX, moveY;
points.push([x1, y1]);
while (!complete) {
deltaX = x2 - x1;
deltaY = y2 - y1;
distance = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
if (distance > interval) {
ratio = interval / distance;
moveX = ratio * deltaX;
moveY = ratio * deltaY;
x1 += moveX;
y1 += moveY;
points.push([x1, y1]);
}
else {
points.push([b[0], b[1]]);
complete = true;
}
}
return points;
};
/* *
*
* Functions
*
* */
/**
* Simulates a mouse click.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.click = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = void 0; }
if (debug === void 0) { debug = false; }
this.mouseDown(chartX, chartY, extra, debug);
this.mouseUp(chartX, chartY, extra, debug);
this.triggerEvent('click', chartX, chartY, extra, debug);
};
TestController.prototype.createEvent = function (type, chartX, chartY, extra) {
var _a, _b;
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = void 0; }
var chartOffset = Highcharts.offset(this.chart.container);
var evt;
if (document.createEvent) {
evt = document.createEvent('Events');
evt.initEvent(type, true, true);
}
else {
evt = new Event(type, {
bubbles: ((_a = extra.bubbles) !== null && _a !== void 0 ? _a : true),
cancelable: ((_b = extra.cancelable) !== null && _b !== void 0 ? _b : true)
});
}
extra = (extra || {});
extra.pageX = (chartOffset.left + chartX);
extra.pageY = (chartOffset.top + chartY);
switch (type) {
case 'click':
case 'dblclick':
case 'mousedown':
case 'mouseup':
if (typeof extra.button === 'undefined') {
extra.button = TestController.MouseButtons.left;
}
break;
case 'mouseenter':
case 'mouseleave':
extra.bubbles = false;
extra.cancelable = false;
break;
}
if (typeof extra.buttons === 'undefined') {
extra.buttons = (TestController.MouseButtonsBitMap[extra.button] || 0);
}
Object.keys(extra).forEach(function (key) {
evt[key] = extra[key];
});
return evt;
};
/**
* Get the element from a point on the chart.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*/
TestController.prototype.elementFromPoint = function (chartX, chartY, useMSWorkaround) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (useMSWorkaround === void 0) { useMSWorkaround = true; }
var chartOffset = Highcharts.offset(this.chart.container);
var clipPaths;
if (useMSWorkaround) {
clipPaths = this.setUpMSWorkaround();
}
var element = document.elementFromPoint((chartOffset.left + chartX), (chartOffset.top + chartY));
if (element && getComputedStyle(element).pointerEvents === 'none') {
element = this.elementsFromPoint(chartX, chartY, useMSWorkaround)[0];
}
// Reset clip paths for Edge and IE
if (clipPaths) {
this.tearDownMSWorkaround(clipPaths);
}
return element;
};
TestController.prototype.elementsFromPoint = function (chartX, chartY, useMSWorkaround) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (useMSWorkaround === void 0) { useMSWorkaround = true; }
var chartOffset = Highcharts.offset(this.chart.container);
var clipPaths;
if (useMSWorkaround) {
clipPaths = this.setUpMSWorkaround();
}
var elements = document
.elementsFromPoint((chartOffset.left + chartX), (chartOffset.top + chartY))
.filter(function (element) { return (getComputedStyle(element).pointerEvents !== 'none'); });
// Reset clip paths for Edge and IE
if (clipPaths) {
this.tearDownMSWorkaround(clipPaths);
}
return elements;
};
/**
* Get the current position of the cursor.
*/
TestController.prototype.getPosition = function () {
return {
x: this.positionX,
y: this.positionY,
relatedTarget: this.relatedTarget
};
};
/**
* Triggers an event.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseDown = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.triggerEvent('mousedown', chartX, chartY, extra, debug);
};
/**
* Triggers mouse enter event on all necessary elements.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseEnter = function (newPosition, oldPosition, extra, debug) {
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var oldStack = this.elementsFromPoint(oldPosition[0], oldPosition[1]);
var newStack = this.elementsFromPoint(newPosition[0], newPosition[1]);
var newElement = newStack[0];
if (debug) {
this.setDebugMark(newPosition[0], newPosition[1], TestController.DebugMarkTypes.normal);
}
var element;
while (element = newStack.pop()) {
if (oldStack.indexOf(element) !== -1) {
continue;
}
extra.currentTarget = element;
extra.target = newElement;
element.dispatchEvent(this.createEvent('mouseenter', newPosition[0], newPosition[1], extra));
}
// Make sure to fire always for the top SVG element
if (newElement instanceof SVGElement &&
oldStack.indexOf(newElement) !== -1) {
extra.currentTarget = newElement;
extra.target = newElement;
newElement.dispatchEvent(this.createEvent('mouseenter', newPosition[0], newPosition[1], extra));
}
};
/**
* Triggers mouse enter event on all elements, that are missing on the
* provided new position.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseLeave = function (newPosition, oldPosition, extra, debug) {
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var oldStack = this.elementsFromPoint(oldPosition[0], oldPosition[1]);
var oldElement = oldStack[0];
var newStack = this.elementsFromPoint(newPosition[0], newPosition[1]);
var newElement = newStack[0];
if (debug) {
this.setDebugMark(newPosition[0], newPosition[1], TestController.DebugMarkTypes.normal);
}
var element;
while (element = oldStack.shift()) {
if (newStack.indexOf(element) !== -1) {
continue;
}
extra.currentTarget = element;
extra.target = newElement;
element.dispatchEvent(this.createEvent('mouseleave', oldPosition[0], oldPosition[1], extra));
}
// Make sure to fire always for the top SVG element
if (oldElement instanceof SVGElement &&
newStack.indexOf(oldElement) !== -1) {
extra.currentTarget = oldElement;
extra.target = newElement;
oldElement.dispatchEvent(this.createEvent('mouseleave', oldPosition[0], oldPosition[1], extra));
}
};
/**
* Triggers an event.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseMove = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.triggerEvent('mousemove', chartX, chartY, extra, debug);
};
/**
* Triggers an event.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseOut = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.triggerEvent('mouseout', chartX, chartY, extra, debug);
};
/**
* Triggers an event.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseOver = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.triggerEvent('mouseover', chartX, chartY, extra, debug);
};
/**
* Triggers an event.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.mouseUp = function (chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.triggerEvent('mouseup', chartX, chartY, extra, debug);
};
/**
* Move the cursor from current position to a new one. Fire a series of
* mousemoves, also mouseout and mouseover if new targets are found.
*
* @param chartX
* New x position on the chart.
*
* @param chartY
* New y position on the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.moveTo = function (chartX, chartY, extra, debug) {
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var points = TestController.getPointsBetween([this.positionX, this.positionY], [chartX, chartY]);
var point, oldPoint, oldTarget, target;
var clipPaths = this.setUpMSWorkaround();
for (var i = 0, ie = points.length; i < ie; ++i) {
oldPoint = [this.positionX, this.positionY];
oldTarget = this.relatedTarget;
point = points[i];
this.setPosition(point[0], point[1], false);
target = this.relatedTarget;
if (!target) {
continue;
}
if (oldTarget &&
target !== oldTarget) {
// First trigger a mouseout on the old target.
this.mouseOut(oldPoint[0], oldPoint[1], Highcharts.merge({
currentTarget: oldTarget,
relatedTarget: target,
target: target
}, extra));
this.mouseLeave(point, oldPoint, Highcharts.merge({
currentTarget: oldTarget,
relatedTarget: target,
target: target
}, extra));
// Then trigger a mouseover on the new target.
this.mouseOver(point[0], point[1], Highcharts.merge({
relatedTarget: target,
target: target
}, extra));
this.mouseEnter(point, oldPoint, Highcharts.merge({
relatedTarget: target,
target: target
}, extra));
}
this.mouseMove(point[0], point[1], extra, debug);
}
this.tearDownMSWorkaround(clipPaths);
};
/**
* Simulates a mouse pan action between two points.
*
* @param startPoint
* Starting point with x and y values relative to the chart.
*
* @param endPoint
* Ending point with x any y values relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.pan = function (startPoint, endPoint, extra, debug) {
if (startPoint === void 0) { startPoint = [this.positionX, this.positionY]; }
if (endPoint === void 0) { endPoint = [this.positionX, this.positionY]; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
this.setPosition(startPoint[0], startPoint[1]);
this.mouseDown(startPoint[0], startPoint[1], extra, debug);
this.moveTo(endPoint[0], endPoint[1], extra, debug);
this.mouseUp(endPoint[0], endPoint[1], extra, debug);
};
/**
* Simulates a pinch gesture.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param distance
* Distance between the two fingers. Negative values indicate, that the
* fingers move to each other.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.pinch = function (chartX, chartY, distance, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (distance === void 0) { distance = 10; }
if (debug === void 0) { debug = false; }
var startPoint1, startPoint2, endPoint1, endPoint2;
distance = Math.round(distance / 2);
if (distance < 0) {
distance = (-1 * distance);
distance = (distance > 10 ? distance : 11);
startPoint1 = [(chartX - distance), (chartY - distance)];
startPoint2 = [(chartX + distance), (chartY + distance)];
endPoint1 = [(chartX - 11), (chartY - 11)];
endPoint2 = [(chartX + 11), (chartY + 11)];
}
else {
distance = (distance > 10 ? distance : 11);
startPoint1 = [(chartX - 11), (chartY - 11)];
startPoint2 = [(chartX + 11), (chartY + 11)];
endPoint1 = [(chartX - distance), (chartY - distance)];
endPoint2 = [(chartX + distance), (chartY + distance)];
}
var movePoints1 = TestController.getPointsBetween(startPoint1, endPoint1, 1);
var movePoints2 = TestController.getPointsBetween(startPoint2, endPoint2, 1);
var target = this.elementFromPoint(chartX, chartY);
var extra, movePoint1, movePoint2;
for (var i = 0, ie = (movePoints1.length - 1); i <= ie; ++i) {
movePoint1 = movePoints1[i];
movePoint2 = movePoints2[i];
extra = {
relatedTarget: target,
touches: TestController.createTouchList([
{ pageX: movePoint1[0], pageY: movePoint1[1] },
{ pageX: movePoint2[0], pageY: movePoint2[1] }
])
};
if (i === 0) {
this.touchStart(chartX, chartY, undefined, extra, debug);
}
this.touchMove(chartX, chartY, undefined, extra, debug);
if (i === ie) {
this.touchEnd(chartX, chartY, undefined, extra, debug);
}
}
};
/**
* Leave marks for debugging purposes.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*/
TestController.prototype.setDebugMark = function (chartX, chartY, type) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (type === void 0) { type = TestController.DebugMarkTypes.normal; }
var marker = this.chart.renderer
.circle(chartX, chartY, (type === TestController.DebugMarkTypes.movement ? 2 : 3))
.attr({
fill: 'white',
stroke: (type === TestController.DebugMarkTypes.movement ?
'blue' :
type === TestController.DebugMarkTypes.activation ?
'green' :
'red'),
'stroke-width': (type === TestController.DebugMarkTypes.movement ? 1 : 2),
zIndex: 100
});
return marker
.css({
'pointer-events': 'none'
})
.add();
};
/**
* Move the cursor position to a new position, without firing events.
*
* @param chartX
* New x position on the chart.
*
* @param chartY
* New y position on the chart.
*
* @param useMSWorkaround
* Whether to do additional operations to work around IE problems.
*/
TestController.prototype.setPosition = function (chartX, chartY, useMSWorkaround) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
this.positionX = chartX;
this.positionY = chartY;
this.relatedTarget = this.elementFromPoint(chartX, chartY, useMSWorkaround);
};
/**
* Edge and IE are unable to get elementFromPoint when the group has a
* clip path. It reports the first underlying element with no clip path.
*/
TestController.prototype.setUpMSWorkaround = function () {
var clipPaths = {
elements: [],
values: []
};
if (/(Trident|Edge)/.test(window.navigator.userAgent)) {
[].slice
.call(document.querySelectorAll('[clip-path],[CLIP-PATH]'))
.forEach(function (elemCP) {
clipPaths.elements.push(elemCP);
clipPaths.values.push(elemCP.getAttribute('clip-path'));
elemCP.removeAttribute('clip-path');
});
}
return clipPaths;
};
/**
* Simulates a slide gesture between two points.
*
* @param startPoint
* Starting point on the chart with x and y value.
*
* @param endPoint
* Ending point on the chart with x any y value.
*
* @param twoFingers
* Whether to use one or two fingers for the gesture.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.slide = function (startPoint, endPoint, twoFingers, debug) {
if (startPoint === void 0) { startPoint = [this.positionX, this.positionY]; }
if (endPoint === void 0) { endPoint = [this.positionX, this.positionY]; }
if (twoFingers === void 0) { twoFingers = false; }
if (debug === void 0) { debug = false; }
var movePoints = TestController
.getPointsBetween(startPoint, endPoint);
this.touchStart(startPoint[0], startPoint[1], twoFingers, undefined, debug);
var movePoint;
for (var i = 0, ie = movePoints.length; i < ie; ++i) {
movePoint = movePoints[i];
this.touchMove(movePoint[0], movePoint[1], twoFingers, undefined, debug);
}
this.touchEnd(endPoint[0], endPoint[1], twoFingers, undefined, debug);
};
/**
* Simulates a tap action with a finger.
*
* @param chartX
* X position to tab on.
*
* @param chartY
* Y position to tab on.
*
* @param twoFingers
* Whether to use one or two fingers for the gesture.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.tap = function (chartX, chartY, twoFingers, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (twoFingers === void 0) { twoFingers = false; }
if (debug === void 0) { debug = false; }
this.touchStart(chartX, chartY, twoFingers, undefined, debug);
this.touchEnd(chartX, chartY, twoFingers, undefined, debug);
};
/**
* Undo the workaround for Edge and IE.
*
* @param clipPaths
* The clip paths that were returned from the `setUpMSWorkaround` function.
*/
TestController.prototype.tearDownMSWorkaround = function (clipPaths) {
// Reset clip paths for Edge and IE
if (clipPaths) {
clipPaths.elements.forEach(function (elemCP, i) {
elemCP.setAttribute('clip-path', clipPaths.values[i]);
});
}
};
/**
* Triggers touch ends events.
*
* @param chartX
* X position on the chart.
*
* @param chartY
* Y position on the chart.
*
* @param twoFingers
* Whether to use one or two fingers for the gesture.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.touchEnd = function (chartX, chartY, twoFingers, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (twoFingers === void 0) { twoFingers = false; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var target = (this.elementFromPoint(chartX, chartY) || undefined);
extra = (extra || {});
extra.preventDefault = (extra.preventDefault || function () { });
extra.relatedTarget = (extra.relatedTarget || target);
if (twoFingers === true) {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: (chartX - 11), pageY: (chartY - 11) },
{ pageX: (chartX + 11), pageY: (chartY + 11) }
]));
}
else {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: chartX, pageY: chartY }
]));
}
this.triggerEvent('touchend', chartX, chartY, extra, debug);
if (Highcharts.Pointer) {
this.triggerEvent('pointerup', chartX, chartY, extra, debug);
}
else if (Highcharts.MSPointer) {
this.triggerEvent('MSPointerUp', chartX, chartY, extra, debug);
}
};
/**
* Triggers touch move events.
*
* @param chartX
* X position on the chart.
*
* @param chartY
* Y position on the chart.
*
* @param twoFingers
* Whether to use one or two fingers for the gesture.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.touchMove = function (chartX, chartY, twoFingers, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (twoFingers === void 0) { twoFingers = false; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var target = this.elementFromPoint(chartX, chartY);
extra = (extra || {});
extra.preventDefault = (extra.preventDefault || function () { });
extra.relatedTarget = (extra.relatedTarget || target);
if (twoFingers === true) {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: (chartX - 11), pageY: (chartY - 11) },
{ pageX: (chartX + 11), pageY: (chartY + 11) }
]));
}
else {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: chartX, pageY: chartY }
]));
}
if (Highcharts.Pointer) {
this.triggerEvent('pointermove', chartX, chartY, extra, debug);
}
else if (Highcharts.MSPointer) {
this.triggerEvent('MSPointerMove', chartX, chartY, extra, debug);
}
this.triggerEvent('touchmove', chartX, chartY, extra, debug);
};
/**
* Triggers touch starts events.
*
* @param chartX
* X position on the chart.
*
* @param chartY
* Y position on the chart.
*
* @param twoFingers
* Whether to use one or two fingers for the gesture.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.touchStart = function (chartX, chartY, twoFingers, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (twoFingers === void 0) { twoFingers = false; }
if (extra === void 0) { extra = undefined; }
if (debug === void 0) { debug = false; }
var target = this.elementFromPoint(chartX, chartY);
extra = (extra || {});
extra.preventDefault = (extra.preventDefault || function () { });
extra.relatedTarget = (extra.relatedTarget || target);
if (twoFingers === true) {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: (chartX - 11), pageY: (chartY - 11) },
{ pageX: (chartX + 11), pageY: (chartY + 11) }
]));
}
else {
extra.touches = (extra.touches ||
TestController.createTouchList([
{ pageX: chartX, pageY: chartY }
]));
}
this.triggerEvent('touchstart', chartX, chartY, extra, debug);
if (Highcharts.Pointer) {
this.triggerEvent('pointerdown', chartX, chartY, extra, debug);
}
else if (Highcharts.MSPointer) {
this.triggerEvent('MSPointerDown', chartX, chartY, extra, debug);
}
};
/**
* Trigger an event. The target element will be found based on the chart
* coordinates. This function is called behind the shorthand functions
* like .click() and .mousemove().
*
* @param type
* Event type.
*
* @param chartX
* X relative to the chart.
*
* @param chartY
* Y relative to the chart.
*
* @param extra
* Extra properties for the event arguments, for example
* `{ shiftKey: true }` to emulate that the shift key has been pressed in a
* mouse event.
*
* @param debug
* Add marks where the event was triggered. Should not be enabled in
* production, as it slows down the test and also leaves an element that
* might catch events and mess up the test result.
*/
TestController.prototype.triggerEvent = function (type, chartX, chartY, extra, debug) {
if (chartX === void 0) { chartX = this.positionX; }
if (chartY === void 0) { chartY = this.positionY; }
if (extra === void 0) { extra = {}; }
if (debug === void 0) { debug = false; }
// Find an element related to the coordinates and fire event.
var element = ((extra && extra.currentTarget) ||
(extra && extra.target) ||
this.elementFromPoint(chartX, chartY));
if (!element) {
return;
}
// Leave marks for debugging
if (debug) {
this.setDebugMark(chartX, chartY, type === 'mousemove' ?
TestController.DebugMarkTypes.movement :
type === 'mousedown' ?
TestController.DebugMarkTypes.activation :
TestController.DebugMarkTypes.normal);
}
if (typeof extra.currentTarget === 'undefined') {
extra.currentTarget = element;
}
if (typeof extra.target === 'undefined') {
extra.target = element;
}
element.dispatchEvent(this.createEvent(type, chartX, chartY, extra));
};
return TestController;
}());
(function (TestController) {
/* *
*
* Enums
*
* */
var DebugMarkTypes;
(function (DebugMarkTypes) {
DebugMarkTypes[DebugMarkTypes["activation"] = 0] = "activation";
DebugMarkTypes[DebugMarkTypes["movement"] = 1] = "movement";
DebugMarkTypes[DebugMarkTypes["normal"] = 2] = "normal";
})(DebugMarkTypes = TestController.DebugMarkTypes || (TestController.DebugMarkTypes = {}));
var MouseButtons;
(function (MouseButtons) {
MouseButtons[MouseButtons["left"] = 0] = "left";
MouseButtons[MouseButtons["middle"] = 1] = "middle";
MouseButtons[MouseButtons["right"] = 2] = "right";
})(MouseButtons = TestController.MouseButtons || (TestController.MouseButtons = {}));
TestController.MouseButtonsBitMap = {
0: 1,
1: 4,
2: 2,
3: 8,
4: 16,
};
})(TestController || (TestController = {}));