react-dropzone 11.5.3 → 12.0.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.
@@ -1,277 +1,437 @@
1
1
  beforeEach(() => {
2
- jest.resetModules()
3
- })
4
-
5
-
6
- describe('fileMatchSize()', () => {
7
- let utils
8
- beforeEach(async done => {
9
- utils = await import('./index')
10
- done()
11
- })
12
-
13
- it('should return true if the file object doesn\'t have a {size} property', () => {
14
- expect(utils.fileMatchSize({})).toEqual([true, null])
15
- expect(utils.fileMatchSize({size: null})).toEqual([true, null])
16
- })
17
-
18
- it('should return true if the minSize and maxSize were not provided', () => {
19
- expect(utils.fileMatchSize({size: 100})).toEqual([true, null])
20
- expect(utils.fileMatchSize({size: 100}, undefined, undefined)).toEqual([true, null])
21
- expect(utils.fileMatchSize({size: 100}, null, null)).toEqual([true, null])
22
- })
23
-
24
- it('should return true if the file {size} is within the [minSize, maxSize] range', () => {
25
- expect(utils.fileMatchSize({size: 100}, 10, 200)).toEqual([true, null])
26
- expect(utils.fileMatchSize({size: 100}, 10, 99)).toEqual([false, { code: 'file-too-large', message: 'File is larger than 99 bytes' }])
27
- expect(utils.fileMatchSize({size: 100}, 101, 200)).toEqual([false, { code: 'file-too-small', message: 'File is smaller than 101 bytes' }])
28
- })
29
-
30
- it('should return true if the file {size} is more than minSize', () => {
31
- expect(utils.fileMatchSize({size: 100}, 100)).toEqual([true, null])
32
- expect(utils.fileMatchSize({size: 100}, 101)).toEqual([false, { code: 'file-too-small', message: 'File is smaller than 101 bytes' }])
33
- })
34
-
35
- it('should return true if the file {size} is less than maxSize', () => {
36
- expect(utils.fileMatchSize({size: 100}, undefined, 100)).toEqual([true, null])
37
- expect(utils.fileMatchSize({size: 100}, null, 100)).toEqual([true, null])
38
- expect(utils.fileMatchSize({size: 100}, undefined, 99)).toEqual([false, { code: 'file-too-large', message: 'File is larger than 99 bytes' }])
39
- expect(utils.fileMatchSize({size: 100}, null, 99)).toEqual([false, { code: 'file-too-large', message: 'File is larger than 99 bytes' }])
40
- })
41
- })
42
-
43
- describe('isIeOrEdge', () => {
44
- let utils
45
- beforeEach(async done => {
46
- utils = await import('./index')
47
- done()
48
- })
49
-
50
- it('should return true for IE10', () => {
2
+ jest.resetModules();
3
+ });
4
+
5
+ describe("fileMatchSize()", () => {
6
+ let utils;
7
+ beforeEach(async () => {
8
+ utils = await import("./index");
9
+ });
10
+
11
+ it("should return true if the file object doesn't have a {size} property", () => {
12
+ expect(utils.fileMatchSize({})).toEqual([true, null]);
13
+ expect(utils.fileMatchSize({ size: null })).toEqual([true, null]);
14
+ });
15
+
16
+ it("should return true if the minSize and maxSize were not provided", () => {
17
+ expect(utils.fileMatchSize({ size: 100 })).toEqual([true, null]);
18
+ expect(utils.fileMatchSize({ size: 100 }, undefined, undefined)).toEqual([
19
+ true,
20
+ null,
21
+ ]);
22
+ expect(utils.fileMatchSize({ size: 100 }, null, null)).toEqual([
23
+ true,
24
+ null,
25
+ ]);
26
+ });
27
+
28
+ it("should return true if the file {size} is within the [minSize, maxSize] range", () => {
29
+ expect(utils.fileMatchSize({ size: 100 }, 10, 200)).toEqual([true, null]);
30
+ expect(utils.fileMatchSize({ size: 100 }, 10, 99)).toEqual([
31
+ false,
32
+ { code: "file-too-large", message: "File is larger than 99 bytes" },
33
+ ]);
34
+ expect(utils.fileMatchSize({ size: 100 }, 101, 200)).toEqual([
35
+ false,
36
+ { code: "file-too-small", message: "File is smaller than 101 bytes" },
37
+ ]);
38
+ });
39
+
40
+ it("should return true if the file {size} is more than minSize", () => {
41
+ expect(utils.fileMatchSize({ size: 100 }, 100)).toEqual([true, null]);
42
+ expect(utils.fileMatchSize({ size: 100 }, 101)).toEqual([
43
+ false,
44
+ { code: "file-too-small", message: "File is smaller than 101 bytes" },
45
+ ]);
46
+ });
47
+
48
+ it("should return true if the file {size} is less than maxSize", () => {
49
+ expect(utils.fileMatchSize({ size: 100 }, undefined, 100)).toEqual([
50
+ true,
51
+ null,
52
+ ]);
53
+ expect(utils.fileMatchSize({ size: 100 }, null, 100)).toEqual([true, null]);
54
+ expect(utils.fileMatchSize({ size: 100 }, undefined, 99)).toEqual([
55
+ false,
56
+ { code: "file-too-large", message: "File is larger than 99 bytes" },
57
+ ]);
58
+ expect(utils.fileMatchSize({ size: 100 }, null, 99)).toEqual([
59
+ false,
60
+ { code: "file-too-large", message: "File is larger than 99 bytes" },
61
+ ]);
62
+ });
63
+ });
64
+
65
+ describe("isIeOrEdge", () => {
66
+ let utils;
67
+ beforeEach(async () => {
68
+ utils = await import("./index");
69
+ });
70
+
71
+ it("should return true for IE10", () => {
51
72
  const userAgent =
52
- 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)'
73
+ "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729)";
53
74
 
54
- expect(utils.isIeOrEdge(userAgent)).toBe(true)
55
- })
75
+ expect(utils.isIeOrEdge(userAgent)).toBe(true);
76
+ });
56
77
 
57
- it('should return true for IE11', () => {
78
+ it("should return true for IE11", () => {
58
79
  const userAgent =
59
- 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko'
60
- expect(utils.isIeOrEdge(userAgent)).toBe(true)
61
- })
80
+ "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko";
81
+ expect(utils.isIeOrEdge(userAgent)).toBe(true);
82
+ });
62
83
 
63
- it('should return true for Edge', () => {
84
+ it("should return true for Edge", () => {
64
85
  const userAgent =
65
- 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16258'
86
+ "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16258";
66
87
 
67
- expect(utils.isIeOrEdge(userAgent)).toBe(true)
68
- })
88
+ expect(utils.isIeOrEdge(userAgent)).toBe(true);
89
+ });
69
90
 
70
- it('should return false for Chrome', () => {
91
+ it("should return false for Chrome", () => {
71
92
  const userAgent =
72
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'
93
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36";
73
94
 
74
- expect(utils.isIeOrEdge(userAgent)).toBe(false)
75
- })
76
- })
95
+ expect(utils.isIeOrEdge(userAgent)).toBe(false);
96
+ });
97
+ });
77
98
 
