@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.
Files changed (118) hide show
  1. package/README.md +57 -45
  2. package/lib/base/component/component.js +142 -20
  3. package/lib/base/component/component.test.js +753 -374
  4. package/lib/base/component/index.js +3 -0
  5. package/lib/base/styles/index.js +4 -1
  6. package/lib/base/utils/define.js +30 -7
  7. package/lib/base/utils/define.test.js +129 -42
  8. package/lib/base/utils/format.js +12 -6
  9. package/lib/base/utils/format.test.js +16 -16
  10. package/lib/base/utils/helpers.js +42 -9
  11. package/lib/base/utils/helpers.test.js +134 -115
  12. package/lib/base/utils/index.js +1 -0
  13. package/lib/base/utils/slots.js +3 -2
  14. package/lib/base/utils/slots.test.js +38 -38
  15. package/lib/base/utils/uuid.js +1 -1
  16. package/lib/base/utils/uuid.test.js +13 -13
  17. package/lib/components/audio/components/audio.js +36 -3
  18. package/lib/components/audio/components/audio.test.js +120 -90
  19. package/lib/components/audio/index.js +1 -0
  20. package/lib/components/audio/styles/index.js +5 -1
  21. package/lib/components/camera/components/camera.js +15 -0
  22. package/lib/components/camera/components/camera.test.js +96 -91
  23. package/lib/components/camera/index.js +1 -0
  24. package/lib/components/camera/styles/index.js +5 -1
  25. package/lib/components/capture/components/capture.js +48 -4
  26. package/lib/components/capture/components/capture.test.js +165 -97
  27. package/lib/components/capture/index.js +1 -0
  28. package/lib/components/droparea/components/droparea-preview.js +114 -19
  29. package/lib/components/droparea/components/droparea-preview.test.js +344 -80
  30. package/lib/components/droparea/components/droparea.js +82 -6
  31. package/lib/components/droparea/components/droparea.test.js +309 -299
  32. package/lib/components/droparea/index.js +1 -0
  33. package/lib/components/droparea/styles/index.js +5 -1
  34. package/lib/components/emit/components/emit.js +34 -4
  35. package/lib/components/emit/components/emit.test.js +192 -134
  36. package/lib/components/emit/index.js +1 -0
  37. package/lib/components/index.js +2 -1
  38. package/lib/components/list/components/item.js +6 -0
  39. package/lib/components/list/components/item.test.js +69 -68
  40. package/lib/components/list/components/list.js +51 -7
  41. package/lib/components/list/components/list.test.js +358 -227
  42. package/lib/components/list/index.js +1 -0
  43. package/lib/components/paginator/components/paginator.js +34 -8
  44. package/lib/components/paginator/components/paginator.test.js +146 -143
  45. package/lib/components/paginator/index.js +1 -0
  46. package/lib/components/paginator/styles/index.js +5 -1
  47. package/lib/components/spinner/components/spinner.js +10 -0
  48. package/lib/components/spinner/components/spinner.test.js +36 -41
  49. package/lib/components/spinner/index.js +1 -0
  50. package/lib/components/spinner/styles/index.js +5 -1
  51. package/lib/components/splitview/components/splitview.detail.js +10 -1
  52. package/lib/components/splitview/components/splitview.detail.test.js +75 -73
  53. package/lib/components/splitview/components/splitview.js +54 -11
  54. package/lib/components/splitview/components/splitview.master.js +37 -2
  55. package/lib/components/splitview/components/splitview.master.test.js +52 -52
  56. package/lib/components/splitview/components/splitview.test.js +135 -31
  57. package/lib/components/splitview/index.js +1 -0
  58. package/lib/components/translate/components/translate.js +65 -14
  59. package/lib/components/translate/components/translate.test.js +658 -131
  60. package/lib/components/translate/index.js +1 -0
  61. package/lib/index.js +3 -0
  62. package/package.json +4 -27
  63. package/scripts/node-test-setup.js +94 -0
  64. package/tsconfig.json +1 -1
  65. package/types/base/component/component.d.ts +43 -8
  66. package/types/base/component/component.d.ts.map +1 -1
  67. package/types/base/component/index.d.ts +4 -6
  68. package/types/base/component/index.d.ts.map +1 -1
  69. package/types/base/styles/index.d.ts +3 -2
  70. package/types/base/styles/index.d.ts.map +1 -1
  71. package/types/base/utils/define.d.ts +3 -2
  72. package/types/base/utils/define.d.ts.map +1 -1
  73. package/types/base/utils/format.d.ts +12 -6
  74. package/types/base/utils/format.d.ts.map +1 -1
  75. package/types/base/utils/helpers.d.ts +27 -7
  76. package/types/base/utils/helpers.d.ts.map +1 -1
  77. package/types/base/utils/slots.d.ts +8 -10
  78. package/types/base/utils/slots.d.ts.map +1 -1
  79. package/types/base/utils/uuid.d.ts +1 -1
  80. package/types/base/utils/uuid.d.ts.map +1 -1
  81. package/types/components/audio/components/audio.d.ts +23 -9
  82. package/types/components/audio/components/audio.d.ts.map +1 -1
  83. package/types/components/audio/styles/index.d.ts +3 -2
  84. package/types/components/audio/styles/index.d.ts.map +1 -1
  85. package/types/components/camera/components/camera.d.ts +11 -3
  86. package/types/components/camera/components/camera.d.ts.map +1 -1
  87. package/types/components/camera/styles/index.d.ts +3 -2
  88. package/types/components/camera/styles/index.d.ts.map +1 -1
  89. package/types/components/capture/components/capture.d.ts +23 -3
  90. package/types/components/capture/components/capture.d.ts.map +1 -1
  91. package/types/components/droparea/components/droparea-preview.d.ts +64 -11
  92. package/types/components/droparea/components/droparea-preview.d.ts.map +1 -1
  93. package/types/components/droparea/components/droparea.d.ts +58 -13
  94. package/types/components/droparea/components/droparea.d.ts.map +1 -1
  95. package/types/components/droparea/styles/index.d.ts +3 -2
  96. package/types/components/droparea/styles/index.d.ts.map +1 -1
  97. package/types/components/emit/components/emit.d.ts +15 -3
  98. package/types/components/emit/components/emit.d.ts.map +1 -1
  99. package/types/components/list/components/item.d.ts +8 -1
  100. package/types/components/list/components/item.d.ts.map +1 -1
  101. package/types/components/list/components/list.d.ts +23 -5
  102. package/types/components/list/components/list.d.ts.map +1 -1
  103. package/types/components/paginator/components/paginator.d.ts +32 -8
  104. package/types/components/paginator/components/paginator.d.ts.map +1 -1
  105. package/types/components/paginator/styles/index.d.ts +3 -2
  106. package/types/components/paginator/styles/index.d.ts.map +1 -1
  107. package/types/components/spinner/components/spinner.d.ts +14 -3
  108. package/types/components/spinner/components/spinner.d.ts.map +1 -1
  109. package/types/components/spinner/styles/index.d.ts +3 -2
  110. package/types/components/spinner/styles/index.d.ts.map +1 -1
  111. package/types/components/splitview/components/splitview.d.ts +22 -4
  112. package/types/components/splitview/components/splitview.d.ts.map +1 -1
  113. package/types/components/splitview/components/splitview.detail.d.ts +12 -2
  114. package/types/components/splitview/components/splitview.detail.d.ts.map +1 -1
  115. package/types/components/splitview/components/splitview.master.d.ts +12 -1
  116. package/types/components/splitview/components/splitview.master.d.ts.map +1 -1
  117. package/types/components/translate/components/translate.d.ts +44 -10
  118. package/types/components/translate/components/translate.d.ts.map +1 -1
