forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathis-shaken.test.ts
More file actions
45 lines (34 loc) · 1.49 KB
/
is-shaken.test.ts
File metadata and controls
45 lines (34 loc) · 1.49 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
import { isShaken } from '../../src/is-shaken';
describe('isShaken', () => {
it('should return true if e1 has shaken property', () => {
const e1: any = { shaken: true };
const e2: MouseEvent | DragEvent = { target: null } as MouseEvent | DragEvent;
expect(isShaken(e1, e2)).toBe(true);
});
it('should return true if e1.target and e2.target are different', () => {
const e1: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent;
const e2: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent;
expect(isShaken(e1, e2)).toBe(true);
});
it('should return false if e1 and e2 targets are the same and distance is less than SHAKE_DISTANCE', () => {
const target = {};
const e1: MouseEvent | DragEvent = { target: target } as MouseEvent | DragEvent;
const e2: MouseEvent | DragEvent = { target: target } as MouseEvent | DragEvent;
// Assuming SHAKE_DISTANCE is 100
e1.clientY = 50;
e2.clientY = 50;
e1.clientX = 60;
e2.clientX = 60;
expect(isShaken(e1, e2)).toBe(false);
});
it('should return true if e1 and e2 targets are the same and distance is greater than SHAKE_DISTANCE', () => {
const e1: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent;
const e2: MouseEvent | DragEvent = { target: {} } as MouseEvent | DragEvent;
// Assuming SHAKE_DISTANCE is 100
e1.clientY = 50;
e1.clientX = 50;
e2.clientY = 200;
e2.clientX = 200;
expect(isShaken(e1, e2)).toBe(true);
});
});