-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathevent.mouse.spec.ts
More file actions
87 lines (75 loc) · 2.03 KB
/
Copy pathevent.mouse.spec.ts
File metadata and controls
87 lines (75 loc) · 2.03 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
import { Canvas, Circle } 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,
supportsPointerEvents: false, // disable pointer event
});
describe.skip('Event API', () => {
afterEach(() => {
canvas.destroyChildren();
});
afterAll(() => {
canvas.destroy();
});
it('should emit mouseup 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(100);
const mouseupCallback = jest.fn();
circle.addEventListener('mouseup', mouseupCallback);
const $canvas = canvas
.getContextService()
.getDomElement() as HTMLCanvasElement;
$canvas.dispatchEvent(
new MouseEvent('mouseup', {
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,
}),
);
// wait event propgation, especially for picking in an async way
await sleep(100);
expect(mouseupCallback).toBeCalled();
});
});