@react-magma/dropzone 0.1.0-next.2 → 0.1.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/{components → src/components}/dropzone/Dropzone.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/Dropzone.stories.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/Dropzone.test.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/FileIcon.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/FilePreview.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/Preview.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/index.d.ts +0 -0
- package/dist/{components → src/components}/dropzone/utils.d.ts +0 -0
- package/dist/{index.d.ts → src/index.d.ts} +0 -0
- package/package.json +3 -3
- package/src/components/dropzone/Dropzone.test.js +69 -80
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/dropzone",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@emotion/styled": "^10.0.27",
|
|
31
31
|
"react": "^15.0.0 || ^16.0.0 || ^17.0.0",
|
|
32
32
|
"react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0",
|
|
33
|
-
"react-magma-dom": "^2.5.
|
|
33
|
+
"react-magma-dom": "^2.5.8-next.0",
|
|
34
34
|
"react-magma-icons": "^2.3.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@emotion/styled": "^10.0.27",
|
|
42
42
|
"react": "^16.10.0",
|
|
43
43
|
"react-dom": "^16.10.0",
|
|
44
|
-
"react-magma-dom": "^2.5.
|
|
44
|
+
"react-magma-dom": "^2.5.8",
|
|
45
45
|
"react-magma-icons": "^2.3.1"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { axe } from '
|
|
2
|
+
import { axe } from '../../../axe-helper.js';
|
|
3
3
|
import { Dropzone } from '.';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cleanup,
|
|
6
|
+
render,
|
|
7
|
+
act,
|
|
8
|
+
fireEvent,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from '@testing-library/react';
|
|
5
11
|
import { I18nContext, defaultI18n } from 'react-magma-dom';
|
|
6
12
|
import userEvent from '@testing-library/user-event';
|
|
7
13
|
|
|
@@ -20,7 +26,7 @@ describe('File Uploader', () => {
|
|
|
20
26
|
createFile('cats.png', 1234, 'image/png'),
|
|
21
27
|
createFile('dogs.png', 2345, 'image/png'),
|
|
22
28
|
];
|
|
23
|
-
})
|
|
29
|
+
});
|
|
24
30
|
|
|
25
31
|
afterEach(() => {
|
|
26
32
|
jest.useRealTimers();
|
|
@@ -29,13 +35,9 @@ describe('File Uploader', () => {
|
|
|
29
35
|
});
|
|
30
36
|
|
|
31
37
|
it('should render the file uploader component', () => {
|
|
32
|
-
const { container, getByText } = render(
|
|
33
|
-
<Dropzone/>
|
|
34
|
-
);
|
|
38
|
+
const { container, getByText } = render(<Dropzone />);
|
|
35
39
|
|
|
36
|
-
expect(
|
|
37
|
-
getByText('Browse Files')
|
|
38
|
-
).toBeInTheDocument();
|
|
40
|
+
expect(getByText('Browse Files')).toBeInTheDocument();
|
|
39
41
|
|
|
40
42
|
expect(
|
|
41
43
|
getByText('Drag and drop or browse files to upload.')
|
|
@@ -43,9 +45,7 @@ describe('File Uploader', () => {
|
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
it('should render the file uploader component without drag', () => {
|
|
46
|
-
const { container, queryByText } = render(
|
|
47
|
-
<Dropzone noDrag/>
|
|
48
|
-
);
|
|
48
|
+
const { container, queryByText } = render(<Dropzone noDrag />);
|
|
49
49
|
|
|
50
50
|
expect(queryByText('Browse Files')).toBeInTheDocument();
|
|
51
51
|
expect(
|
|
@@ -55,9 +55,7 @@ describe('File Uploader', () => {
|
|
|
55
55
|
|
|
56
56
|
it('should find element by testId', () => {
|
|
57
57
|
const testId = 'test-id';
|
|
58
|
-
const { getByTestId } = render(
|
|
59
|
-
<Dropzone testId={testId}/>
|
|
60
|
-
);
|
|
58
|
+
const { getByTestId } = render(<Dropzone testId={testId} />);
|
|
61
59
|
|
|
62
60
|
expect(getByTestId(testId)).toBeInTheDocument();
|
|
63
61
|
});
|
|
@@ -65,9 +63,7 @@ describe('File Uploader', () => {
|
|
|
65
63
|
it('Does not violate accessibility standards', () => {
|
|
66
64
|
jest.useRealTimers();
|
|
67
65
|
|
|
68
|
-
const { container } = render(
|
|
69
|
-
<Dropzone/>
|
|
70
|
-
);
|
|
66
|
+
const { container } = render(<Dropzone />);
|
|
71
67
|
|
|
72
68
|
return axe(container.innerHTML).then(result => {
|
|
73
69
|
return expect(result).toHaveNoViolations();
|
|
@@ -77,15 +73,16 @@ describe('File Uploader', () => {
|
|
|
77
73
|
it('Supports i18n', () => {
|
|
78
74
|
const browseFiles = 'find those files';
|
|
79
75
|
const { getByText } = render(
|
|
80
|
-
<I18nContext.Provider
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
76
|
+
<I18nContext.Provider
|
|
77
|
+
value={{
|
|
78
|
+
...defaultI18n,
|
|
79
|
+
dropzone: {
|
|
80
|
+
...defaultI18n.dropzone,
|
|
81
|
+
browseFiles,
|
|
82
|
+
},
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<Dropzone />
|
|
89
86
|
</I18nContext.Provider>
|
|
90
87
|
);
|
|
91
88
|
|
|
@@ -94,9 +91,7 @@ describe('File Uploader', () => {
|
|
|
94
91
|
|
|
95
92
|
it('sets {accept} prop on the <input>', () => {
|
|
96
93
|
const accept = 'image/jpeg';
|
|
97
|
-
const { container } = render(
|
|
98
|
-
<Dropzone accept={accept}/>
|
|
99
|
-
);
|
|
94
|
+
const { container } = render(<Dropzone accept={accept} />);
|
|
100
95
|
|
|
101
96
|
const input = container.querySelector('input');
|
|
102
97
|
expect(input).toHaveAttribute('accept', accept);
|
|
@@ -110,9 +105,7 @@ describe('File Uploader', () => {
|
|
|
110
105
|
});
|
|
111
106
|
|
|
112
107
|
it('allows adding files via drop', () => {
|
|
113
|
-
const { container } = render(
|
|
114
|
-
<Dropzone />
|
|
115
|
-
);
|
|
108
|
+
const { container } = render(<Dropzone />);
|
|
116
109
|
|
|
117
110
|
const dropzone = container.querySelector('div');
|
|
118
111
|
|
|
@@ -124,9 +117,7 @@ describe('File Uploader', () => {
|
|
|
124
117
|
});
|
|
125
118
|
|
|
126
119
|
it('allows adding files via drop', () => {
|
|
127
|
-
const { container } = render(
|
|
128
|
-
<Dropzone />
|
|
129
|
-
);
|
|
120
|
+
const { container } = render(<Dropzone />);
|
|
130
121
|
|
|
131
122
|
const dropzone = container.querySelector('div');
|
|
132
123
|
|
|
@@ -140,7 +131,7 @@ describe('File Uploader', () => {
|
|
|
140
131
|
it('border color changes for success', async () => {
|
|
141
132
|
const data = createDtWithFiles(files);
|
|
142
133
|
const testId = 'testId';
|
|
143
|
-
const ui = <Dropzone testId={testId}/>;
|
|
134
|
+
const ui = <Dropzone testId={testId} />;
|
|
144
135
|
const { getByTestId, rerender } = render(ui);
|
|
145
136
|
|
|
146
137
|
const dropzone = getByTestId(testId);
|
|
@@ -179,7 +170,9 @@ describe('File Uploader', () => {
|
|
|
179
170
|
dispatchEvt(input, 'change');
|
|
180
171
|
await flushPromises(rerender, ui);
|
|
181
172
|
|
|
182
|
-
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
173
|
+
expect(onSendFileSpy).toHaveBeenCalledWith(
|
|
174
|
+
expect.objectContaining({ file: files[0] })
|
|
175
|
+
);
|
|
183
176
|
});
|
|
184
177
|
|
|
185
178
|
it('calls onSendFiles for multiple files added via the input', async () => {
|
|
@@ -277,10 +270,7 @@ describe('File Uploader', () => {
|
|
|
277
270
|
const data = createDtWithFiles(files);
|
|
278
271
|
const testId = 'testId';
|
|
279
272
|
|
|
280
|
-
const ui = <Dropzone
|
|
281
|
-
sendFiles
|
|
282
|
-
testId={testId}
|
|
283
|
-
/>;
|
|
273
|
+
const ui = <Dropzone sendFiles testId={testId} />;
|
|
284
274
|
|
|
285
275
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
286
276
|
|
|
@@ -332,9 +322,7 @@ describe('File Uploader', () => {
|
|
|
332
322
|
const data = createDtWithFiles(files);
|
|
333
323
|
const testId = 'testId';
|
|
334
324
|
|
|
335
|
-
const ui =
|
|
336
|
-
<Dropzone accept={['.png']} testId={testId} />
|
|
337
|
-
);
|
|
325
|
+
const ui = <Dropzone accept={['.png']} testId={testId} />;
|
|
338
326
|
|
|
339
327
|
const { getByTestId, getByText, rerender } = render(ui);
|
|
340
328
|
|
|
@@ -364,23 +352,23 @@ describe('File Uploader', () => {
|
|
|
364
352
|
).toBeInTheDocument();
|
|
365
353
|
});
|
|
366
354
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
355
|
+
it('shows errors on too few files in the file list', async () => {
|
|
356
|
+
const data = createDtWithFiles(images);
|
|
357
|
+
const testId = 'testId';
|
|
370
358
|
|
|
371
|
-
|
|
359
|
+
const ui = <Dropzone minFiles={6} testId={testId} />;
|
|
372
360
|
|
|
373
|
-
|
|
361
|
+
const { getByTestId, getByText, rerender } = render(ui);
|
|
374
362
|
|
|
375
|
-
|
|
376
|
-
|
|
363
|
+
const dropzone = getByTestId(testId);
|
|
364
|
+
fireDrop(dropzone, data);
|
|
377
365
|
|
|
378
|
-
|
|
366
|
+
await flushPromises(rerender, ui);
|
|
379
367
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
368
|
+
expect(
|
|
369
|
+
getByText('You must upload a minimum of 6 files.')
|
|
370
|
+
).toBeInTheDocument();
|
|
371
|
+
});
|
|
384
372
|
|
|
385
373
|
it('shows errors on too large of a file in the file list', async () => {
|
|
386
374
|
const data = createDtWithFiles(files);
|
|
@@ -419,15 +407,13 @@ describe('File Uploader', () => {
|
|
|
419
407
|
});
|
|
420
408
|
|
|
421
409
|
it('adds a Spinner to files in progress', async () => {
|
|
422
|
-
const onSendFile = ({file, onProgress}) => {
|
|
423
|
-
onProgress({file, percent: 25})
|
|
424
|
-
}
|
|
410
|
+
const onSendFile = ({ file, onProgress }) => {
|
|
411
|
+
onProgress({ file, percent: 25 });
|
|
412
|
+
};
|
|
425
413
|
const data = createDtWithFiles(files);
|
|
426
414
|
const testId = 'testId';
|
|
427
415
|
|
|
428
|
-
const ui =
|
|
429
|
-
<Dropzone sendFiles onSendFile={onSendFile} testId={testId} />
|
|
430
|
-
);
|
|
416
|
+
const ui = <Dropzone sendFiles onSendFile={onSendFile} testId={testId} />;
|
|
431
417
|
|
|
432
418
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
433
419
|
|
|
@@ -443,7 +429,16 @@ describe('File Uploader', () => {
|
|
|
443
429
|
|
|
444
430
|
it('shows an error in the file list on error', async () => {
|
|
445
431
|
const onSendFile = ({ file, onError }) => {
|
|
446
|
-
onError({
|
|
432
|
+
onError({
|
|
433
|
+
file,
|
|
434
|
+
errors: [
|
|
435
|
+
{
|
|
436
|
+
message: 'error from the processor',
|
|
437
|
+
header: 'test-error',
|
|
438
|
+
code: 'error',
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
});
|
|
447
442
|
};
|
|
448
443
|
const data = createDtWithFiles(files);
|
|
449
444
|
const testId = 'testId';
|
|
@@ -467,9 +462,7 @@ describe('File Uploader', () => {
|
|
|
467
462
|
const data = createDtWithFiles(files);
|
|
468
463
|
const testId = 'testId';
|
|
469
464
|
|
|
470
|
-
const ui =
|
|
471
|
-
<Dropzone sendFiles onSendFile={onSendFile} testId={testId} />
|
|
472
|
-
);
|
|
465
|
+
const ui = <Dropzone sendFiles onSendFile={onSendFile} testId={testId} />;
|
|
473
466
|
|
|
474
467
|
const { getByTestId, getByLabelText, getByText, rerender } = render(ui);
|
|
475
468
|
|
|
@@ -490,9 +483,7 @@ describe('File Uploader', () => {
|
|
|
490
483
|
const data = createDtWithFiles(files);
|
|
491
484
|
const testId = 'testId';
|
|
492
485
|
|
|
493
|
-
const ui =
|
|
494
|
-
<Dropzone sendFiles onSendFile={onSendFile} testId={testId} />
|
|
495
|
-
);
|
|
486
|
+
const ui = <Dropzone sendFiles onSendFile={onSendFile} testId={testId} />;
|
|
496
487
|
|
|
497
488
|
const { getByTestId, getByLabelText, getByText, queryByText, rerender } =
|
|
498
489
|
render(ui);
|
|
@@ -521,7 +512,12 @@ describe('File Uploader', () => {
|
|
|
521
512
|
const testId = 'testId';
|
|
522
513
|
|
|
523
514
|
const ui = (
|
|
524
|
-
<Dropzone
|
|
515
|
+
<Dropzone
|
|
516
|
+
sendFiles
|
|
517
|
+
onDeleteFile={onDeleteFileSpy}
|
|
518
|
+
onSendFile={onSendFile}
|
|
519
|
+
testId={testId}
|
|
520
|
+
/>
|
|
525
521
|
);
|
|
526
522
|
|
|
527
523
|
const { getByTestId, getByLabelText, getByText, queryByText, rerender } =
|
|
@@ -568,9 +564,7 @@ describe('File Uploader', () => {
|
|
|
568
564
|
const data = createDtWithFiles(files);
|
|
569
565
|
const testId = 'testId';
|
|
570
566
|
|
|
571
|
-
const ui =
|
|
572
|
-
<Dropzone onRemoveFile={onRemoveFileSpy} testId={testId} />
|
|
573
|
-
);
|
|
567
|
+
const ui = <Dropzone onRemoveFile={onRemoveFileSpy} testId={testId} />;
|
|
574
568
|
|
|
575
569
|
const { getByTestId, getByLabelText, queryByText, rerender } = render(ui);
|
|
576
570
|
|
|
@@ -584,12 +578,7 @@ describe('File Uploader', () => {
|
|
|
584
578
|
|
|
585
579
|
await flushPromises(rerender, ui);
|
|
586
580
|
expect(onRemoveFileSpy).toHaveBeenCalledTimes(1);
|
|
587
|
-
|
|
588
581
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
582
|
});
|
|
594
583
|
|
|
595
584
|
async function flushPromises(rerender, ui) {
|
|
@@ -643,4 +632,4 @@ function createFile(name, size, type) {
|
|
|
643
632
|
},
|
|
644
633
|
});
|
|
645
634
|
return file;
|
|
646
|
-
}
|
|
635
|
+
}
|