@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.
@@ -1,6 +1,12 @@
1
1
  import React from 'react';
2
2
 
3
- import { cleanup, render, fireEvent, waitFor } from '@testing-library/react';
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
- await userEvent.click(getByRole('button'));
73
+ userEvent.click(getByRole('button'));
66
74
 
67
- expect(fileInputClickFn).toHaveBeenCalled();
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
- rerender(ui);
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
- rerender(ui);
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
- rerender(ui);
188
-
189
- await waitFor(() => {
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
- rerender(ui);
209
-
210
- await waitFor(() => {
211
- expect(onSendFileSpy).toHaveBeenCalledWith(
212
- expect.objectContaining({ file: images[0] })
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(ui);
220
+ await flushPromises(rerender, ui);
236
221
 
237
- await waitFor(() => {
238
- expect(onSendFileSpy).toHaveBeenCalledWith(
239
- expect.objectContaining({ file: files[0] })
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(ui);
240
+ await flushPromises(rerender, ui);
260
241
 
261
- await waitFor(() => {
262
- expect(onSendFileSpy).toHaveBeenCalledWith(
263
- expect.objectContaining({ file: images[0] })
264
- );
265
- expect(onSendFileSpy).toHaveBeenCalledWith(
266
- expect.objectContaining({ file: images[1] })
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(ui(false));
267
+ await flushPromises(rerender, ui(false));
291
268
 
292
- await waitFor(() => {
293
- expect(onSendFileSpy).not.toHaveBeenCalled();
294
- });
269
+ expect(onSendFileSpy).not.toHaveBeenCalled();
295
270
 
296
- rerender(ui(true));
271
+ await flushPromises(rerender, ui(true));
297
272
 
298
- await waitFor(() => {
299
- expect(onSendFileSpy).toHaveBeenCalledWith(
300
- expect.objectContaining({ file: files[0] })
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(ui);
289
+ await flushPromises(rerender, ui);
318
290
 
319
- await waitFor(() => {
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(ui);
306
+ await flushPromises(rerender, ui);
338
307
 
339
- await waitFor(() => {
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(ui);
325
+ await flushPromises(rerender, ui);
360
326
 
361
- await waitFor(() => {
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(ui);
341
+ await flushPromises(rerender, ui);
379
342
 
380
- await waitFor(() => {
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(ui);
357
+ await flushPromises(rerender, ui);
398
358
 
399
- await waitFor(() => {
400
- expect(
401
- getByText('You must upload a maximum of 1 files.')
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(ui);
375
+ await flushPromises(rerender, ui);
418
376
 
419
- await waitFor(() => {
420
- expect(
421
- getByText('You must upload a minimum of 6 files.')
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(ui);
393
+ await flushPromises(rerender, ui);
439
394
 
440
- await waitFor(() => {
441
- expect(
442
- getByText('Upload only files with a maximum size of 1 Bytes.')
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(ui);
411
+ await flushPromises(rerender, ui);
460
412
 
461
- await waitFor(() => {
462
- expect(
463
- getByText('Upload only files with a minimum size of 9.77 KB.')
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(ui);
432
+ await flushPromises(rerender, ui);
484
433
 
485
- await waitFor(() => {
486
- expect(getByText(files[0].name)).toBeInTheDocument();
487
- expect(getByText('25%')).toBeInTheDocument();
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(ui);
462
+ await flushPromises(rerender, ui);
517
463
 
518
- await waitFor(() => {
519
- expect(getByText('error from the processor')).toBeInTheDocument();
520
- });
464
+ expect(getByText('error from the processor')).toBeInTheDocument();
521
465
  });
522
466
 
523
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
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
- fireDrop(dropzone, data);
538
-
539
- rerender(ui);
481
+ await flushPromises(rerender, ui);
482
+ await act(() => waitFor(() => getByLabelText('Delete file')));
540
483
 
541
- await waitFor(() => {
542
- expect(getByText(files[0].name)).toBeInTheDocument();
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
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
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 waitFor(() => {
567
- expect(getByText(files[0].name)).toBeInTheDocument();
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
- await userEvent.click(deleteIcon);
509
+ userEvent.click(deleteIcon);
573
510
 
574
- rerender(ui);
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
- // TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
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
- fireDrop(dropzone, data);
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
- await userEvent.click(deleteIcon);
543
+ userEvent.click(deleteIcon);
614
544
 
615
- rerender(ui);
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(ui);
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
- await userEvent.click(removeIcon);
564
+ userEvent.click(removeIcon);
643
565
 
644
- rerender(ui);
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, findByLabelText, rerender } = render(ui);
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(ui);
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
- rerender(ui);
585
+ userEvent.click(removeIcon);
671
586
 
672
- await waitFor(() => {
673
- expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
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(ui);
602
+ await flushPromises(rerender, ui);
690
603
 
691
- await waitFor(() => {
692
- expect(
693
- getAllByText(/You must upload a maximum of/i)[0]
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
  });