File size: 2,330 Bytes
10c9dc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
// Test uploading a file in an import box.
import { expect, test } from "@playwright/test";
import { Splash, Workspace } from "./lynxkite";

let workspace: Workspace;

test.beforeEach(async ({ browser }) => {
  workspace = await Workspace.empty(
    await browser.newPage(),
    "import_spec_test",
  );
});

test.afterEach(async () => {
  await workspace.close();
  const splash = await new Splash(workspace.page);
  splash.page.on("dialog", async (dialog) => {
    await dialog.accept();
  });
  await splash.deleteEntry("import_spec_test");
});

async function validateImport(
  workspace: Workspace,
  fileName: string,
  fileFormat: string,
) {
  const __filename = fileURLToPath(import.meta.url);
  const __dirname = dirname(__filename);
  const filePath = join(__dirname, "data", fileName);

  await workspace.addBox("Import file");
  const importBox = workspace.getBox("Import file 1");
  const fileFormatSelect = await importBox
    .locator("label.param", { hasText: "file format" })
    .locator("select");
  await fileFormatSelect.selectOption(fileFormat);
  const filePathInput = await importBox
    .locator("label.param", { hasText: "file path" })
    .locator("input");
  await filePathInput.click();
  await filePathInput.fill(filePath);
  await filePathInput.press("Enter");
  const tableNameInput = await importBox
    .locator("label.param", { hasText: "table name" })
    .locator("input");
  await tableNameInput.click();
  await tableNameInput.fill("table");
  await tableNameInput.press("Enter");

  await workspace.addBox("View tables");
  const tableBox = workspace.getBox("View tables 1");
  await workspace.connectBoxes("Import file 1", "View tables 1");

  const tableRows = tableBox.locator("table tbody tr");
  await expect(tableRows).toHaveCount(4);
}

test("Can import a CSV file", async () => {
  await validateImport(workspace, "import_test.csv", "csv");
});

test("Can import a parquet file", async () => {
  await validateImport(workspace, "import_test.parquet", "parquet");
});

test("Can import a JSON file", async () => {
  await validateImport(workspace, "import_test.json", "json");
});

test("Can import an Excel file", async () => {
  await validateImport(workspace, "import_test.xlsx", "excel");
});