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 pathcustomConfig.test.ts
162 lines (138 loc) · 4.94 KB
/
customConfig.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { By, until } from 'selenium-webdriver';
import { expect } from 'chai';
import path from 'path';
import { runTestServer } from './testServer';
import { runDriver } from './webdriver';
import { runUI } from './uiSetup';
// extra timeout allowance on CI
const testTimeoutMs = process.env.CI ? 20000 : 10000;
describe('importer with custom Papa Parse config', () => {
const appUrl = runTestServer();
const getDriver = runDriver();
const initUI = runUI(getDriver);
beforeEach(async () => {
await getDriver().get(appUrl);
await initUI((React, ReactDOM, ReactCSVImporter, ReactCSVImporterField) => {
ReactDOM.render(
React.createElement(
ReactCSVImporter,
{
delimiter: '!', // not a normal guessable delimiter for Papa Parse
dataHandler: (rows, info) => {
((window as unknown) as Record<
string,
unknown
>).TEST_DATA_HANDLER_ROWS = rows;
((window as unknown) as Record<
string,
unknown
>).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 () => {
const filePath = path.resolve(
__dirname,
'./fixtures/customDelimited.txt'
);
const fileInput = await getDriver().findElement(By.xpath('//input'));
await fileInput.sendKeys(filePath);
await getDriver().wait(
until.elementLocated(By.xpath('//*[contains(., "Raw File Contents")]')),
300 // extra time
);
});
it('shows correctly parsed preview table', async () => {
const tablePreview = await getDriver().findElement(By.xpath('//table'));
// header row
const tableCols = await tablePreview.findElements(
By.xpath('thead/tr/th')
);
const tableColStrings = await tableCols.reduce(
async (acc, col) => [...(await acc), await col.getText()],
Promise.resolve([] as string[])
);
expect(tableColStrings).to.deep.equal(['val1', 'val2']);
// first data row
const firstDataCells = await tablePreview.findElements(
By.xpath('tbody/tr[1]/td')
);
const firstDataCellStrings = await firstDataCells.reduce(
async (acc, col) => [...(await acc), await col.getText()],
Promise.resolve([] as string[])
);
expect(firstDataCellStrings).to.deep.equal(['val3', 'val4']);
});
describe('after accepting and assigning fields', () => {
beforeEach(async () => {
const previewNextButton = await getDriver().findElement(
By.xpath('//button[text() = "Choose columns"]')
);
await previewNextButton.click();
await getDriver().wait(
until.elementLocated(By.xpath('//*[contains(., "Select Columns")]')),
300 // extra time
);
// start the keyboard-based selection mode
const focusedHeading = await getDriver().switchTo().activeElement();
await focusedHeading.sendKeys('\t'); // tab to next element
const selectButton = await getDriver().findElement(
By.xpath('//button[@aria-label = "Select column for assignment"][1]')
);
await selectButton.sendKeys('\n'); // cannot use click
await getDriver().wait(
until.elementLocated(
By.xpath('//*[contains(., "Assigning column A")]')
),
200
);
const assignButton = await getDriver().findElement(
By.xpath('//button[@aria-label = "Assign column A"]')
);
await assignButton.click();
const fieldsNextButton = await getDriver().findElement(
By.xpath('//button[text() = "Import"]')
);
await fieldsNextButton.click();
await getDriver().wait(
until.elementLocated(
By.xpath(
'//button[@aria-label = "Go to previous step"]/../*[contains(., "Import")]'
)
),
200
);
await getDriver().wait(
until.elementLocated(By.xpath('//*[contains(., "Complete")]')),
200
);
});
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: 'val3' }]);
expect(chunkInfo).to.deep.equal({ startIndex: 0 });
});
});
});
}).timeout(testTimeoutMs);