@react-magma/dropzone 13.0.1-rc.0 → 13.0.1
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 +1 -1
- package/dist/fileuploader.js.map +1 -1
- package/dist/fileuploader.modern.js +83 -0
- package/dist/fileuploader.modern.js.map +1 -0
- package/dist/fileuploader.modern.module.js +1 -1
- package/dist/fileuploader.modern.module.js.map +1 -1
- package/dist/fileuploader.umd.js +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 +22 -20
- package/src/components/dropzone/Dropzone.stories.tsx +0 -4
- package/src/components/dropzone/Dropzone.test.js +123 -193
- package/src/components/dropzone/Dropzone.tsx +175 -81
- package/src/components/dropzone/Preview.tsx +150 -152
- package/src/components/dropzone/utils.ts +0 -1
- package/dist/fileuploader.modern.mjs +0 -80
- 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 () => {
|
|
@@ -388,17 +349,16 @@ describe('File Uploader', () => {
|
|
|
388
349
|
|
|
389
350
|
const ui = <Dropzone maxFiles={1} testId={testId} />;
|
|
390
351
|
|
|
391
|
-
const { getByTestId,
|
|
352
|
+
const { getByTestId, getAllByText, 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
359
|
await waitFor(() => {
|
|
400
360
|
expect(
|
|
401
|
-
|
|
361
|
+
getAllByText('You must upload a maximum of 1 files.')[0]
|
|
402
362
|
).toBeInTheDocument();
|
|
403
363
|
});
|
|
404
364
|
});
|
|
@@ -409,16 +369,16 @@ describe('File Uploader', () => {
|
|
|
409
369
|
|
|
410
370
|
const ui = <Dropzone minFiles={6} testId={testId} />;
|
|
411
371
|
|
|
412
|
-
const { getByTestId,
|
|
372
|
+
const { getByTestId, getAllByText, rerender } = render(ui);
|
|
413
373
|
|
|
414
374
|
const dropzone = getByTestId(testId);
|
|
415
375
|
fireDrop(dropzone, data);
|
|
416
376
|
|
|
417
|
-
rerender
|
|
377
|
+
await flushPromises(rerender, ui);
|
|
418
378
|
|
|
419
379
|
await waitFor(() => {
|
|
420
380
|
expect(
|
|
421
|
-
|
|
381
|
+
getAllByText('You must upload a minimum of 6 files.')[0]
|
|
422
382
|
).toBeInTheDocument();
|
|
423
383
|
});
|
|
424
384
|
});
|
|
@@ -432,16 +392,13 @@ describe('File Uploader', () => {
|
|
|
432
392
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
433
393
|
|
|
434
394
|
const dropzone = getByTestId(testId);
|
|
435
|
-
|
|
436
395
|
fireDrop(dropzone, data);
|
|
437
396
|
|
|
438
|
-
rerender
|
|
397
|
+
await flushPromises(rerender, ui);
|
|
439
398
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
).toBeInTheDocument();
|
|
444
|
-
});
|
|
399
|
+
expect(
|
|
400
|
+
getByText('Upload only files with a maximum size of 1 Bytes.')
|
|
401
|
+
).toBeInTheDocument();
|
|
445
402
|
});
|
|
446
403
|
|
|
447
404
|
it('shows errors on too small of a file in the file list', async () => {
|
|
@@ -453,16 +410,13 @@ describe('File Uploader', () => {
|
|
|
453
410
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
454
411
|
|
|
455
412
|
const dropzone = getByTestId(testId);
|
|
456
|
-
|
|
457
413
|
fireDrop(dropzone, data);
|
|
458
414
|
|
|
459
|
-
rerender
|
|
415
|
+
await flushPromises(rerender, ui);
|
|
460
416
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
).toBeInTheDocument();
|
|
465
|
-
});
|
|
417
|
+
expect(
|
|
418
|
+
getByText('Upload only files with a minimum size of 9.77 KB.')
|
|
419
|
+
).toBeInTheDocument();
|
|
466
420
|
});
|
|
467
421
|
|
|
468
422
|
it('adds a Spinner to files in progress', async () => {
|
|
@@ -477,16 +431,13 @@ describe('File Uploader', () => {
|
|
|
477
431
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
478
432
|
|
|
479
433
|
const dropzone = getByTestId(testId);
|
|
480
|
-
|
|
481
434
|
fireDrop(dropzone, data);
|
|
482
435
|
|
|
483
|
-
rerender
|
|
436
|
+
await flushPromises(rerender, ui);
|
|
484
437
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
expect(getByLabelText('Loading')).toBeInTheDocument();
|
|
489
|
-
});
|
|
438
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
439
|
+
expect(getByText('25%')).toBeInTheDocument();
|
|
440
|
+
expect(getByLabelText('Loading')).toBeInTheDocument();
|
|
490
441
|
});
|
|
491
442
|
|
|
492
443
|
it('shows an error in the file list on error', async () => {
|
|
@@ -510,18 +461,14 @@ describe('File Uploader', () => {
|
|
|
510
461
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
511
462
|
|
|
512
463
|
const dropzone = getByTestId(testId);
|
|
513
|
-
|
|
514
464
|
fireDrop(dropzone, data);
|
|
515
465
|
|
|
516
|
-
rerender
|
|
466
|
+
await flushPromises(rerender, ui);
|
|
517
467
|
|
|
518
|
-
|
|
519
|
-
expect(getByText('error from the processor')).toBeInTheDocument();
|
|
520
|
-
});
|
|
468
|
+
expect(getByText('error from the processor')).toBeInTheDocument();
|
|
521
469
|
});
|
|
522
470
|
|
|
523
|
-
|
|
524
|
-
xit('changes to delete file on finish', async () => {
|
|
471
|
+
it('changes to delete file on finish', async () => {
|
|
525
472
|
const onSendFile = ({ file, onFinish }) => {
|
|
526
473
|
onFinish({ file });
|
|
527
474
|
};
|
|
@@ -533,23 +480,21 @@ describe('File Uploader', () => {
|
|
|
533
480
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
534
481
|
|
|
535
482
|
const dropzone = getByTestId(testId);
|
|
483
|
+
act(() => fireDrop(dropzone, data));
|
|
536
484
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
485
|
+
await flushPromises(rerender, ui);
|
|
486
|
+
await act(() =>
|
|
487
|
+
waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
|
|
488
|
+
);
|
|
540
489
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
expect(getByLabelText('Delete file')).toBeInTheDocument();
|
|
544
|
-
});
|
|
490
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
491
|
+
expect(getByLabelText(`Delete file ${files[0].name}`)).toBeInTheDocument();
|
|
545
492
|
});
|
|
546
493
|
|
|
547
|
-
|
|
548
|
-
xit('deletes the file when the Delete File icon is clicked', async () => {
|
|
494
|
+
it('deletes the file when the Delete File icon is clicked', async () => {
|
|
549
495
|
const onSendFile = ({ file, onFinish }) => {
|
|
550
496
|
onFinish({ file });
|
|
551
497
|
};
|
|
552
|
-
|
|
553
498
|
const data = createDtWithFiles(files);
|
|
554
499
|
const testId = 'testId';
|
|
555
500
|
|
|
@@ -559,27 +504,23 @@ describe('File Uploader', () => {
|
|
|
559
504
|
render(ui);
|
|
560
505
|
|
|
561
506
|
const dropzone = getByTestId(testId);
|
|
562
|
-
fireDrop(dropzone, data);
|
|
563
|
-
|
|
564
|
-
rerender(ui);
|
|
507
|
+
act(() => fireDrop(dropzone, data));
|
|
565
508
|
|
|
566
|
-
await
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const deleteIcon = getByLabelText('Delete file');
|
|
509
|
+
await flushPromises(rerender, ui);
|
|
510
|
+
await act(() =>
|
|
511
|
+
waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
|
|
512
|
+
);
|
|
571
513
|
|
|
572
|
-
|
|
514
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
515
|
+
const deleteIcon = getByLabelText(`Delete file ${files[0].name}`);
|
|
573
516
|
|
|
574
|
-
|
|
517
|
+
userEvent.click(deleteIcon);
|
|
575
518
|
|
|
576
|
-
await
|
|
577
|
-
|
|
578
|
-
});
|
|
519
|
+
await flushPromises(rerender, ui);
|
|
520
|
+
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
579
521
|
});
|
|
580
522
|
|
|
581
|
-
|
|
582
|
-
xit('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
523
|
+
it('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
583
524
|
const onDeleteFileSpy = jest.fn();
|
|
584
525
|
const onSendFile = ({ file, onFinish }) => {
|
|
585
526
|
onFinish({ file });
|
|
@@ -599,24 +540,20 @@ describe('File Uploader', () => {
|
|
|
599
540
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
600
541
|
|
|
601
542
|
const dropzone = getByTestId(testId);
|
|
543
|
+
act(() => fireDrop(dropzone, data));
|
|
602
544
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
await waitFor(() => {
|
|
608
|
-
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
609
|
-
});
|
|
545
|
+
await flushPromises(rerender, ui);
|
|
546
|
+
await act(() =>
|
|
547
|
+
waitFor(() => getByLabelText(`Delete file ${files[0].name}`))
|
|
548
|
+
);
|
|
610
549
|
|
|
611
|
-
|
|
550
|
+
expect(getByText(files[0].name)).toBeInTheDocument();
|
|
551
|
+
const deleteIcon = getByLabelText(`Delete file ${files[0].name}`);
|
|
612
552
|
|
|
613
|
-
|
|
553
|
+
userEvent.click(deleteIcon);
|
|
614
554
|
|
|
615
|
-
rerender
|
|
616
|
-
|
|
617
|
-
await waitFor(() => {
|
|
618
|
-
expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
|
|
619
|
-
});
|
|
555
|
+
await flushPromises(rerender, ui);
|
|
556
|
+
expect(onDeleteFileSpy).toHaveBeenCalledTimes(1);
|
|
620
557
|
});
|
|
621
558
|
|
|
622
559
|
it('removes the file when the Remove File icon is clicked', async () => {
|
|
@@ -628,7 +565,6 @@ describe('File Uploader', () => {
|
|
|
628
565
|
const { getByTestId, getByLabelText, queryByText, rerender } = render(ui);
|
|
629
566
|
|
|
630
567
|
const dropzone = getByTestId(testId);
|
|
631
|
-
|
|
632
568
|
fireDrop(dropzone, data);
|
|
633
569
|
|
|
634
570
|
rerender(ui);
|
|
@@ -637,15 +573,12 @@ describe('File Uploader', () => {
|
|
|
637
573
|
expect(queryByText(files[0].name)).toBeInTheDocument();
|
|
638
574
|
});
|
|
639
575
|
|
|
640
|
-
const removeIcon = getByLabelText(
|
|
576
|
+
const removeIcon = getByLabelText(`Remove file ${files[0].name}`);
|
|
641
577
|
|
|
642
|
-
|
|
578
|
+
userEvent.click(removeIcon);
|
|
643
579
|
|
|
644
|
-
rerender
|
|
645
|
-
|
|
646
|
-
await waitFor(() => {
|
|
647
|
-
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
648
|
-
});
|
|
580
|
+
await flushPromises(rerender, ui);
|
|
581
|
+
expect(queryByText(files[0].name)).not.toBeInTheDocument();
|
|
649
582
|
});
|
|
650
583
|
|
|
651
584
|
it('calls onRemoveFile when the Remove File icon is clicked', async () => {
|
|
@@ -658,20 +591,16 @@ describe('File Uploader', () => {
|
|
|
658
591
|
const { getByTestId, findByLabelText, rerender } = render(ui);
|
|
659
592
|
|
|
660
593
|
const dropzone = getByTestId(testId);
|
|
661
|
-
|
|
662
594
|
fireDrop(dropzone, data);
|
|
663
595
|
|
|
664
596
|
rerender(ui);
|
|
665
597
|
|
|
666
|
-
const removeIcon = await findByLabelText(
|
|
598
|
+
const removeIcon = await findByLabelText(`Remove file ${files[0].name}`);
|
|
667
599
|
|
|
668
|
-
|
|
600
|
+
userEvent.click(removeIcon);
|
|
669
601
|
|
|
670
|
-
rerender
|
|
671
|
-
|
|
672
|
-
await waitFor(() => {
|
|
673
|
-
expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
|
|
674
|
-
});
|
|
602
|
+
await flushPromises(rerender, ui);
|
|
603
|
+
expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
|
|
675
604
|
});
|
|
676
605
|
|
|
677
606
|
it('dropzoneOptions should be passed to Dropzone', async () => {
|
|
@@ -683,19 +612,20 @@ describe('File Uploader', () => {
|
|
|
683
612
|
const { getByTestId, getAllByText, rerender } = render(ui);
|
|
684
613
|
|
|
685
614
|
const dropzone = getByTestId(testId);
|
|
686
|
-
|
|
687
615
|
fireDrop(dropzone, data);
|
|
688
616
|
|
|
689
|
-
rerender
|
|
617
|
+
await flushPromises(rerender, ui);
|
|
690
618
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
).toBeInTheDocument();
|
|
695
|
-
});
|
|
619
|
+
expect(
|
|
620
|
+
getAllByText(/You must upload a maximum of/i)[0]
|
|
621
|
+
).toBeInTheDocument();
|
|
696
622
|
});
|
|
697
623
|
});
|
|
698
624
|
|
|
625
|
+
async function flushPromises(rerender, ui) {
|
|
626
|
+
await act(() => waitFor(() => rerender(ui)));
|
|
627
|
+
}
|
|
628
|
+
|
|
699
629
|
function createDtWithFiles(files = []) {
|
|
700
630
|
return {
|
|
701
631
|
dataTransfer: {
|