forked from muxinc/elements
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploader-drop.test.js
61 lines (51 loc) · 1.75 KB
/
uploader-drop.test.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
import { fixture, assert, oneEvent } from '@open-wc/testing';
import '../src/index.ts';
describe('<mux-uploader-drop>', () => {
it('adds and removes active attribute on drag events', async function () {
const uploader = await fixture(`
<mux-uploader-drop mux-uploader="my-uploader">
<mux-uploader id="my-uploader" endpoint="https://my-authenticated-url/storage?your-url-params">
</mux-uploader>
</mux-uploader-drop>
`);
uploader.dispatchEvent(
new DragEvent('dragenter', {
composed: true,
bubbles: true,
})
);
assert.exists(uploader.getAttribute('active'), 'active attribute is set');
uploader.dispatchEvent(
new DragEvent('dragleave', {
composed: true,
bubbles: true,
})
);
assert.notExists(uploader.getAttribute('active'), 'active attribute is removed');
});
it('fires a file-ready event when a file is dropped', async function () {
const uploader = await fixture(`
<mux-uploader-drop mux-uploader="my-uploader">
<mux-uploader id="my-uploader" endpoint="https://my-authenticated-url/storage?your-url-params">
</mux-uploader>
</mux-uploader-drop>
`);
const file = new File(['foo'], 'foo.mp4', {
type: 'video/mp4',
});
const dataTransfer = new DataTransfer();
dataTransfer.items.add(file);
setTimeout(() => {
uploader.dispatchEvent(
new DragEvent('drop', {
composed: true,
bubbles: true,
dataTransfer,
})
);
});
const { detail } = await oneEvent(uploader, 'file-ready');
assert.equal(detail, file, 'file matches');
assert.equal(uploader.hasAttribute('upload-in-progress'), true, 'upload-in-progress attr is set');
});
});