react-dropzone 11.7.0 → 12.0.2

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