Skip to content

Commit f0ee297

Browse files
committed
Fix testing
1 parent fa380bd commit f0ee297

File tree

4 files changed

+73
-29
lines changed

4 files changed

+73
-29
lines changed

test/CSVReader.spec.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
15
import React from 'react';
2-
import expect from 'expect';
6+
// import expect from 'expect';
37
import CustomReader from './CustomReader';
48
import renderer from 'react-test-renderer';
59

610
// eslint-disable-next-line no-undef
711
describe('CSVReader', () => {
812
// eslint-disable-next-line no-undef
9-
it('should match snapshot', function () {
10-
const handleFileUploaded = jest.fn().mockImplementation();
13+
it('should match snapshot', async function () {
14+
const handleUploadAccepted = jest.fn().mockImplementation();
1115
const tree = renderer
1216
.create(
1317
<CustomReader
14-
onFileLoaded={handleFileUploaded}
18+
onUploadAccepted={handleUploadAccepted}
1519
label="Chargez votre offre"
1620
/>
1721
)

test/CustomReader.tsx

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
import React from 'react';
2-
import { CSVReader } from '../src/react-papaparse';
2+
import { useCSVReader } from '../src/react-papaparse';
33

44
interface CustomReaderProps {
5-
onFileLoaded?: ((data: any, file?: any) => void) | undefined;
5+
onUploadAccepted?: ((data: any, file?: any) => void) | undefined;
66
label: string;
77
}
88

99
const CustomReader: React.FC<CustomReaderProps> = (
1010
props: CustomReaderProps
1111
) => {
12-
const { onFileLoaded, label } = props;
12+
const { CSVReader } = useCSVReader();
13+
const { onUploadAccepted, label } = props;
1314

1415
return (
15-
<CSVReader onFileLoad={onFileLoaded}>
16-
<span>{label}</span>
16+
<CSVReader
17+
onUploadAccepted={onUploadAccepted}
18+
>
19+
{({
20+
getRootProps,
21+
acceptedFile,
22+
ProgressBar,
23+
getRemoveFileProps,
24+
}: any) => (
25+
<>
26+
<div>
27+
<button type='button' {...getRootProps()}>
28+
{label}
29+
</button>
30+
<div>
31+
{acceptedFile && acceptedFile.name}
32+
</div>
33+
<button {...getRemoveFileProps()}>
34+
Remove
35+
</button>
36+
</div>
37+
<ProgressBar />
38+
</>
39+
)}
1740
</CSVReader>
1841
);
1942
};

test/__snapshots__/CSVReader.spec.tsx.snap

+35-18
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,52 @@ exports[`CSVReader should match snapshot 1`] = `
44
Array [
55
<input
66
accept="text/csv, .csv, application/vnd.ms-excel"
7+
autoComplete="off"
8+
multiple={false}
79
onChange={[Function]}
10+
onClick={[Function]}
811
style={
912
Object {
1013
"display": "none",
1114
}
1215
}
16+
tabIndex={-1}
1317
type="file"
1418
/>,
15-
<div
16-
onClick={[Function]}
19+
<div>
20+
<button
21+
onBlur={[Function]}
22+
onClick={[Function]}
23+
onDragEnter={[Function]}
24+
onDragLeave={[Function]}
25+
onDragOver={[Function]}
26+
onDrop={[Function]}
27+
onFocus={[Function]}
28+
onKeyDown={[Function]}
29+
type="button"
30+
>
31+
Chargez votre offre
32+
</button>
33+
<div />
34+
<button
35+
onClick={[Function]}
36+
>
37+
Remove
38+
</button>
39+
</div>,
40+
<span
1741
style={
1842
Object {
19-
"alignItems": "center",
20-
"borderColor": "#CCC",
21-
"borderRadius": 20,
22-
"borderStyle": "dashed",
23-
"borderWidth": 2,
24-
"cursor": "pointer",
25-
"display": "flex",
26-
"flexDirection": "column",
27-
"height": "100%",
28-
"justifyContent": "center",
29-
"padding": 20,
43+
"backgroundColor": "#659cef",
44+
"borderRadius": 3,
45+
"bottom": 14,
46+
"boxShadow": "inset 0 1px 3px rgba(0, 0, 0, .2)",
47+
"display": "none",
48+
"height": 10,
49+
"transition": "width 500ms ease-in-out",
50+
"width": "0%",
3051
}
3152
}
32-
>
33-
<span>
34-
Chargez votre offre
35-
</span>
36-
</div>,
53+
/>,
3754
]
3855
`;

test/utils.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import expect from 'expect'
2-
import getSize from '../src/utils'
2+
import { formatFileSize } from '../src/utils'
33

44
// eslint-disable-next-line no-undef
55
describe('util', () => {
66
// eslint-disable-next-line no-undef
77
it('should return 1 KB', function() {
8-
const strSize = getSize(1000)
8+
const strSize = formatFileSize(1000)
99
expect(strSize).toEqual('1 KB')
1010
})
1111
})

0 commit comments

Comments
 (0)