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