@@ -1,354 +1,364 @@
1
- import { jest } from '@jest/globals'
1
+ import { it, mock } from 'node:test'
2
+ import assert from 'node:assert/strict'
2
3
  import './droparea.js'
3
4
 
4
- describe('Droparea', () => {
5
- const createBubbledEvent = (type, props = {}) => {
6
- const event = new Event(type, {
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
- afterEach(() => {
24
- container.remove()
25
- container = null
26
- })
13
+ global.URL.createObjectURL = (
14
+ /** @type {(obj: Blob | MediaSource) => string} */ (mock.fn()))
27
15
 
28
- it('can be instantiated', () => {
29
- container.innerHTML = /* html */ `
30
- <ark-droparea></ark-droparea>
31
- `
16
+ let container = null
32
17
 
33
- const droparea = container.querySelector('ark-droparea')
34
- expect(droparea).toBe(droparea.init())
35
- })
18
+ const setup = () => {
19
+ document.body.innerHTML = ''
20
+ container = document.createElement('div')
21
+ document.body.appendChild(container)
22
+ }
36
23
 
37
- it('drag files to zone highlights the drop area', () => {
38
- container.innerHTML = /* html */ `
39
- <ark-droparea></ark-droparea>
40
- `
24
+ it('can be instantiated', () => {
25
+ setup()
26
+ container.innerHTML = /* html */ `
27
+ <ark-droparea></ark-droparea>
28
+ `
41
29
 
42
- const droparea = container.querySelector('ark-droparea')
43
- const dropZone = droparea.dropZone
44
- const dragNode = dropZone
30
+ const droparea = container.querySelector('ark-droparea')
31
+ assert.strictEqual(droparea, droparea.init())
32
+ })
45
33
 
46
- dragNode.dispatchEvent(
47
- createBubbledEvent('dragover', {
48
- clientX: 0,
49
- clientY: 1
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
- it('drag files outside the zone unhighlight the drop area', () => {
56
- container.innerHTML = /* html */ `
57
- <ark-droparea></ark-droparea>
58
- `
40
+ const droparea = container.querySelector('ark-droparea')
41
+ const dropZone = droparea.dropZone
42
+ const dragNode = dropZone
59
43
 
60
- const droparea = container.querySelector('ark-droparea')
61
- const dropZone = droparea.dropZone
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
- dropZone.dispatchEvent(
64
- createBubbledEvent('dragleave', {
65
- clientX: 0,
66
- clientY: 1
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
- it('Allows dropping multiple files to the component', () => {
73
- container.innerHTML = /* html */ `
74
- <ark-droparea></ark-droparea>
75
- `
59
+ const droparea = container.querySelector('ark-droparea')
60
+ const dropZone = droparea.dropZone
76
61
 
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', {
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
- dropZone.dispatchEvent(dropEvent)
94
- expect(droparea.fileList[0].name).toEqual(myFile.name)
95
- expect(droparea.fileList[1].name).toEqual(myFile2.name)
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
- it('Can recieve a single file', () => {
99
- container.innerHTML = /* html */ `
100
- <ark-droparea single></ark-droparea>
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
- const droparea = container.querySelector('ark-droparea')
104
- const dropZone = droparea.querySelector('.ark-droparea__form')
105
- const myFile = new File(['image'], 'Snoopy.png', {
106
- type: 'image/png'
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
- const dropEvent = createBubbledEvent('drop', {
113
- clientX: 0,
114
- clientY: 1,
115
- dataTransfer: {
116
- files: [myFile, myFile2]
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
- dropZone.dispatchEvent(dropEvent)
121
- expect(droparea.fileList.length).toBe(1)
122
- expect(droparea.fileList[1]).toBeFalsy()
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
- it('Returns the file list as object URL', () => {
126
- container.innerHTML = /* html */ `
127
- <ark-droparea></ark-droparea>
128
- `
113
+ const dropEvent = createBubbledEvent('drop', {
114
+ clientX: 0,
115
+ clientY: 1,
116
+ dataTransfer: {
117
+ files: [myFile, myFile2]
118
+ }
119
+ })
129
120
 
130
- const droparea = container.querySelector('ark-droparea')
131
- const dropZone = droparea.querySelector('.ark-droparea__form')
132
- const myFile = new File(['image'], 'Snoopy.png', {
133
- type: 'image/png'
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
- const dropEvent = createBubbledEvent('drop', {
140
- clientX: 0,
141
- clientY: 1,
142
- dataTransfer: {
143
- files: [myFile, myFile2]
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
- dropZone.dispatchEvent(dropEvent)
148
- expect(droparea.fileList.length).toEqual(2)
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
- it('Returns a media list of file metadata objects', () => {
152
- container.innerHTML = /* html */ `
153
- <ark-droparea></ark-droparea>
154
- `
141
+ const dropEvent = createBubbledEvent('drop', {
142
+ clientX: 0,
143
+ clientY: 1,
144
+ dataTransfer: {
145
+ files: [myFile, myFile2]
146
+ }
147
+ })
155
148
 
156
- const droparea = container.querySelector('ark-droparea')
157
- const dropZone = droparea.querySelector('.ark-droparea__form')
158
- const myFile = new File(['image'], 'Snoopy.png', {
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
- const dropEvent = createBubbledEvent('drop', {
166
- clientX: 0,
167
- clientY: 1,
168
- dataTransfer: {
169
- files: [myFile, myFile2]
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
- dropZone.dispatchEvent(dropEvent)
174
- expect(droparea.mediaList.length).toEqual(2)
175
- expect(droparea.mediaList).toEqual([
176
- {
177
- name: 'Snoopy.png',
178
- size: 5,
179
- type: 'image/png',
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
- it('Can limit the file formats that component recieves', () => {
214
- container.innerHTML = /* html */ `
215
- <ark-droparea accept="jpg, png"></ark-droparea>
216
- `
168
+ const dropEvent = createBubbledEvent('drop', {
169
+ clientX: 0,
170
+ clientY: 1,
171
+ dataTransfer: {
172
+ files: [myFile, myFile2]
173
+ }
174
+ })
217
175
 
218
- const droparea = container.querySelector('ark-droparea')
219
- const input = droparea.querySelector('.ark-droparea__input')
220
- const myFile = new File(['image'], 'Snoopy.jpg', {
221
- type: 'image/png'
222
- })
223
- const myFile2 = new File(['image'], 'Scrappy.png', {
224
- type: 'image/png'
225
- })
226
- const changeEvent = createBubbledEvent('change', {})
227
- Object.defineProperty(changeEvent, 'target', {
228
- value: {
229
- files: [myFile, myFile2]
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
- input.dispatchEvent(changeEvent)
234
- expect(droparea.fileList.length).toBeTruthy()
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
- it("Does not allow dropping a file that doesn't not exist in accept'", () => {
238
- container.innerHTML = /* html */ `
239
- <ark-droparea accept="jpg, png"></ark-droparea>
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
- const droparea = container.querySelector('ark-droparea')
243
- const input = droparea.querySelector('.ark-droparea__input')
244
- const myFile = new File(['text'], 'Snoopy.txt', {
245
- type: 'text/txt'
246
- })
247
- const changeEvent = createBubbledEvent('change', {})
248
- Object.defineProperty(changeEvent, 'target', {
249
- value: {
250
- files: [myFile]
251
- }
252
- })
253
- input.dispatchEvent(changeEvent)
254
- expect(droparea.fileList.length).toBeFalsy()
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
- it("General file type values can be specified'", () => {
258
- container.innerHTML = /* html */ `
259
- <ark-droparea accept="audio, image, video, text">
260
- </ark-droparea>
261
- `
238
+ input.dispatchEvent(changeEvent)
239
+ assert.ok(droparea.fileList.length)
240
+ })
262
241
 
263
- const droparea = container.querySelector('ark-droparea')
264
- const dropZone = droparea.querySelector('.ark-droparea__form')
265
- const myFile = new File(['audio'], 'autechre.mp3', {
266
- type: 'audio/mp3'
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
- const files = [myFile, myFile2, myFile3, myFile4]
279
- const dropEvent = createBubbledEvent('drop', {
280
- clientX: 0,
281
- clientY: 1,
282
- dataTransfer: {
283
- files
284
- }
285
- })
286
- dropZone.dispatchEvent(dropEvent)
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
- droparea.fileList.forEach((file, i) => {
289
- expect(file.type).toBe(files[i].type)
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
- it('Size of files can be limited', () => {
294
- container.innerHTML = /* html */ `
295
- <ark-droparea max-size= "2"></ark-droparea>
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
- const droparea = container.querySelector('ark-droparea')
299
- const dropZone = droparea.querySelector('.ark-droparea__form')
300
- const myFile = new File(['image'], 'Doggy.png', {
301
- type: 'image/png'
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
- const dropEvent = createBubbledEvent('drop', {
309
- clientX: 0,
310
- clientY: 1,
311
- dataTransfer: {
312
- files: [myFile, myFile2]
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
- droparea.maxSizeValidate([])
317
- droparea.maxSizeValidate(myFile2)
318
- dropZone.dispatchEvent(dropEvent)
319
- expect(droparea.maxSizeValidate).toBeCalled
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
- const dropEvent = createBubbledEvent('drop', {
343
- clientX: 0,
344
- clientY: 1,
345
- dataTransfer: {
346
- files: [myFile, myFile2]
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
- dropZone.dispatchEvent(dropEvent)
351
- expect(droparea.fileList.length).toBe(1)
352
- expect(droparea.fileList[1]).toBeFalsy()
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
  })
@@ -1 +1,2 @@
1
+ /** Drag-and-drop file input area components. */
1
2
  export { Droparea } from './components/droparea.js'