-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathevent.wheel.spec.ts
More file actions
152 lines (133 loc) · 3.58 KB
/
Copy pathevent.wheel.spec.ts
File metadata and controls
152 lines (133 loc) · 3.58 KB
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
import { Canvas, Circle, FederatedWheelEvent } from '../../packages/g/src';
import { Renderer as CanvasRenderer } from '../../packages/g-svg/src';
import { Plugin } from '../../packages/g-plugin-css-select/src';
import { sleep } from './utils';
const $container = document.createElement('div');
$container.id = 'container';
document.body.prepend($container);
const renderer = new CanvasRenderer();
renderer.registerPlugin(new Plugin());
// create a canvas
const canvas = new Canvas({
container: 'container',
width: 600,
height: 500,
renderer,
});
describe.skip('Event API', () => {
afterEach(() => {
canvas.destroyChildren();
});
afterAll(() => {
canvas.destroy();
});
it('should trigger wheel event correctly', async () => {
const circle = new Circle({
id: 'circle',
style: {
fill: 'rgb(239, 244, 255)',
fillOpacity: 1,
lineWidth: 1,
opacity: 1,
r: 50,
stroke: 'rgb(95, 149, 255)',
strokeOpacity: 1,
cursor: 'pointer',
},
});
circle.setPosition(300, 200);
await canvas.ready;
canvas.appendChild(circle);
const wheelCallback = jest.fn();
circle.addEventListener('wheel', wheelCallback);
const $canvas = canvas
.getContextService()
.getDomElement() as HTMLCanvasElement;
await sleep(100);
$canvas.dispatchEvent(
new WheelEvent('wheel', {
altKey: false,
bubbles: true,
button: 0,
buttons: 1,
cancelable: true,
clientX: 295.3359375,
clientY: 201.03515625,
composed: true,
ctrlKey: false,
detail: 0,
metaKey: false,
movementX: 0,
movementY: 0,
relatedTarget: null,
screenX: 295.3359375,
screenY: 254.03515625,
shiftKey: false,
view: window,
which: 1,
deltaX: 10,
}),
);
// wait event propgation, especially for picking in an async way
await sleep(100);
expect(wheelCallback).toBeCalled();
});
it('should clone wheel event correctly', async () => {
const circle = new Circle({
id: 'circle',
style: {
fill: 'rgb(239, 244, 255)',
fillOpacity: 1,
lineWidth: 1,
opacity: 1,
r: 50,
stroke: 'rgb(95, 149, 255)',
strokeOpacity: 1,
cursor: 'pointer',
},
});
circle.setPosition(300, 200);
await canvas.ready;
canvas.appendChild(circle);
await sleep(200);
let cloned: FederatedWheelEvent = null as unknown as FederatedWheelEvent;
circle.addEventListener('wheel', (event: FederatedWheelEvent) => {
cloned = event.clone();
});
const $canvas = canvas
.getContextService()
.getDomElement() as HTMLCanvasElement;
// trigger native pointerdown event
$canvas.dispatchEvent(
new WheelEvent('wheel', {
altKey: false,
bubbles: true,
button: 0,
buttons: 1,
cancelable: true,
clientX: 295.3359375,
clientY: 201.03515625,
composed: true,
ctrlKey: false,
detail: 0,
metaKey: false,
movementX: 0,
movementY: 0,
relatedTarget: null,
screenX: 295.3359375,
screenY: 254.03515625,
shiftKey: false,
view: window,
which: 1,
deltaX: 10,
}),
);
await sleep(1000);
expect(cloned.type).toBe('wheel');
expect(cloned.button).toBe(0);
expect(cloned.clientX).toBe(295);
expect(cloned.clientY).toBe(201);
expect(cloned.deltaX).toBe(10);
expect(cloned.target).toBe(circle);
});
});