78
- describe('isKindFile()', () => {
99
+ describe("isKindFile()", () => {
79
100
  it('should return true for DataTransferItem of kind "file"', async () => {
80
- const utils = await import('./index')
81
- expect(utils.isKindFile({ kind: 'file' })).toBe(true)
82
- expect(utils.isKindFile({ kind: 'text/html' })).toBe(false)
83
- expect(utils.isKindFile({})).toBe(false)
84
- expect(utils.isKindFile(null)).toBe(false)
85
- })
86
- })
87
-
88
- describe('isPropagationStopped()', () => {
89
- const trueFn = jest.fn(() => true)
90
-
91
- let utils
92
- beforeEach(async done => {
93
- utils = await import('./index')
94
- done()
95
- })
96
-
97
- it('should return result of isPropagationStopped() if isPropagationStopped exists', () => {
98
- expect(utils.isPropagationStopped({ isPropagationStopped: trueFn })).toBe(true)
99
- })
100
-
101
- it('should return value of cancelBubble if isPropagationStopped doesnt exist and cancelBubble exists', () => {
102
- expect(utils.isPropagationStopped({ cancelBubble: true })).toBe(true)
103
- })
104
-
105
- it('should return false if isPropagationStopped and cancelBubble are missing', () => {
106
- expect(utils.isPropagationStopped({})).toBe(false)
107
- })
108
- })
109
-
110
- describe('isEvtWithFiles()', () => {
111
- let utils
112
- beforeEach(async done => {
113
- utils = await import('./index')
114
- done()
115
- })
116
-
117
- it('should return true if some dragged types are files', () => {
118
- expect(utils.isEvtWithFiles({ dataTransfer: { types: ['Files'] } })).toBe(true)
119
- expect(utils.isEvtWithFiles({ dataTransfer: { types: ['application/x-moz-file'] } })).toBe(true)
101
+ const utils = await import("./index");
102
+ expect(utils.isKindFile({ kind: "file" })).toBe(true);
103
+ expect(utils.isKindFile({ kind: "text/html" })).toBe(false);
104
+ expect(utils.isKindFile({})).toBe(false);
105
+ expect(utils.isKindFile(null)).toBe(false);
106
+ });
107
+ });
108
+
109
+ describe("isPropagationStopped()", () => {
110
+ const trueFn = jest.fn(() => true);
111
+
112
+ let utils;
113
+ beforeEach(async () => {
114
+ utils = await import("./index");
115
+ });
116
+
117
+ it("should return result of isPropagationStopped() if isPropagationStopped exists", () => {
118
+ expect(utils.isPropagationStopped({ isPropagationStopped: trueFn })).toBe(
119
+ true
120
+ );
121
+ });
122
+
123
+ it("should return value of cancelBubble if isPropagationStopped doesnt exist and cancelBubble exists", () => {
124
+ expect(utils.isPropagationStopped({ cancelBubble: true })).toBe(true);
125
+ });
126
+
127
+ it("should return false if isPropagationStopped and cancelBubble are missing", () => {
128
+ expect(utils.isPropagationStopped({})).toBe(false);
129
+ });
130
+ });
131
+
132
+ describe("isEvtWithFiles()", () => {
133
+ let utils;
134
+ beforeEach(async () => {
135
+ utils = await import("./index");
136
+ });
137
+
138
+ it("should return true if some dragged types are files", () => {
139
+ expect(utils.isEvtWithFiles({ dataTransfer: { types: ["Files"] } })).toBe(
140
+ true
141
+ );
120
142
  expect(
121
143
  utils.isEvtWithFiles({
122
- dataTransfer: { types: ['Files', 'application/x-moz-file'] }
144
+ dataTransfer: { types: ["application/x-moz-file"] },
123
145
  })
124
- ).toBe(true)
125
- expect(utils.isEvtWithFiles({ dataTransfer: { types: ['text/plain'] } })).toBe(false)
126
- expect(utils.isEvtWithFiles({ dataTransfer: { types: ['text/html'] } })).toBe(false)
127
- expect(utils.isEvtWithFiles({ dataTransfer: { types: ['Files', 'application/test'] } })).toBe(
128
- true
129
- )
146
+ ).toBe(true);
147
+ expect(
148
+ utils.isEvtWithFiles({
149
+ dataTransfer: { types: ["Files", "application/x-moz-file"] },
150
+ })
151
+ ).toBe(true);
152
+ expect(
153
+ utils.isEvtWithFiles({ dataTransfer: { types: ["text/plain"] } })
154
+ ).toBe(false);
155
+ expect(
156
+ utils.isEvtWithFiles({ dataTransfer: { types: ["text/html"] } })
157
+ ).toBe(false);
158
+ expect(
159
+ utils.isEvtWithFiles({
160
+ dataTransfer: { types: ["Files", "application/test"] },
161
+ })
162
+ ).toBe(true);
130
163
  expect(
131
164
  utils.isEvtWithFiles({
132
- dataTransfer: { types: ['application/x-moz-file', 'application/test'] }
165
+ dataTransfer: { types: ["application/x-moz-file", "application/test"] },
166
+ })
167
+ ).toBe(true);
168
+ });
169
+
170
+ it("should return true if the event has a target with files", () => {
171
+ expect(utils.isEvtWithFiles({ target: { files: [] } })).toBe(true);
172
+ });
173
+
174
+ it("should return false otherwise", () => {
175
+ expect(utils.isEvtWithFiles({})).toBe(false);
176
+ });
177
+ });
178
+
179
+ describe("composeEventHandlers", () => {
180
+ let utils;
181
+ beforeEach(async () => {
182
+ utils = await import("./index");
183
+ });
184
+
185
+ it("returns a fn", () => {
186
+ const fn = utils.composeEventHandlers(() => {});
187
+ expect(typeof fn).toBe("function");
188
+ });
189
+
190
+ it("runs every passed fn in order", () => {
191
+ const fn1 = jest.fn();
192
+ const fn2 = jest.fn();
193
+ const fn = utils.composeEventHandlers(fn1, fn2);
194
+ const event = { type: "click" };
195
+ const data = { ping: true };
196
+ fn(event, data);
197
+ expect(fn1).toHaveBeenCalledWith(event, data);
198
+ expect(fn2).toHaveBeenCalledWith(event, data);
199
+ });
200
+
201
+ it("stops after first fn that calls stopPropagation()", () => {
202
+ const fn1 = jest.fn().mockImplementation((event) => {
203
+ Object.defineProperty(event, "cancelBubble", { value: true });
204
+ return event;
205
+ });
206
+ const fn2 = jest.fn();
207
+ const fn = utils.composeEventHandlers(fn1, fn2);
208
+ const event = new MouseEvent("click");
209
+ fn(event);
210
+ expect(fn1).toHaveBeenCalledWith(event);
211
+ expect(fn2).not.toHaveBeenCalled();
212
+ });
213
+
214
+ it("stops before first fn if bubble is already canceled", () => {
215
+ const fn1 = jest.fn();
216
+ const fn2 = jest.fn();
217
+ const fn = utils.composeEventHandlers(fn1, fn2);
218
+ const event = new MouseEvent("click");
219
+ Object.defineProperty(event, "cancelBubble", { value: true });
220
+ fn(event);
221
+ expect(fn1).not.toHaveBeenCalled();
222
+ expect(fn2).not.toHaveBeenCalled();
223
+ });
224
+ });
225
+
226
+ describe("fileAccepted", () => {
227
+ let utils;
228
+ beforeEach(async () => {
229
+ utils = await import("./index");
230
+ });
231
+
232
+ it("accepts bogus firefox file", () => {
233
+ const file = createFile("bogus.png", 100, "application/x-moz-file");
234
+ expect(utils.fileAccepted(file, ".pdf")).toEqual([true, null]);
235
+ });
236
+
237
+ it("accepts file when single accept criteria", () => {
238
+ const file = createFile("hamster.pdf", 100, "application/pdf");
239
+ expect(utils.fileAccepted(file, ".pdf")).toEqual([true, null]);
240
+ });
241
+
242
+ it("accepts file when multiple accept criteria", () => {
243
+ const file = createFile("hamster.pdf", 100, "application/pdf");
244
+ expect(utils.fileAccepted(file, [".pdf", ".png"])).toEqual([true, null]);
245
+ });
246
+
247
+ it("rejects file when single accept criteria", () => {
248
+ const file = createFile("hamster.pdf", 100, "application/pdf");
249
+ expect(utils.fileAccepted(file, ".png")).toEqual([
250
+ false,
251
+ { code: "file-invalid-type", message: "File type must be .png" },
252
+ ]);
253
+ });
254
+
255
+ it("rejects file when multiple accept criteria", () => {
256
+ const file = createFile("hamster.pdf", 100, "application/pdf");
257
+ expect(utils.fileAccepted(file, [".gif", ".png"])).toEqual([
258
+ false,
259
+ {
260
+ code: "file-invalid-type",
261
+ message: "File type must be one of .gif, .png",
262
+ },
263
+ ]);
264
+ });
265
+
266
+ it("rejects file when single accept criteria as array", () => {
267
+ const file = createFile("hamster.pdf", 100, "application/pdf");
268
+ expect(utils.fileAccepted(file, [".gif"])).toEqual([
269
+ false,
270
+ { code: "file-invalid-type", message: "File type must be .gif" },
271
+ ]);
272
+ });
273
+ });
274
+
275
+ describe("allFilesAccepted()", () => {
276
+ let utils;
277
+ beforeEach(async () => {
278
+ utils = await import("./index");
279
+ });
280
+ it("rejects file when multiple accept criteria", () => {
281
+ const files = [
282
+ createFile("hamster.pdf", 100, "application/pdf"),
283
+ createFile("fish.pdf", 100, "application/pdf"),
284
+ ];
285
+ const images = [
286
+ createFile("cats.gif", 1234, "image/gif"),
287
+ createFile("dogs.gif", 2345, "image/jpeg"),
288
+ ];
289
+ expect(utils.allFilesAccepted({ files, multiple: true })).toEqual(true);
290
+ expect(
291
+ utils.allFilesAccepted({ files, multiple: true, maxFiles: 10 })
292
+ ).toEqual(true);
293
+ expect(
294
+ utils.allFilesAccepted({ files, multiple: false, maxFiles: 10 })
295
+ ).toEqual(false);
296
+ expect(
297
+ utils.allFilesAccepted({ files, multiple: true, accept: "image/jpeg" })
298
+ ).toEqual(false);
299
+ expect(
300
+ utils.allFilesAccepted({
301
+ files: images,
302
+ multiple: true,
303
+ accept: "image/*",
133
304
  })
134
- ).toBe(true)
135
- })
136
-
137
- it('should return true if the event has a target with files', () => {
138
- expect(utils.isEvtWithFiles({ target: { files: [] } })).toBe(true)
139
- })
140
-
141
- it('should return false otherwise', () => {
142
- expect(utils.isEvtWithFiles({})).toBe(false)
143
- })
144
- })
145
-
146
- describe('composeEventHandlers', () => {
147
- let utils
148
- beforeEach(async done => {
149
- utils = await import('./index')
150
- done()
151
- })
152
-
153
- it('returns a fn', () => {
154
- const fn = utils.composeEventHandlers(() => {})
155
- expect(typeof fn).toBe('function')
156
- })
157
-
158
- it('runs every passed fn in order', () => {
159
- const fn1 = jest.fn()
160
- const fn2 = jest.fn()
161
- const fn = utils.composeEventHandlers(fn1, fn2)
162
- const event = { type: 'click' }
163
- const data = { ping: true }
164
- fn(event, data)
165
- expect(fn1).toHaveBeenCalledWith(event, data)
166
- expect(fn2).toHaveBeenCalledWith(event, data)
167
- })
168
-
169
- it('stops after first fn that calls stopPropagation()', () => {
170
- const fn1 = jest.fn().mockImplementation(event => {
171
- Object.defineProperty(event, 'cancelBubble', { value: true })
172
- return event
173
- })
174
- const fn2 = jest.fn()
175
- const fn = utils.composeEventHandlers(fn1, fn2)
176
- const event = new MouseEvent('click')
177
- fn(event)
178
- expect(fn1).toHaveBeenCalledWith(event)
179
- expect(fn2).not.toHaveBeenCalled()
180
- })
181
-
182
- it('stops before first fn if bubble is already canceled', () => {
183
- const fn1 = jest.fn()
184
- const fn2 = jest.fn()
185
- const fn = utils.composeEventHandlers(fn1, fn2)
186
- const event = new MouseEvent('click')
187
- Object.defineProperty(event, 'cancelBubble', { value: true })
188
- fn(event)
189
- expect(fn1).not.toHaveBeenCalled()
190
- expect(fn2).not.toHaveBeenCalled()
191
- })
192
- })
193
-
194
- describe('fileAccepted', () => {
195
- let utils
196
- beforeEach(async done => {
197
- utils = await import('./index')
198
- done()
199
- })
200
-
201
- it('accepts bogus firefox file', () => {
202
- const file = createFile('bogus.png', 100, 'application/x-moz-file');
203
- expect(utils.fileAccepted(file, '.pdf')).toEqual([true, null])
204
- })
205
-
206
- it('accepts file when single accept criteria', () => {
207
- const file = createFile('hamster.pdf', 100, 'application/pdf');
208
- expect(utils.fileAccepted(file, '.pdf')).toEqual([true, null])
209
- })
210
-
211
- it('accepts file when multiple accept criteria', () => {
212
- const file = createFile('hamster.pdf', 100, 'application/pdf');
213
- expect(utils.fileAccepted(file, ['.pdf', '.png'])).toEqual([true, null])
214
- })
215
-
216
- it('rejects file when single accept criteria', () => {
217
- const file = createFile('hamster.pdf', 100, 'application/pdf');
218
- expect(utils.fileAccepted(file, '.png')).toEqual([false, { code: 'file-invalid-type', message: 'File type must be .png' }])
219
- })
220
-
221
- it('rejects file when multiple accept criteria', () => {
222
- const file = createFile('hamster.pdf', 100, 'application/pdf');
223
- expect(utils.fileAccepted(file, ['.gif', '.png'])).toEqual([false, { code: 'file-invalid-type', message: 'File type must be one of .gif, .png' }])
224
- })
225
-
226
- it('rejects file when single accept criteria as array', () => {
227
- const file = createFile('hamster.pdf', 100, 'application/pdf');
228
- expect(utils.fileAccepted(file, ['.gif'])).toEqual([false, { code: 'file-invalid-type', message: 'File type must be .gif' }])
229
- })
230
-
231
- })
232
-
233
- describe('allFilesAccepted()', () => {
234
- let utils
235
- beforeEach(async done => {
236
- utils = await import('./index')
237
- done()
238
- })
239
- it('rejects file when multiple accept criteria', () => {
240
- const files = [createFile('hamster.pdf', 100, 'application/pdf'),createFile('fish.pdf', 100, 'application/pdf')];
241
- const images = [createFile('cats.gif', 1234, 'image/gif'), createFile('dogs.gif', 2345, 'image/jpeg')]
242
- expect(utils.allFilesAccepted({ files, multiple: true})).toEqual(true)
243
- expect(utils.allFilesAccepted({ files, multiple: true, maxFiles: 10 })).toEqual(true)
244
- expect(utils.allFilesAccepted({ files, multiple: false, maxFiles: 10 })).toEqual(false)
245
- expect(utils.allFilesAccepted({ files, multiple: true, accept:'image/jpeg' })).toEqual(false)
246
- expect(utils.allFilesAccepted({ files: images, multiple: true,accept:'image/*' })).toEqual(true)
247
- expect(utils.allFilesAccepted({ files, multiple: true, minSize: 110 })).toEqual(false)
248
- expect(utils.allFilesAccepted({ files, multiple: true, maxSize: 99 })).toEqual(false)
249
- expect(utils.allFilesAccepted({ files, multiple: true, maxFiles: 1 })).toEqual(false)
250
- })
251
- })
305
+ ).toEqual(true);
306
+ expect(
307
+ utils.allFilesAccepted({ files, multiple: true, minSize: 110 })
308
+ ).toEqual(false);
309
+ expect(
310
+ utils.allFilesAccepted({ files, multiple: true, maxSize: 99 })
311
+ ).toEqual(false);
312
+ expect(
313
+ utils.allFilesAccepted({ files, multiple: true, maxFiles: 1 })
314
+ ).toEqual(false);
315
+ });
316
+ });
317
+
318
+ describe("ErrorCode", () => {
319
+ let utils;
320
+ beforeEach(async () => {
321
+ utils = await import("./index");
322
+ });
323
+
324
+ it("should exist and have known error code properties", () => {
325
+ expect(utils.ErrorCode.FileInvalidType).toEqual(utils.FILE_INVALID_TYPE);
326
+ expect(utils.ErrorCode.FileTooLarge).toEqual(utils.FILE_TOO_LARGE);
327
+ expect(utils.ErrorCode.FileTooSmall).toEqual(utils.FILE_TOO_SMALL);
328
+ expect(utils.ErrorCode.TooManyFiles).toEqual(utils.TOO_MANY_FILES);
329
+ });
330
+ });
331
+
332
+ describe("canUseFileSystemAccessAPI()", () => {
333
+ let utils;
334
+ beforeEach(async () => {
335
+ utils = await import("./index");
336
+ });
337
+
338
+ it("should return false if not", () => {
339
+ expect(utils.canUseFileSystemAccessAPI()).toBe(false);
340
+ });
341
+
342
+ it("should return true if yes", () => {
343
+ // TODO: If we use these in other tests, restore once test is done
344
+ window.showOpenFilePicker = jest.fn();
345
+ expect(utils.canUseFileSystemAccessAPI()).toBe(true);
346
+ });
347
+ });
348
+
349
+ describe("filePickerOptionsTypes()", () => {
350
+ let utils;
351
+ beforeEach(async () => {
352
+ utils = await import("./index");
353
+ });
354
+
355
+ it("should return proper types when the arg is a MIME type", () => {
356
+ expect(utils.filePickerOptionsTypes("application/zip")).toEqual([
357
+ {
358
+ description: "everything",
359
+ accept: { "application/zip": [] },
360
+ },
361
+ ]);
362
+ });
363
+
364
+ it("should return proper types when the arg is an array of MIME types", () => {
365
+ expect(
366
+ utils.filePickerOptionsTypes(["application/zip", "application/json"])
367
+ ).toEqual([
368
+ {
369
+ description: "everything",
370
+ accept: {
371
+ "application/zip": [],
372
+ "application/json": [],
373
+ },
374
+ },
375
+ ]);
376
+ });
377
+
378
+ it("should exclude anything that's not a MIME type", () => {
379
+ expect(
380
+ utils.filePickerOptionsTypes([
381
+ "audio/*",
382
+ "video/*",
383
+ "image/*",
384
+ ".txt",
385
+ "text/*",
386
+ ])
387
+ ).toEqual([
388
+ {
389
+ description: "everything",
390
+ accept: {
391
+ "audio/*": [],
392
+ "video/*": [],
393
+ "image/*": [],
394
+ "text/*": [],
395
+ },
396
+ },
397
+ ]);
398
+ });
399
+
400
+ it("should work with comma separated string of MIME types", () => {
401
+ expect(
402
+ utils.filePickerOptionsTypes(
403
+ "audio/*,video/*,image/*,.txt,text/*,application/zip"
404
+ )
405
+ ).toEqual([
406
+ {
407
+ description: "everything",
408
+ accept: {
409
+ "audio/*": [],
410
+ "video/*": [],
411
+ "image/*": [],
412
+ "text/*": [],
413
+ "application/zip": [],
414
+ },
415
+ },
416
+ ]);
417
+ });
418
+
419
+ it("should return empty otherwise", () => {
420
+ expect(utils.filePickerOptionsTypes("")).toEqual([
421
+ {
422
+ description: "everything",
423
+ accept: {},
424
+ },
425
+ ]);
426
+ });
427
+ });
252
428
 
253
429
  function createFile(name, size, type) {
254
- const file = new File([], name, { type })
255
- Object.defineProperty(file, 'size', {
430
+ const file = new File([], name, { type });
431
+ Object.defineProperty(file, "size", {
256
432
  get() {
257
- return size
258
- }
259
- })
260
- return file
433
+ return size;
434
+ },
435
+ });
436
+ return file;
261
437
  }
262
-
263
- describe('ErrorCode', () => {
264
- let utils
265
- beforeEach(async done => {
266
- utils = await import('./index')
267
- done()
268
- })
269
-
270
- it('should exist and have known error code properties', () => {
271
- expect(utils.ErrorCode.FileInvalidType).toEqual(utils.FILE_INVALID_TYPE)
272
- expect(utils.ErrorCode.FileTooLarge).toEqual(utils.FILE_TOO_LARGE)
273
- expect(utils.ErrorCode.FileTooSmall).toEqual(utils.FILE_TOO_SMALL)
274
- expect(utils.ErrorCode.TooManyFiles).toEqual(utils.TOO_MANY_FILES)
275
- })
276
- })
277
-