-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathutilsCsvImport.ts
More file actions
53 lines (45 loc) · 2.11 KB
/
utilsCsvImport.ts
File metadata and controls
53 lines (45 loc) · 2.11 KB
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
import {Page} from 'playwright';
import {expect} from '@playwright/test';
import path from 'node:path';
const fixturesDir = path.resolve(process.cwd(), 'e2e/test-fixtures');
export async function openCsvImportDialog(page: Page) {
await page.locator('#import-data').click();
await page.getByRole('menuitem', {name: 'Import CSV Data'}).click();
await expect(page.getByRole('dialog', {name: 'Import CSV'})).toBeVisible();
}
export async function uploadCsvFile(page: Page, filename: string) {
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByTestId('csv-select-file').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(path.join(fixturesDir, filename));
// wait for the Import button to appear, confirming the CSV was parsed
await expect(page.getByTestId('csv-submit-import')).toBeVisible();
}
export async function uploadCsvFileAndCheckProgress(page: Page, filename: string, timeoutMs: number = 5000) {
const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser', {timeout: timeoutMs}),
page.getByTestId('csv-select-file').click({timeout: timeoutMs}),
]);
await fileChooser.setFiles(path.join(fixturesDir, filename));
await expect(
page.getByTestId('csv-submit-import'),
'CSV import dialog did not progress past file selection'
).toBeVisible({timeout: timeoutMs});
}
export async function expandImportOptions(page: Page) {
await page.getByTestId('csv-import-options-toggle').click();
}
export async function setCsvTablePath(page: Page, tablePath: string) {
const input = page.getByTestId('csv-table-path-input');
await input.clear();
await input.fill(tablePath);
}
export async function setColumnPath(page: Page, columnName: string, newPath: string) {
const input = page.getByTestId(`csv-column-path-${columnName}`);
await input.clear();
await input.fill(newPath);
}
export async function submitCsvImport(page: Page) {
await page.getByTestId('csv-submit-import').click();
await expect(page.getByRole('dialog', {name: 'Import CSV'})).not.toBeVisible();
}