This repository was archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathencoding.test.ts
87 lines (76 loc) · 2.53 KB
/
encoding.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { expect } from 'chai';
import path from 'path';
import { runTestServer } from './testServer';
import { runDriver } from './webdriver';
import { runUI, uiHelperSetup } from './uiSetup';
type RawWindow = Record<string, unknown>;
// extra timeout allowance on CI
const testTimeoutMs = process.env.CI ? 20000 : 10000;
describe('importer with custom encoding setting', () => {
const appUrl = runTestServer();
const getDriver = runDriver();
const initUI = runUI(getDriver);
const {
uploadFile,
getDisplayedPreviewData,
advanceToFieldStepAndFinish
} = uiHelperSetup(getDriver);
beforeEach(async () => {
await getDriver().get(appUrl);
await initUI((React, ReactDOM, ReactCSVImporter, ReactCSVImporterField) => {
ReactDOM.render(
React.createElement(
ReactCSVImporter,
{
encoding: 'windows-1250', // encoding incompatible with UTF-8
delimiter: ',',
dataHandler: (rows, info) => {
((window as unknown) as RawWindow).TEST_DATA_HANDLER_ROWS = rows;
((window as unknown) as RawWindow).TEST_DATA_HANDLER_INFO = info;
}
},
[
React.createElement(ReactCSVImporterField, {
name: 'fieldA',
label: 'Field A'
}),
React.createElement(ReactCSVImporterField, {
name: 'fieldB',
label: 'Field B',
optional: true
})
]
),
document.getElementById('root')
);
});
});
describe('at preview stage', () => {
beforeEach(async () => {
await uploadFile(
path.resolve(__dirname, './fixtures/encodingWindows1250.csv')
);
});
it('shows correctly parsed preview table', async () => {
expect(await getDisplayedPreviewData()).to.deep.equal([
['value1', 'value2'],
['Montréal', 'Köppen']
]);
});
describe('after accepting and assigning fields', () => {
beforeEach(async () => {
await advanceToFieldStepAndFinish();
});
it('produces parsed data with correct fields', async () => {
const parsedData = await getDriver().executeScript(
'return window.TEST_DATA_HANDLER_ROWS'
);
const chunkInfo = await getDriver().executeScript(
'return window.TEST_DATA_HANDLER_INFO'
);
expect(parsedData).to.deep.equal([{ fieldA: 'Montréal' }]);
expect(chunkInfo).to.deep.equal({ startIndex: 0 });
});
});
});
}).timeout(testTimeoutMs);