This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
dragster.test.ts
87 lines (70 loc) · 2.45 KB
/
dragster.test.ts
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import dragster from './dragster';
describe('utils.dragster', () => {
let div: HTMLElement;
let unbind: () => void;
let enterEvent: CustomEvent | null;
let leaveEvent: CustomEvent | null;
let overEvent: CustomEvent | null;
let dropEvent: CustomEvent | null;
const id = 'utils_dragster_test';
const dragenter = new CustomEvent('dragenter', {detail: 'dragenter_detail'});
const dragleave = new CustomEvent('dragleave', {detail: 'dragleave_detail'});
const dragover = new CustomEvent('dragover', {detail: 'dragover_detail'});
const drop = new CustomEvent('drop', {detail: 'drop_detail'});
const options = {
enter: (event: CustomEvent) => {
enterEvent = event;
},
leave: (event: CustomEvent) => {
leaveEvent = event;
},
over: (event: CustomEvent) => {
overEvent = event;
},
drop: (event: CustomEvent) => {
dropEvent = event;
},
};
beforeAll(() => {
div = document.createElement('div');
document.body.appendChild(div);
div.setAttribute('id', id);
unbind = dragster(`#${id}`, options);
});
afterAll(() => {
unbind();
div.remove();
});
afterEach(() => {
enterEvent = null;
leaveEvent = null;
overEvent = null;
dropEvent = null;
});
it('should dispatch dragenter event', () => {
div.dispatchEvent(dragenter);
expect(enterEvent!.detail.detail).toEqual('dragenter_detail');
});
it('should dispatch dragleave event', () => {
div.dispatchEvent(dragleave);
expect(leaveEvent!.detail.detail).toEqual('dragleave_detail');
});
it('should dispatch dragover event', () => {
div.dispatchEvent(dragover);
expect(overEvent!.detail.detail).toEqual('dragover_detail');
});
it('should dispatch drop event', () => {
div.dispatchEvent(drop);
expect(dropEvent!.detail.detail).toEqual('drop_detail');
});
it('should dispatch dragenter event again', () => {
div.dispatchEvent(dragenter);
expect(enterEvent!.detail.detail).toEqual('dragenter_detail');
});
it('should dispatch dragenter event once if dispatched 2 times', () => {
div.dispatchEvent(dragenter);
expect(enterEvent).toBeNull();
});
});