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