@knowark/componarkjs 1.13.3 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base/component/component.js +17 -1
- package/lib/base/component/component.test.js +475 -389
- package/lib/base/utils/define.js +28 -6
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +11 -4
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +22 -3
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/camera/components/camera.js +8 -3
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/capture/components/capture.js +33 -5
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/droparea/components/droparea-preview.js +66 -15
- package/lib/components/droparea/components/droparea-preview.test.js +262 -78
- package/lib/components/droparea/components/droparea.js +47 -8
- package/lib/components/droparea/components/droparea.test.js +309 -298
- package/lib/components/emit/components/emit.js +24 -4
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/index.js +1 -1
- package/lib/components/list/components/{list.item.js → item.js} +1 -1
- package/lib/components/list/components/item.test.js +70 -69
- package/lib/components/list/components/list.js +35 -5
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/list/index.js +1 -1
- package/lib/components/paginator/components/paginator.js +3 -2
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/spinner/components/spinner.js +1 -1
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/splitview/components/splitview.detail.js +1 -1
- package/lib/components/splitview/components/splitview.detail.test.js +78 -74
- package/lib/components/splitview/components/splitview.js +40 -10
- package/lib/components/splitview/components/splitview.master.js +29 -3
- package/lib/components/splitview/components/splitview.master.test.js +52 -52
- package/lib/components/splitview/components/splitview.test.js +136 -32
- package/lib/components/translate/components/translate.js +32 -10
- package/lib/components/translate/components/translate.test.js +492 -133
- package/package.json +7 -27
- package/scripts/node-test-setup.js +94 -0
- package/showcase/components/index.html +1 -1
- package/{jsconfig.json → tsconfig.json} +6 -4
- package/types/base/component/component.d.ts +48 -0
- package/types/base/component/component.d.ts.map +1 -0
- package/types/base/component/component.test.d.ts +2 -0
- package/types/base/component/component.test.d.ts.map +1 -0
- package/types/base/component/index.d.ts +8 -0
- package/types/base/component/index.d.ts.map +1 -0
- package/types/base/index.d.ts +2 -0
- package/types/base/index.d.ts.map +1 -0
- package/types/base/styles/index.d.ts +3 -0
- package/types/base/styles/index.d.ts.map +1 -0
- package/types/base/styles/styles.d.ts +3 -0
- package/types/base/styles/styles.d.ts.map +1 -0
- package/types/base/utils/define.d.ts +5 -0
- package/types/base/utils/define.d.ts.map +1 -0
- package/types/base/utils/define.test.d.ts +2 -0
- package/types/base/utils/define.test.d.ts.map +1 -0
- package/types/base/utils/format.d.ts +13 -0
- package/types/base/utils/format.d.ts.map +1 -0
- package/types/base/utils/format.test.d.ts +2 -0
- package/types/base/utils/format.test.d.ts.map +1 -0
- package/types/base/utils/helpers.d.ts +11 -0
- package/types/base/utils/helpers.d.ts.map +1 -0
- package/types/base/utils/helpers.test.d.ts +2 -0
- package/types/base/utils/helpers.test.d.ts.map +1 -0
- package/types/base/utils/index.d.ts +6 -0
- package/types/base/utils/index.d.ts.map +1 -0
- package/types/base/utils/slots.d.ts +15 -0
- package/types/base/utils/slots.d.ts.map +1 -0
- package/types/base/utils/slots.test.d.ts +2 -0
- package/types/base/utils/slots.test.d.ts.map +1 -0
- package/types/base/utils/uuid.d.ts +3 -0
- package/types/base/utils/uuid.d.ts.map +1 -0
- package/types/base/utils/uuid.test.d.ts +2 -0
- package/types/base/utils/uuid.test.d.ts.map +1 -0
- package/types/components/audio/components/audio.d.ts +18 -0
- package/types/components/audio/components/audio.d.ts.map +1 -0
- package/types/components/audio/components/audio.test.d.ts +2 -0
- package/types/components/audio/components/audio.test.d.ts.map +1 -0
- package/types/components/audio/index.d.ts +2 -0
- package/types/components/audio/index.d.ts.map +1 -0
- package/types/components/audio/styles/ark.css.d.ts +3 -0
- package/types/components/audio/styles/ark.css.d.ts.map +1 -0
- package/types/components/audio/styles/index.d.ts +3 -0
- package/types/components/audio/styles/index.d.ts.map +1 -0
- package/types/components/camera/components/camera.d.ts +18 -0
- package/types/components/camera/components/camera.d.ts.map +1 -0
- package/types/components/camera/components/camera.test.d.ts +2 -0
- package/types/components/camera/components/camera.test.d.ts.map +1 -0
- package/types/components/camera/index.d.ts +2 -0
- package/types/components/camera/index.d.ts.map +1 -0
- package/types/components/camera/styles/ark.css.d.ts +3 -0
- package/types/components/camera/styles/ark.css.d.ts.map +1 -0
- package/types/components/camera/styles/index.d.ts +3 -0
- package/types/components/camera/styles/index.d.ts.map +1 -0
- package/types/components/capture/components/capture.d.ts +10 -0
- package/types/components/capture/components/capture.d.ts.map +1 -0
- package/types/components/capture/components/capture.test.d.ts +2 -0
- package/types/components/capture/components/capture.test.d.ts.map +1 -0
- package/types/components/capture/index.d.ts +2 -0
- package/types/components/capture/index.d.ts.map +1 -0
- package/types/components/droparea/components/droparea-preview.d.ts +21 -0
- package/types/components/droparea/components/droparea-preview.d.ts.map +1 -0
- package/types/components/droparea/components/droparea-preview.test.d.ts +2 -0
- package/types/components/droparea/components/droparea-preview.test.d.ts.map +1 -0
- package/types/components/droparea/components/droparea.d.ts +32 -0
- package/types/components/droparea/components/droparea.d.ts.map +1 -0
- package/types/components/droparea/components/droparea.test.d.ts +2 -0
- package/types/components/droparea/components/droparea.test.d.ts.map +1 -0
- package/types/components/droparea/index.d.ts +2 -0
- package/types/components/droparea/index.d.ts.map +1 -0
- package/types/components/droparea/styles/ark.css.d.ts +3 -0
- package/types/components/droparea/styles/ark.css.d.ts.map +1 -0
- package/types/components/droparea/styles/index.d.ts +3 -0
- package/types/components/droparea/styles/index.d.ts.map +1 -0
- package/types/components/emit/components/emit.d.ts +10 -0
- package/types/components/emit/components/emit.d.ts.map +1 -0
- package/types/components/emit/components/emit.test.d.ts +2 -0
- package/types/components/emit/components/emit.test.d.ts.map +1 -0
- package/types/components/emit/index.d.ts +2 -0
- package/types/components/emit/index.d.ts.map +1 -0
- package/types/components/index.d.ts +10 -0
- package/types/components/index.d.ts.map +1 -0
- package/types/components/list/components/item.d.ts +8 -0
- package/types/components/list/components/item.d.ts.map +1 -0
- package/types/components/list/components/item.test.d.ts +2 -0
- package/types/components/list/components/item.test.d.ts.map +1 -0
- package/types/components/list/components/list.d.ts +13 -0
- package/types/components/list/components/list.d.ts.map +1 -0
- package/types/components/list/components/list.test.d.ts +2 -0
- package/types/components/list/components/list.test.d.ts.map +1 -0
- package/types/components/list/index.d.ts +3 -0
- package/types/components/list/index.d.ts.map +1 -0
- package/types/components/paginator/components/paginator.d.ts +32 -0
- package/types/components/paginator/components/paginator.d.ts.map +1 -0
- package/types/components/paginator/components/paginator.test.d.ts +2 -0
- package/types/components/paginator/components/paginator.test.d.ts.map +1 -0
- package/types/components/paginator/index.d.ts +2 -0
- package/types/components/paginator/index.d.ts.map +1 -0
- package/types/components/paginator/styles/ark.css.d.ts +3 -0
- package/types/components/paginator/styles/ark.css.d.ts.map +1 -0
- package/types/components/paginator/styles/index.d.ts +3 -0
- package/types/components/paginator/styles/index.d.ts.map +1 -0
- package/types/components/spinner/components/spinner.d.ts +11 -0
- package/types/components/spinner/components/spinner.d.ts.map +1 -0
- package/types/components/spinner/components/spinner.test.d.ts +2 -0
- package/types/components/spinner/components/spinner.test.d.ts.map +1 -0
- package/types/components/spinner/index.d.ts +2 -0
- package/types/components/spinner/index.d.ts.map +1 -0
- package/types/components/spinner/styles/ark.css.d.ts +3 -0
- package/types/components/spinner/styles/ark.css.d.ts.map +1 -0
- package/types/components/spinner/styles/index.d.ts +3 -0
- package/types/components/spinner/styles/index.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.d.ts +12 -0
- package/types/components/splitview/components/splitview.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.detail.d.ts +10 -0
- package/types/components/splitview/components/splitview.detail.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.detail.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.detail.test.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.master.d.ts +8 -0
- package/types/components/splitview/components/splitview.master.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.master.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.master.test.d.ts.map +1 -0
- package/types/components/splitview/components/splitview.test.d.ts +2 -0
- package/types/components/splitview/components/splitview.test.d.ts.map +1 -0
- package/types/components/splitview/index.d.ts +4 -0
- package/types/components/splitview/index.d.ts.map +1 -0
- package/types/components/translate/components/translate.d.ts +18 -0
- package/types/components/translate/components/translate.d.ts.map +1 -0
- package/types/components/translate/components/translate.test.d.ts +2 -0
- package/types/components/translate/components/translate.test.d.ts.map +1 -0
- package/types/components/translate/index.d.ts +2 -0
- package/types/components/translate/index.d.ts.map +1 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +1 -0
|
@@ -1,353 +1,364 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { it, mock } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
2
3
|
import './droparea.js'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
bubbles: true
|
|
8
|
-
})
|
|
9
|
-
Object.assign(event, props)
|
|
10
|
-
return event
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
global.URL.createObjectURL = jest.fn()
|
|
14
|
-
|
|
15
|
-
let container = null
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
container = document.createElement('div')
|
|
19
|
-
document.body.appendChild(container)
|
|
5
|
+
const createBubbledEvent = (type, props = {}) => {
|
|
6
|
+
const event = new Event(type, {
|
|
7
|
+
bubbles: true
|
|
20
8
|
})
|
|
9
|
+
Object.assign(event, props)
|
|
10
|
+
return event
|
|
11
|
+
}
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
container = null
|
|
25
|
-
})
|
|
13
|
+
global.URL.createObjectURL = (
|
|
14
|
+
/** @type {(obj: Blob | MediaSource) => string} */ (mock.fn()))
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
container.innerHTML = /* html */ `
|
|
29
|
-
<ark-droparea></ark-droparea>
|
|
30
|
-
`
|
|
16
|
+
let container = null
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const setup = () => {
|
|
19
|
+
document.body.innerHTML = ''
|
|
20
|
+
container = document.createElement('div')
|
|
21
|
+
document.body.appendChild(container)
|
|
22
|
+
}
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
it('can be instantiated', () => {
|
|
25
|
+
setup()
|
|
26
|
+
container.innerHTML = /* html */ `
|
|
27
|
+
<ark-droparea></ark-droparea>
|
|
28
|
+
`
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
const droparea = container.querySelector('ark-droparea')
|
|
31
|
+
assert.strictEqual(droparea, droparea.init())
|
|
32
|
+
})
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
expect(dropZone.classList['1']).toBe('highlight')
|
|
52
|
-
})
|
|
34
|
+
it('drag files to zone highlights the drop area', () => {
|
|
35
|
+
setup()
|
|
36
|
+
container.innerHTML = /* html */ `
|
|
37
|
+
<ark-droparea></ark-droparea>
|
|
38
|
+
`
|
|
53
39
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
`
|
|
40
|
+
const droparea = container.querySelector('ark-droparea')
|
|
41
|
+
const dropZone = droparea.dropZone
|
|
42
|
+
const dragNode = dropZone
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
|
|
44
|
+
dragNode.dispatchEvent(
|
|
45
|
+
createBubbledEvent('dragover', {
|
|
46
|
+
clientX: 0,
|
|
47
|
+
clientY: 1
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
assert.strictEqual(dropZone.classList['1'], 'highlight')
|
|
51
|
+
})
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
expect(dropZone.classList.length).toBe(1)
|
|
69
|
-
})
|
|
53
|
+
it('drag files outside the zone unhighlight the drop area', () => {
|
|
54
|
+
setup()
|
|
55
|
+
container.innerHTML = /* html */ `
|
|
56
|
+
<ark-droparea></ark-droparea>
|
|
57
|
+
`
|
|
70
58
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<ark-droparea></ark-droparea>
|
|
74
|
-
`
|
|
59
|
+
const droparea = container.querySelector('ark-droparea')
|
|
60
|
+
const dropZone = droparea.dropZone
|
|
75
61
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const myFile = new File(['image'], 'Doggy.png', {
|
|
79
|
-
type: 'image/png'
|
|
80
|
-
})
|
|
81
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
82
|
-
type: 'image/png'
|
|
83
|
-
})
|
|
84
|
-
const dropEvent = createBubbledEvent('drop', {
|
|
62
|
+
dropZone.dispatchEvent(
|
|
63
|
+
createBubbledEvent('dragleave', {
|
|
85
64
|
clientX: 0,
|
|
86
|
-
clientY: 1
|
|
87
|
-
dataTransfer: {
|
|
88
|
-
files: [myFile, myFile2]
|
|
89
|
-
}
|
|
65
|
+
clientY: 1
|
|
90
66
|
})
|
|
67
|
+
)
|
|
68
|
+
assert.strictEqual(dropZone.classList.length, 1)
|
|
69
|
+
})
|
|
91
70
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
71
|
+
it('Allows dropping multiple files to the component', () => {
|
|
72
|
+
setup()
|
|
73
|
+
container.innerHTML = /* html */ `
|
|
74
|
+
<ark-droparea></ark-droparea>
|
|
75
|
+
`
|
|
96
76
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
const droparea = container.querySelector('ark-droparea')
|
|
78
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
79
|
+
const myFile = new File(['image'], 'Doggy.png', {
|
|
80
|
+
type: 'image/png'
|
|
81
|
+
})
|
|
82
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
83
|
+
type: 'image/png'
|
|
84
|
+
})
|
|
85
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
86
|
+
clientX: 0,
|
|
87
|
+
clientY: 1,
|
|
88
|
+
dataTransfer: {
|
|
89
|
+
files: [myFile, myFile2]
|
|
90
|
+
}
|
|
91
|
+
})
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
})
|
|
107
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
108
|
-
type: 'image/png'
|
|
109
|
-
})
|
|
93
|
+
dropZone.dispatchEvent(dropEvent)
|
|
94
|
+
assert.deepStrictEqual(droparea.fileList[0].name, myFile.name)
|
|
95
|
+
assert.deepStrictEqual(droparea.fileList[1].name, myFile2.name)
|
|
96
|
+
})
|
|
110
97
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
})
|
|
98
|
+
it('Can recieve a single file', () => {
|
|
99
|
+
setup()
|
|
100
|
+
container.innerHTML = /* html */ `
|
|
101
|
+
<ark-droparea single></ark-droparea>
|
|
102
|
+
`
|
|
118
103
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
104
|
+
const droparea = container.querySelector('ark-droparea')
|
|
105
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
106
|
+
const myFile = new File(['image'], 'Snoopy.png', {
|
|
107
|
+
type: 'image/png'
|
|
108
|
+
})
|
|
109
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
110
|
+
type: 'image/png'
|
|
122
111
|
})
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
114
|
+
clientX: 0,
|
|
115
|
+
clientY: 1,
|
|
116
|
+
dataTransfer: {
|
|
117
|
+
files: [myFile, myFile2]
|
|
118
|
+
}
|
|
119
|
+
})
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
135
|
-
type: 'image/png'
|
|
136
|
-
})
|
|
121
|
+
dropZone.dispatchEvent(dropEvent)
|
|
122
|
+
assert.strictEqual(droparea.fileList.length, 1)
|
|
123
|
+
assert.ok(!droparea.fileList[1])
|
|
124
|
+
})
|
|
137
125
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
})
|
|
126
|
+
it('Returns the file list as object URL', () => {
|
|
127
|
+
setup()
|
|
128
|
+
container.innerHTML = /* html */ `
|
|
129
|
+
<ark-droparea></ark-droparea>
|
|
130
|
+
`
|
|
145
131
|
|
|
146
|
-
|
|
147
|
-
|
|
132
|
+
const droparea = container.querySelector('ark-droparea')
|
|
133
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
134
|
+
const myFile = new File(['image'], 'Snoopy.png', {
|
|
135
|
+
type: 'image/png'
|
|
136
|
+
})
|
|
137
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
138
|
+
type: 'image/png'
|
|
148
139
|
})
|
|
149
140
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
142
|
+
clientX: 0,
|
|
143
|
+
clientY: 1,
|
|
144
|
+
dataTransfer: {
|
|
145
|
+
files: [myFile, myFile2]
|
|
146
|
+
}
|
|
147
|
+
})
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
type: 'image/png'
|
|
159
|
-
})
|
|
160
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
161
|
-
type: 'image/png'
|
|
162
|
-
})
|
|
149
|
+
dropZone.dispatchEvent(dropEvent)
|
|
150
|
+
assert.deepStrictEqual(droparea.fileList.length, 2)
|
|
151
|
+
})
|
|
163
152
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
})
|
|
153
|
+
it('Returns a media list of file metadata objects', () => {
|
|
154
|
+
setup()
|
|
155
|
+
container.innerHTML = /* html */ `
|
|
156
|
+
<ark-droparea></ark-droparea>
|
|
157
|
+
`
|
|
171
158
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
url: undefined
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: 'Scooby.png',
|
|
183
|
-
size: 5,
|
|
184
|
-
type: 'image/png',
|
|
185
|
-
url: undefined
|
|
186
|
-
}
|
|
187
|
-
])
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('Can select files from input', () => {
|
|
191
|
-
container.innerHTML = /* html */ `
|
|
192
|
-
<ark-droparea></ark-droparea>
|
|
193
|
-
`
|
|
194
|
-
|
|
195
|
-
const droparea = container.querySelector('ark-droparea')
|
|
196
|
-
const dropOpen = droparea.querySelector('.ark-droparea__open')
|
|
197
|
-
const input = droparea.querySelector('.ark-droparea__input')
|
|
198
|
-
const myFile = new File(['image'], 'Snoopy.png', {
|
|
199
|
-
type: 'image/png'
|
|
200
|
-
})
|
|
201
|
-
const changeEvent = createBubbledEvent('change', {})
|
|
202
|
-
Object.defineProperty(changeEvent, 'target', {
|
|
203
|
-
value: {
|
|
204
|
-
files: [myFile]
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
dropOpen.click()
|
|
208
|
-
input.dispatchEvent(changeEvent)
|
|
209
|
-
expect(droparea.fileList.length).toBeTruthy()
|
|
159
|
+
const droparea = container.querySelector('ark-droparea')
|
|
160
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
161
|
+
const myFile = new File(['image'], 'Snoopy.png', {
|
|
162
|
+
type: 'image/png'
|
|
163
|
+
})
|
|
164
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
165
|
+
type: 'image/png'
|
|
210
166
|
})
|
|
211
167
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
168
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
169
|
+
clientX: 0,
|
|
170
|
+
clientY: 1,
|
|
171
|
+
dataTransfer: {
|
|
172
|
+
files: [myFile, myFile2]
|
|
173
|
+
}
|
|
174
|
+
})
|
|
216
175
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
type: 'image/png'
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
176
|
+
dropZone.dispatchEvent(dropEvent)
|
|
177
|
+
assert.deepStrictEqual(droparea.mediaList.length, 2)
|
|
178
|
+
assert.deepStrictEqual(droparea.mediaList, [
|
|
179
|
+
{
|
|
180
|
+
name: 'Snoopy.png',
|
|
181
|
+
size: 5,
|
|
182
|
+
type: 'image/png',
|
|
183
|
+
url: undefined
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Scooby.png',
|
|
187
|
+
size: 5,
|
|
188
|
+
type: 'image/png',
|
|
189
|
+
url: undefined
|
|
190
|
+
}
|
|
191
|
+
])
|
|
192
|
+
})
|
|
231
193
|
|
|
232
|
-
|
|
233
|
-
|
|
194
|
+
it('Can select files from input', () => {
|
|
195
|
+
setup()
|
|
196
|
+
container.innerHTML = /* html */ `
|
|
197
|
+
<ark-droparea></ark-droparea>
|
|
198
|
+
`
|
|
199
|
+
|
|
200
|
+
const droparea = container.querySelector('ark-droparea')
|
|
201
|
+
const dropOpen = droparea.querySelector('.ark-droparea__open')
|
|
202
|
+
const input = droparea.querySelector('.ark-droparea__input')
|
|
203
|
+
const myFile = new File(['image'], 'Snoopy.png', {
|
|
204
|
+
type: 'image/png'
|
|
205
|
+
})
|
|
206
|
+
const changeEvent = createBubbledEvent('change', {})
|
|
207
|
+
Object.defineProperty(changeEvent, 'target', {
|
|
208
|
+
value: {
|
|
209
|
+
files: [myFile]
|
|
210
|
+
}
|
|
234
211
|
})
|
|
212
|
+
dropOpen.click()
|
|
213
|
+
input.dispatchEvent(changeEvent)
|
|
214
|
+
assert.ok(droparea.fileList.length)
|
|
215
|
+
})
|
|
235
216
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
217
|
+
it('Can limit the file formats that component recieves', () => {
|
|
218
|
+
setup()
|
|
219
|
+
container.innerHTML = /* html */ `
|
|
220
|
+
<ark-droparea accept="jpg, png"></ark-droparea>
|
|
221
|
+
`
|
|
240
222
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
223
|
+
const droparea = container.querySelector('ark-droparea')
|
|
224
|
+
const input = droparea.querySelector('.ark-droparea__input')
|
|
225
|
+
const myFile = new File(['image'], 'Snoopy.jpg', {
|
|
226
|
+
type: 'image/png'
|
|
227
|
+
})
|
|
228
|
+
const myFile2 = new File(['image'], 'Scrappy.png', {
|
|
229
|
+
type: 'image/png'
|
|
230
|
+
})
|
|
231
|
+
const changeEvent = createBubbledEvent('change', {})
|
|
232
|
+
Object.defineProperty(changeEvent, 'target', {
|
|
233
|
+
value: {
|
|
234
|
+
files: [myFile, myFile2]
|
|
235
|
+
}
|
|
254
236
|
})
|
|
255
237
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
</ark-droparea>
|
|
260
|
-
`
|
|
238
|
+
input.dispatchEvent(changeEvent)
|
|
239
|
+
assert.ok(droparea.fileList.length)
|
|
240
|
+
})
|
|
261
241
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const myFile2 = new File(['video'], 'cats.mov', {
|
|
268
|
-
type: 'video/mov'
|
|
269
|
-
})
|
|
270
|
-
const myFile3 = new File(['image'], 'snoopy.jpg', {
|
|
271
|
-
type: 'image/jpg'
|
|
272
|
-
})
|
|
273
|
-
const myFile4 = new File(['text'], 'styles.css', {
|
|
274
|
-
type: 'text/css'
|
|
275
|
-
})
|
|
242
|
+
it("Does not allow dropping a file that doesn't not exist in accept'", () => {
|
|
243
|
+
setup()
|
|
244
|
+
container.innerHTML = /* html */ `
|
|
245
|
+
<ark-droparea accept="jpg, png"></ark-droparea>
|
|
246
|
+
`
|
|
276
247
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
248
|
+
const droparea = container.querySelector('ark-droparea')
|
|
249
|
+
const input = droparea.querySelector('.ark-droparea__input')
|
|
250
|
+
const myFile = new File(['text'], 'Snoopy.txt', {
|
|
251
|
+
type: 'text/txt'
|
|
252
|
+
})
|
|
253
|
+
const changeEvent = createBubbledEvent('change', {})
|
|
254
|
+
Object.defineProperty(changeEvent, 'target', {
|
|
255
|
+
value: {
|
|
256
|
+
files: [myFile]
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
input.dispatchEvent(changeEvent)
|
|
260
|
+
assert.ok(!droparea.fileList.length)
|
|
261
|
+
})
|
|
286
262
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
263
|
+
it("General file type values can be specified'", () => {
|
|
264
|
+
setup()
|
|
265
|
+
container.innerHTML = /* html */ `
|
|
266
|
+
<ark-droparea accept="audio, image, video, text">
|
|
267
|
+
</ark-droparea>
|
|
268
|
+
`
|
|
269
|
+
|
|
270
|
+
const droparea = container.querySelector('ark-droparea')
|
|
271
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
272
|
+
const myFile = new File(['audio'], 'autechre.mp3', {
|
|
273
|
+
type: 'audio/mp3'
|
|
274
|
+
})
|
|
275
|
+
const myFile2 = new File(['video'], 'cats.mov', {
|
|
276
|
+
type: 'video/mov'
|
|
277
|
+
})
|
|
278
|
+
const myFile3 = new File(['image'], 'snoopy.jpg', {
|
|
279
|
+
type: 'image/jpg'
|
|
280
|
+
})
|
|
281
|
+
const myFile4 = new File(['text'], 'styles.css', {
|
|
282
|
+
type: 'text/css'
|
|
290
283
|
})
|
|
291
284
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
285
|
+
const files = [myFile, myFile2, myFile3, myFile4]
|
|
286
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
287
|
+
clientX: 0,
|
|
288
|
+
clientY: 1,
|
|
289
|
+
dataTransfer: {
|
|
290
|
+
files
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
dropZone.dispatchEvent(dropEvent)
|
|
296
294
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
})
|
|
302
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
303
|
-
type: 'image/png'
|
|
304
|
-
})
|
|
305
|
-
Object.defineProperty(myFile2, 'size', { value: 1024 * 1024 + 1 })
|
|
295
|
+
droparea.fileList.forEach((file, i) => {
|
|
296
|
+
assert.strictEqual(file.type, files[i].type)
|
|
297
|
+
})
|
|
298
|
+
})
|
|
306
299
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
})
|
|
300
|
+
it('Size of files can be limited', () => {
|
|
301
|
+
setup()
|
|
302
|
+
container.innerHTML = /* html */ `
|
|
303
|
+
<ark-droparea max-size= "2"></ark-droparea>
|
|
304
|
+
`
|
|
314
305
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
306
|
+
const droparea = container.querySelector('ark-droparea')
|
|
307
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
308
|
+
const myFile = new File(['image'], 'Doggy.png', {
|
|
309
|
+
type: 'image/png'
|
|
310
|
+
})
|
|
311
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
312
|
+
type: 'image/png'
|
|
313
|
+
})
|
|
314
|
+
Object.defineProperty(myFile2, 'size', { value: 1024 * 1024 + 1 })
|
|
315
|
+
|
|
316
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
317
|
+
clientX: 0,
|
|
318
|
+
clientY: 1,
|
|
319
|
+
dataTransfer: {
|
|
320
|
+
files: [myFile, myFile2]
|
|
321
|
+
}
|
|
319
322
|
})
|
|
320
323
|
|
|
324
|
+
const maxSizeValidateSpy = mock.method(droparea, 'maxSizeValidate')
|
|
325
|
+
droparea.maxSizeValidate([])
|
|
326
|
+
droparea.maxSizeValidate(myFile2)
|
|
327
|
+
dropZone.dispatchEvent(dropEvent)
|
|
328
|
+
assert.ok(maxSizeValidateSpy.mock.calls.length > 0)
|
|
329
|
+
maxSizeValidateSpy.mock.restore()
|
|
330
|
+
})
|
|
321
331
|
|
|
322
|
-
it('allows to be passed a custom input element', () => {
|
|
323
|
-
container.innerHTML = /* html */ `
|
|
324
|
-
<ark-droparea single>
|
|
325
|
-
<input data-custom-input style="font-weight:bold" type="file">
|
|
326
|
-
</ark-droparea>
|
|
327
|
-
`
|
|
328
|
-
|
|
329
|
-
const droparea = container.querySelector('ark-droparea')
|
|
330
|
-
const input = droparea.querySelector('[data-custom-input]')
|
|
331
|
-
expect(input).toBeTruthy()
|
|
332
|
-
expect(input.style.fontWeight).toEqual('bold')
|
|
333
|
-
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
334
|
-
const myFile = new File(['image'], 'Snoopy.png', {
|
|
335
|
-
type: 'image/png'
|
|
336
|
-
})
|
|
337
|
-
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
338
|
-
type: 'image/png'
|
|
339
|
-
})
|
|
340
332
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
333
|
+
it('allows to be passed a custom input element', () => {
|
|
334
|
+
setup()
|
|
335
|
+
container.innerHTML = /* html */ `
|
|
336
|
+
<ark-droparea single>
|
|
337
|
+
<input data-custom-input style="font-weight:bold" type="file">
|
|
338
|
+
</ark-droparea>
|
|
339
|
+
`
|
|
340
|
+
|
|
341
|
+
const droparea = container.querySelector('ark-droparea')
|
|
342
|
+
const input = droparea.querySelector('[data-custom-input]')
|
|
343
|
+
assert.ok(input)
|
|
344
|
+
assert.deepStrictEqual(input.style.fontWeight, 'bold')
|
|
345
|
+
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
346
|
+
const myFile = new File(['image'], 'Snoopy.png', {
|
|
347
|
+
type: 'image/png'
|
|
348
|
+
})
|
|
349
|
+
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
350
|
+
type: 'image/png'
|
|
351
|
+
})
|
|
348
352
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
353
|
+
const dropEvent = createBubbledEvent('drop', {
|
|
354
|
+
clientX: 0,
|
|
355
|
+
clientY: 1,
|
|
356
|
+
dataTransfer: {
|
|
357
|
+
files: [myFile, myFile2]
|
|
358
|
+
}
|
|
352
359
|
})
|
|
360
|
+
|
|
361
|
+
dropZone.dispatchEvent(dropEvent)
|
|
362
|
+
assert.strictEqual(droparea.fileList.length, 1)
|
|
363
|
+
assert.ok(!droparea.fileList[1])
|
|
353
364
|
})
|