@react-magma/dropzone 13.0.0 → 13.0.1-next.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.
- package/dist/fileuploader.js.map +1 -1
- package/dist/{fileuploader.modern.mjs → fileuploader.modern.js} +1 -1
- package/dist/fileuploader.modern.js.map +1 -0
- package/dist/fileuploader.modern.module.js.map +1 -1
- package/dist/fileuploader.umd.js.map +1 -1
- package/dist/src/src/components/dropzone/Dropzone.d.ts +101 -101
- package/dist/src/src/components/dropzone/Dropzone.stories.d.ts +48 -0
- package/dist/src/src/components/dropzone/Dropzone.test.d.ts +1 -1
- package/dist/src/src/components/dropzone/FileIcon.d.ts +8 -7
- package/dist/src/src/components/dropzone/FilePreview.d.ts +15 -15
- package/dist/src/src/components/dropzone/Preview.d.ts +18 -18
- package/dist/src/src/components/dropzone/index.d.ts +4 -4
- package/dist/src/src/components/dropzone/utils.d.ts +1 -1
- package/dist/src/src/index.d.ts +1 -1
- package/package.json +15 -18
- package/src/components/dropzone/Dropzone.stories.tsx +0 -4
- package/src/components/dropzone/Dropzone.test.js +120 -205
- package/src/components/dropzone/Dropzone.tsx +1 -4
- package/src/components/dropzone/Preview.tsx +150 -152
- package/src/components/dropzone/utils.ts +0 -1
- package/dist/fileuploader.modern.mjs.map +0 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
cleanup,
|
|
5
|
+
render,
|
|
6
|
+
act,
|
|
7
|
+
fireEvent,
|
|
8
|
+
waitFor,
|
|
9
|
+
} from '@testing-library/react';
|
|
4
10
|
import userEvent from '@testing-library/user-event';
|
|
5
11
|
import { I18nContext, defaultI18n, magma } from 'react-magma-dom';
|
|
6
12
|
|
|
@@ -15,6 +21,7 @@ describe('File Uploader', () => {
|
|
|
15
21
|
window.URL.revokeObjectURL = jest.fn();
|
|
16
22
|
|
|
17
23
|
beforeEach(() => {
|
|
24
|
+
jest.useFakeTimers();
|
|
18
25
|
files = [createFile('file1.pdf', 1111, 'application/pdf')];
|
|
19
26
|
images = [
|
|
20
27
|
createFile('cats.png', 1234, 'image/png'),
|
|
@@ -23,6 +30,7 @@ describe('File Uploader', () => {
|
|
|
23
30
|
});
|
|
24
31
|
|
|
25
32
|
afterEach(() => {
|
|
33
|
+
jest.useRealTimers();
|
|
26
34
|
window.URL.createObjectURL.mockReset();
|
|
27
35
|
cleanup();
|
|
28
36
|
});
|
|
@@ -48,7 +56,6 @@ describe('File Uploader', () => {
|
|
|
48
56
|
|
|
49
57
|
it('should find element by testId', () => {
|
|
50
58
|
const testId = 'test-id';
|
|
51
|
-
|
|
52
59
|
const { getByTestId } = render(<Dropzone testId={testId} />);
|
|
53
60
|
|
|
54
61
|
expect(getByTestId(testId)).toBeInTheDocument();
|
|
@@ -58,16 +65,21 @@ describe('File Uploader', () => {
|
|
|
58
65
|
const { getByRole, getByTestId } = render(<Dropzone testId="testId" />);
|
|
59
66
|
|
|
60
67
|
const fileInputClickFn = jest.fn();
|
|
68
|
+
|
|
61
69
|
const fileInput = getByTestId('file-input');
|
|
62
70
|
|
|
63
71
|
fileInput.click = fileInputClickFn;
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
userEvent.click(getByRole('button'));
|
|
66
74
|
|
|
67
|
-
|
|
75
|
+
await waitFor(() => {
|
|
76
|
+
expect(fileInputClickFn).toHaveBeenCalled();
|
|
77
|
+
});
|
|
68
78
|
});
|
|
69
79
|
|
|
70
80
|
it('Does not violate accessibility standards', () => {
|
|
81
|
+
jest.useRealTimers();
|
|
82
|
+
|
|
71
83
|
const { container } = render(<Dropzone />);
|
|
72
84
|
|
|
73
85
|
return axe(container.innerHTML).then(result => {
|
|
@@ -77,7 +89,6 @@ describe('File Uploader', () => {
|
|
|
77
89
|
|
|
78
90
|
it('Supports i18n', () => {
|
|
79
91
|
const browseFiles = 'find those files';
|
|
80
|
-
|
|
81
92
|
const { getByText } = render(
|
|
82
93
|
<I18nContext.Provider
|
|
83
94
|
value={{
|
|
@@ -97,11 +108,9 @@ describe('File Uploader', () => {
|
|
|
97
108
|
|
|
98
109
|
it('sets {accept} prop on the <input>', () => {
|
|
99
110
|
const accept = 'image/jpeg';
|
|
100
|
-
|
|
101
111
|
const { container } = render(<Dropzone accept={accept} />);
|
|
102
112
|
|
|
103
113
|
const input = container.querySelector('input');
|
|
104
|
-
|
|
105
114
|
expect(input).toHaveAttribute('accept', accept);
|
|
106
115
|
});
|
|
107
116
|
|
|
@@ -109,7 +118,6 @@ describe('File Uploader', () => {
|
|
|
109
118
|
const { container } = render(<Dropzone multiple />);
|
|
110
119
|
|
|
111
120
|
const input = container.querySelector('input');
|
|
112
|
-
|
|
113
121
|
expect(input).toHaveAttribute('multiple');
|
|
114
122
|
});
|
|
115
123
|
|
|
@@ -117,45 +125,35 @@ describe('File Uploader', () => {
|
|
|
117
125
|
const { container } = render(<Dropzone />);
|
|
118
126
|
|
|
119
127
|
const dropzone = container.querySelector('div');
|
|
128
|
+
|
|
120
129
|
const dropEvt = new Event('drop', { bubbles: true });
|
|
121
130
|
const dropEvtPreventDefaultSpy = jest.spyOn(dropEvt, 'preventDefault');
|
|
122
131
|
|
|
123
132
|
fireEvent(dropzone, dropEvt);
|
|
124
|
-
|
|
125
133
|
expect(dropEvtPreventDefaultSpy).toHaveBeenCalled();
|
|
126
134
|
});
|
|
127
135
|
|
|
128
136
|
it('border color changes for success', async () => {
|
|
129
137
|
const data = createDtWithFiles(files);
|
|
130
138
|
const testId = 'testId';
|
|
131
|
-
|
|
132
139
|
const ui = <Dropzone testId={testId} />;
|
|
133
|
-
|
|
134
140
|
const { getByTestId, rerender } = render(ui);
|
|
135
141
|
|
|
136
142
|
const dropzone = getByTestId(testId);
|
|
137
|
-
|
|
138
143
|
expect(dropzone).toHaveStyle(
|
|
139
144
|
`border: 1px dashed ${magma.colors.neutral400}`
|
|
140
145
|
);
|
|
141
146
|
|
|
142
147
|
fireDragEnter(dropzone, data);
|
|
148
|
+
await flushPromises(rerender, ui);
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
await waitFor(() => {
|
|
147
|
-
expect(dropzone).toHaveStyle(
|
|
148
|
-
`border: 1px dashed ${magma.colors.success}`
|
|
149
|
-
);
|
|
150
|
-
});
|
|
150
|
+
expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.success}`);
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it('border color changes for rejection', async () => {
|
|
154
154
|
const data = createDtWithFiles(files);
|
|
155
155
|
const testId = 'testId';
|
|
156
|
-
|
|
157
156
|
const ui = <Dropzone accept="image/*" testId={testId} />;
|
|
158
|
-
|
|
159
157
|
const { getByTestId, rerender } = render(ui);
|
|
160
158
|
|
|
161
159
|
const dropzone = getByTestId(testId);
|
|
@@ -164,17 +162,13 @@ describe('File Uploader', () => {
|
|
|
164
162
|
);
|
|
165
163
|
|
|
166
164
|
fireDragEnter(dropzone, data);
|
|
165
|
+
await flushPromises(rerender, ui);
|
|
167
166
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
await waitFor(() => {
|
|
171
|
-
expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.danger}`);
|
|
172
|
-
});
|
|
167
|
+
expect(dropzone).toHaveStyle(`border: 1px dashed ${magma.colors.danger}`);
|
|
173
168
|
});
|
|
174
169
|
|
|
175
170
|
it('calls onSendFiles for a single file added via the input', async () => {
|
|
176
171
|
const onSendFileSpy = jest.fn();
|
|
177
|
-
|
|
178
172
|
const ui = <Dropzone sendFiles onSendFile={onSendFileSpy} />;
|
|
179
173
|
|
|
180
174
|
const { container, rerender } = render(ui);
|
|
@@ -183,19 +177,15 @@ describe('File Uploader', () => {
|
|
|
183
177
|
Object.defineProperty(input, 'files', { value: files });
|
|
184
178
|
|
|
185
179
|
dispatchEvt(input, 'change');
|
|
180
|
+
await flushPromises(rerender, ui);
|
|
186
181
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
191
|
-
expect.objectContaining({ file: files[0] })
|
|
192
|
-
);
|
|
193
|
-
});
|
|
182
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
183
|
+
expect.objectContaining({ file: files[0] })
|
|
184
|
+
);
|
|
194
185
|
});
|
|
195
186
|
|
|
196
187
|
it('calls onSendFiles for multiple files added via the input', async () => {
|
|
197
188
|
const onSendFileSpy = jest.fn();
|
|
198
|
-
|
|
199
189
|
const ui = <Dropzone sendFiles onSendFile={onSendFileSpy} />;
|
|
200
190
|
|
|
201
191
|
const { container, rerender } = render(ui);
|
|
@@ -204,17 +194,14 @@ describe('File Uploader', () => {
|
|
|
204
194
|
Object.defineProperty(input, 'files', { value: images });
|
|
205
195
|
|
|
206
196
|
dispatchEvt(input, 'change');
|
|
197
|
+
await flushPromises(rerender, ui);
|
|
207
198
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
215
|
-
expect.objectContaining({ file: images[1] })
|
|
216
|
-
);
|
|
217
|
-
});
|
|
199
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
200
|
+
expect.objectContaining({ file: images[0] })
|
|
201
|
+
);
|
|
202
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
203
|
+
expect.objectContaining({ file: images[1] })
|
|
204
|
+
);
|
|
218
205
|
});
|
|
219
206
|
|
|
220
207
|
it('calls onSendFiles for a single file added via drop', async () => {
|
|
@@ -225,20 +212,16 @@ describe('File Uploader', () => {
|
|
|
225
212
|
const ui = (
|
|
226
213
|
<Dropzone sendFiles onSendFile={onSendFileSpy} testId={testId} />
|
|
227
214
|
);
|
|
228
|
-
|
|
229
215
|
const { getByTestId, rerender } = render(ui);
|
|
230
216
|
|
|
231
217
|
const dropzone = getByTestId(testId);
|
|
232
|
-
|
|
233
218
|
fireDrop(dropzone, data);
|
|
234
219
|
|
|
235
|
-
rerender
|
|
220
|
+
await flushPromises(rerender, ui);
|
|
236
221
|
|
|
237
|
-
|
|
238
|
-
expect(
|
|
239
|
-
|
|
240
|
-
);
|
|
241
|
-
});
|
|
222
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
223
|
+
expect.objectContaining({ file: files[0] })
|
|
224
|
+
);
|
|
242
225
|
});
|
|
243
226
|
|
|
244
227
|
it('calls onSendFiles for a multiple files added via drop', async () => {
|
|
@@ -249,23 +232,19 @@ describe('File Uploader', () => {
|
|
|
249
232
|
const ui = (
|
|
250
233
|
<Dropzone sendFiles onSendFile={onSendFileSpy} testId={testId} />
|
|
251
234
|
);
|
|
252
|
-
|
|
253
235
|
const { getByTestId, rerender } = render(ui);
|
|
254
236
|
|
|
255
237
|
const dropzone = getByTestId(testId);
|
|
256
|
-
|
|
257
238
|
fireDrop(dropzone, data);
|
|
258
239
|
|
|
259
|
-
rerender
|
|
240
|
+
await flushPromises(rerender, ui);
|
|
260
241
|
|
|
261
|
-
|
|
262
|
-
expect(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
expect(
|
|
266
|
-
|
|
267
|
-
);
|
|
268
|
-
});
|
|
242
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
243
|
+
expect.objectContaining({ file: images[0] })
|
|
244
|
+
);
|
|
245
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
246
|
+
expect.objectContaining({ file: images[1] })
|
|
247
|
+
);
|
|
269
248
|
});
|
|
270
249
|
|
|
271
250
|
it('delays calling onSendFiles until sendFiles is true', async () => {
|
|
@@ -280,26 +259,20 @@ describe('File Uploader', () => {
|
|
|
280
259
|
testId={testId}
|
|
281
260
|
/>
|
|
282
261
|
);
|
|
283
|
-
|
|
284
262
|
const { getByTestId, rerender } = render(ui(false));
|
|
285
263
|
|
|
286
264
|
const dropzone = getByTestId(testId);
|
|
287
|
-
|
|
288
265
|
fireDrop(dropzone, data);
|
|
289
266
|
|
|
290
|
-
rerender
|
|
267
|
+
await flushPromises(rerender, ui(false));
|
|
291
268
|
|
|
292
|
-
|
|
293
|
-
expect(onSendFileSpy).not.toHaveBeenCalled();
|
|
294
|
-
});
|
|
269
|
+
expect(onSendFileSpy).not.toHaveBeenCalled();
|
|
295
270
|
|
|
296
|
-
rerender
|
|
271
|
+
await flushPromises(rerender, ui(true));
|
|
297
272
|
|
|
298
|
-
|
|
299
|
-
expect(
|
|
300
|
-
|
|
301
|
-
);
|
|
302
|
-
});
|
|
273
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
274
|
+
expect.objectContaining({ file: files[0] })
|
|
275
|
+
);
|
|
303
276
|
});
|
|
304
277
|
|
|
305
278
|
it('adds files to the file list', async () => {
|
|
@@ -311,14 +284,11 @@ describe('File Uploader', () => {
|
|
|
311
284
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
312
285
|
|
|
313
286
|
const dropzone = getByTestId(testId);
|
|
314
|
-
|
|
315
287
|
fireDrop(dropzone, data);
|
|
316
288
|
|
|
317
|
-
rerender
|
|
289
|
+
await flushPromises(rerender, ui);
|
|
318
290
|
|
|
319
|
-
|
|
320
|
-
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
321
|
-
});
|
|
291
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
322
292
|
});
|
|
323
293
|
|
|
324
294
|
it('preview for image files in the file list by default', async () => {
|
|
@@ -331,14 +301,11 @@ describe('File Uploader', () => {
|
|
|
331
301
|
const { getByTestId, getByRole, rerender } = render(ui);
|
|
332
302
|
|
|
333
303
|
const dropzone = getByTestId(testId);
|
|
334
|
-
|
|
335
304
|
fireDrop(dropzone, data);
|
|
336
305
|
|
|
337
|
-
rerender
|
|
306
|
+
await flushPromises(rerender, ui);
|
|
338
307
|
|
|
339
|
-
|
|
340
|
-
expect(getByRole('img')).toBeInTheDocument();
|
|
341
|
-
});
|
|
308
|
+
expect(getByRole('img')).toBeInTheDocument();
|
|
342
309
|
});
|
|
343
310
|
|
|
344
311
|
it('previews for image files can be disabled', async () => {
|
|
@@ -353,14 +320,11 @@ describe('File Uploader', () => {
|
|
|
353
320
|
const { getByTestId, queryByRole, rerender } = render(ui);
|
|
354
321
|
|
|
355
322
|
const dropzone = getByTestId(testId);
|
|
356
|
-
|
|
357
323
|
fireDrop(dropzone, data);
|
|
358
324
|
|
|
359
|
-
rerender
|
|
325
|
+
await flushPromises(rerender, ui);
|
|
360
326
|
|
|
361
|
-
|
|
362
|
-
expect(queryByRole('img')).not.toBeInTheDocument();
|
|
363
|
-
});
|
|
327
|
+
expect(queryByRole('img')).not.toBeInTheDocument();
|
|
364
328
|
});
|
|
365
329
|
|
|
366
330
|
it('shows errors on invalid file types in the file list', async () => {
|
|
@@ -372,14 +336,11 @@ describe('File Uploader', () => {
|
|
|
372
336
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
373
337
|
|
|
374
338
|
const dropzone = getByTestId(testId);
|
|
375
|
-
|
|
376
339
|
fireDrop(dropzone, data);
|
|
377
340
|
|
|
378
|
-
rerender
|
|
341
|
+
await flushPromises(rerender, ui);
|
|
379
342
|
|
|
380
|
-
|
|
381
|
-
expect(getByText('Invalid File Type')).toBeInTheDocument();
|
|
382
|
-
});
|
|
343
|
+
expect(getByText('Invalid File Type')).toBeInTheDocument();
|
|
383
344
|
});
|
|
384
345
|
|
|
385
346
|
it('shows errors on too many files in the file list', async () => {
|
|
@@ -391,16 +352,13 @@ describe('File Uploader', () => {
|
|
|
391
352
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
392
353
|
|
|
393
354
|
const dropzone = getByTestId(testId);
|
|
394
|
-
|
|
395
355
|
fireDrop(dropzone, data);
|
|
396
356
|
|
|
397
|
-
rerender
|
|
357
|
+
await flushPromises(rerender, ui);
|
|
398
358
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
).toBeInTheDocument();
|
|
403
|
-
});
|
|
359
|
+
expect(
|
|
360
|
+
getByText('You must upload a maximum of 1 files.')
|
|
361
|
+
).toBeInTheDocument();
|
|
404
362
|
});
|
|
405
363
|
|
|
406
364
|
it('shows errors on too few files in the file list', async () => {
|
|
@@ -414,13 +372,11 @@ describe('File Uploader', () => {
|
|
|
414
372
|
const dropzone = getByTestId(testId);
|
|
415
373
|
fireDrop(dropzone, data);
|
|
416
374
|
|
|
417
|
-
rerender
|
|
375
|
+
await flushPromises(rerender, ui);
|
|
418
376
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
).toBeInTheDocument();
|
|
423
|
-
});
|
|
377
|
+
expect(
|
|
378
|
+
getByText('You must upload a minimum of 6 files.')
|
|
379
|
+
).toBeInTheDocument();
|
|
424
380
|
});
|
|
425
381
|
|
|
426
382
|
it('shows errors on too large of a file in the file list', async () => {
|
|
@@ -432,16 +388,13 @@ describe('File Uploader', () => {
|
|
|
432
388
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
433
389
|
|
|
434
390
|
const dropzone = getByTestId(testId);
|
|
435
|
-
|
|
436
391
|
fireDrop(dropzone, data);
|
|
437
392
|
|
|
438
|
-
rerender
|
|
393
|
+
await flushPromises(rerender, ui);
|
|
439
394
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
).toBeInTheDocument();
|
|
444
|
-
});
|
|
395
|
+
expect(
|
|
396
|
+
getByText('Upload only files with a maximum size of 1 Bytes.')
|
|
397
|
+
).toBeInTheDocument();
|
|
445
398
|
});
|
|
446
399
|
|
|
447
400
|
it('shows errors on too small of a file in the file list', async () => {
|
|
@@ -453,16 +406,13 @@ describe('File Uploader', () => {
|
|
|
453
406
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
454
407
|
|
|
455
408
|
const dropzone = getByTestId(testId);
|
|
456
|
-
|
|
457
409
|
fireDrop(dropzone, data);
|
|
458
410
|
|
|
459
|
-
rerender
|
|
411
|
+
await flushPromises(rerender, ui);
|
|
460
412
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
).toBeInTheDocument();
|
|
465
|
-
});
|
|
413
|
+
expect(
|
|
414
|
+
getByText('Upload only files with a minimum size of 9.77 KB.')
|
|
415
|
+
).toBeInTheDocument();
|
|
466
416
|
});
|
|
467
417
|
|
|
468
418
|
it('adds a Spinner to files in progress', async () => {
|
|
@@ -477,16 +427,13 @@ describe('File Uploader', () => {
|
|
|
477
427
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
478
428
|
|
|
479
429
|
const dropzone = getByTestId(testId);
|
|
480
|
-
|
|
481
430
|
fireDrop(dropzone, data);
|
|
482
431
|
|
|
483
|
-
rerender
|
|
432
|
+
await flushPromises(rerender, ui);
|
|
484
433
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
expect(getByLabelText('Loading')).toBeInTheDocument();
|
|
489
|
-
});
|
|
434
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
435
|
+
expect(getByText('25%')).toBeInTheDocument();
|
|
436
|
+
expect(getByLabelText('Loading')).toBeInTheDocument();
|
|
490
437
|
});
|
|
491
438
|
|
|
492
439
|
it('shows an error in the file list on error', async () => {
|
|
@@ -510,18 +457,14 @@ describe('File Uploader', () => {
|
|
|
510
457
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
511
458
|
|
|
512
459
|
const dropzone = getByTestId(testId);
|
|
513
|
-
|
|
514
460
|
fireDrop(dropzone, data);
|
|
515
461
|
|
|
516
|
-
rerender
|
|
462
|
+
await flushPromises(rerender, ui);
|
|
517
463
|
|
|
518
|
-
|
|
519
|
-
expect(getByText('error from the processor')).toBeInTheDocument();
|
|
520
|
-
});
|
|
464
|
+
expect(getByText('error from the processor')).toBeInTheDocument();
|
|
521
465
|
});
|
|
522
466
|
|
|
523
|
-
|
|
524
|
-
xit('changes to delete file on finish', async () => {
|
|
467
|
+
it('changes to delete file on finish', async () => {
|
|
525
468
|
const onSendFile = ({ file, onFinish }) => {
|
|
526
469
|
onFinish({ file });
|
|
527
470
|
};
|
|
@@ -533,23 +476,19 @@ describe('File Uploader', () => {
|
|
|
533
476
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
534
477
|
|
|
535
478
|
const dropzone = getByTestId(testId);
|
|
479
|
+
act(() => fireDrop(dropzone, data));
|
|
536
480
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
rerender(ui);
|
|
481
|
+
await flushPromises(rerender, ui);
|
|
482
|
+
await act(() => waitFor(() => getByLabelText('Delete file')));
|
|
540
483
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
expect(getByLabelText('Delete file')).toBeInTheDocument();
|
|
544
|
-
});
|
|
484
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
485
|
+
expect(getByLabelText('Delete file')).toBeInTheDocument();
|
|
545
486
|
});
|
|
546
487
|
|
|
547
|
-
|
|
548
|
-
xit('deletes the file when the Delete File icon is clicked', async () => {
|
|
488
|
+
it('deletes the file when the Delete File icon is clicked', async () => {
|
|
549
489
|
const onSendFile = ({ file, onFinish }) => {
|
|
550
490
|
onFinish({ file });
|
|
551
491
|
};
|
|
552
|
-
|
|
553
492
|
const data = createDtWithFiles(files);
|
|
554
493
|
const testId = 'testId';
|
|
555
494
|
|
|
@@ -559,27 +498,21 @@ describe('File Uploader', () => {
|
|
|
559
498
|
render(ui);
|
|
560
499
|
|
|
561
500
|
const dropzone = getByTestId(testId);
|
|
562
|
-
fireDrop(dropzone, data);
|
|
563
|
-
|
|
564
|
-
rerender(ui);
|
|
501
|
+
act(() => fireDrop(dropzone, data));
|
|
565
502
|
|
|
566
|
-
await
|
|
567
|
-
|
|
568
|
-
});
|
|
503
|
+
await flushPromises(rerender, ui);
|
|
504
|
+
await act(() => waitFor(() => getByLabelText('Delete file')));
|
|
569
505
|
|
|
506
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
570
507
|
const deleteIcon = getByLabelText('Delete file');
|
|
571
508
|
|
|
572
|
-
|
|
509
|
+
userEvent.click(deleteIcon);
|
|
573
510
|
|
|
574
|
-
rerender
|
|
575
|
-
|
|
576
|
-
await waitFor(() => {
|
|
577
|
-
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
578
|
-
});
|
|
511
|
+
await flushPromises(rerender, ui);
|
|
512
|
+
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
579
513
|
});
|
|
580
514
|
|
|
581
|
-
|
|
582
|
-
xit('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
515
|
+
it('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
583
516
|
const onDeleteFileSpy = jest.fn();
|
|
584
517
|
const onSendFile = ({ file, onFinish }) => {
|
|
585
518
|
onFinish({ file });
|
|
@@ -599,24 +532,18 @@ describe('File Uploader', () => {
|
|
|
599
532
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
600
533
|
|
|
601
534
|
const dropzone = getByTestId(testId);
|
|
535
|
+
act(() => fireDrop(dropzone, data));
|
|
602
536
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
rerender(ui);
|
|
606
|
-
|
|
607
|
-
await waitFor(() => {
|
|
608
|
-
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
609
|
-
});
|
|
537
|
+
await flushPromises(rerender, ui);
|
|
538
|
+
await act(() => waitFor(() => getByLabelText('Delete file')));
|
|
610
539
|
|
|
540
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
611
541
|
const deleteIcon = getByLabelText('Delete file');
|
|
612
542
|
|
|
613
|
-
|
|
543
|
+
userEvent.click(deleteIcon);
|
|
614
544
|
|
|
615
|
-
rerender
|
|
616
|
-
|
|
617
|
-
await waitFor(() => {
|
|
618
|
-
expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
|
|
619
|
-
});
|
|
545
|
+
await flushPromises(rerender, ui);
|
|
546
|
+
expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
|
|
620
547
|
});
|
|
621
548
|
|
|
622
549
|
it('removes the file when the Remove File icon is clicked', async () => {
|
|
@@ -628,24 +555,16 @@ describe('File Uploader', () => {
|
|
|
628
555
|
const { getByTestId, getByLabelText, queryByText, rerender } = render(ui);
|
|
629
556
|
|
|
630
557
|
const dropzone = getByTestId(testId);
|
|
631
|
-
|
|
632
558
|
fireDrop(dropzone, data);
|
|
633
559
|
|
|
634
|
-
rerender
|
|
635
|
-
|
|
636
|
-
await waitFor(() => {
|
|
637
|
-
expect(queryByText(files[0].name)).toBeInTheDocument();
|
|
638
|
-
});
|
|
639
|
-
|
|
560
|
+
await flushPromises(rerender, ui);
|
|
561
|
+
expect(queryByText(files[0].name)).toBeInTheDocument();
|
|
640
562
|
const removeIcon = getByLabelText('Remove file');
|
|
641
563
|
|
|
642
|
-
|
|
564
|
+
userEvent.click(removeIcon);
|
|
643
565
|
|
|
644
|
-
rerender
|
|
645
|
-
|
|
646
|
-
await waitFor(() => {
|
|
647
|
-
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
648
|
-
});
|
|
566
|
+
await flushPromises(rerender, ui);
|
|
567
|
+
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
649
568
|
});
|
|
650
569
|
|
|
651
570
|
it('calls onRemoveFile when the Remove File icon is clicked', async () => {
|
|
@@ -655,23 +574,18 @@ describe('File Uploader', () => {
|
|
|
655
574
|
|
|
656
575
|
const ui = <Dropzone onRemoveFile={onRemoveFileSpy} testId={testId} />;
|
|
657
576
|
|
|
658
|
-
const { getByTestId,
|
|
577
|
+
const { getByTestId, getByLabelText, rerender } = render(ui);
|
|
659
578
|
|
|
660
579
|
const dropzone = getByTestId(testId);
|
|
661
|
-
|
|
662
580
|
fireDrop(dropzone, data);
|
|
663
581
|
|
|
664
|
-
rerender
|
|
665
|
-
|
|
666
|
-
const removeIcon = await findByLabelText('Remove file');
|
|
667
|
-
|
|
668
|
-
await userEvent.click(removeIcon);
|
|
582
|
+
await flushPromises(rerender, ui);
|
|
583
|
+
const removeIcon = getByLabelText('Remove file');
|
|
669
584
|
|
|
670
|
-
|
|
585
|
+
userEvent.click(removeIcon);
|
|
671
586
|
|
|
672
|
-
await
|
|
673
|
-
|
|
674
|
-
});
|
|
587
|
+
await flushPromises(rerender, ui);
|
|
588
|
+
expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
|
|
675
589
|
});
|
|
676
590
|
|
|
677
591
|
it('dropzoneOptions should be passed to Dropzone', async () => {
|
|
@@ -683,19 +597,20 @@ describe('File Uploader', () => {
|
|
|
683
597
|
const { getByTestId, getAllByText, rerender } = render(ui);
|
|
684
598
|
|
|
685
599
|
const dropzone = getByTestId(testId);
|
|
686
|
-
|
|
687
600
|
fireDrop(dropzone, data);
|
|
688
601
|
|
|
689
|
-
rerender
|
|
602
|
+
await flushPromises(rerender, ui);
|
|
690
603
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
).toBeInTheDocument();
|
|
695
|
-
});
|
|
604
|
+
expect(
|
|
605
|
+
getAllByText(/You must upload a maximum of/i)[0]
|
|
606
|
+
).toBeInTheDocument();
|
|
696
607
|
});
|
|
697
608
|
});
|
|
698
609
|
|
|
610
|
+
async function flushPromises(rerender, ui) {
|
|
611
|
+
await act(() => waitFor(() => rerender(ui)));
|
|
612
|
+
}
|
|
613
|
+
|
|
699
614
|
function createDtWithFiles(files = []) {
|
|
700
615
|
return {
|
|
701
616
|
dataTransfer: {
|
|
@@ -187,14 +187,13 @@ const Wrapper = styled.div<{ isInverse?: boolean }>`
|
|
|
187
187
|
font-weight: 500;
|
|
188
188
|
padding: ${({ theme }) => theme.spaceScale.spacing01};
|
|
189
189
|
`;
|
|
190
|
-
|
|
191
190
|
export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
192
191
|
(props, ref) => {
|
|
193
192
|
const {
|
|
194
193
|
accept,
|
|
195
194
|
containerStyle,
|
|
196
195
|
disabled,
|
|
197
|
-
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
198
197
|
dropzoneOptions = {
|
|
199
198
|
multiple: true,
|
|
200
199
|
},
|
|
@@ -350,7 +349,6 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
350
349
|
) => {
|
|
351
350
|
if (code === null) return null;
|
|
352
351
|
const error = i18n.dropzone.errors[code];
|
|
353
|
-
|
|
354
352
|
switch (code) {
|
|
355
353
|
case 'too-many-files':
|
|
356
354
|
return `${error.message} ${constraints.maxFiles} ${i18n.dropzone.files}.`;
|
|
@@ -397,7 +395,6 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
397
395
|
onFinish: setFinished,
|
|
398
396
|
onProgress: setProgress,
|
|
399
397
|
});
|
|
400
|
-
|
|
401
398
|
return file;
|
|
402
399
|
});
|
|
403
400
|
});
|