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