Browse Source

test: import excel

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3848/head
Raju Udava 2 years ago committed by Muhammed Mustafa
parent
commit
553cc043bc
  1. BIN
      scripts/playwright/fixtures/sampleFiles/simple.xlsx
  2. 75
      scripts/playwright/pages/Dashboard/Import/ImportTemplate.ts
  3. 2
      scripts/playwright/pages/Dashboard/index.ts
  4. 33
      scripts/playwright/tests/import.spec.ts

BIN
scripts/playwright/fixtures/sampleFiles/simple.xlsx

Binary file not shown.

75
scripts/playwright/pages/Dashboard/Import/ImportTemplate.ts

@ -0,0 +1,75 @@
// playwright-dev-page.ts
import { expect, Locator } from "@playwright/test";
import BasePage from "../../Base";
import { DashboardPage } from "..";
export class ImportTemplatePage extends BasePage {
readonly dashboard: DashboardPage;
readonly importButton: Locator;
constructor(dashboard: DashboardPage) {
super(dashboard.rootPage);
this.dashboard = dashboard;
this.importButton = dashboard.get().locator(".nc-btn-import");
}
get() {
return this.dashboard.get().locator(`.nc-modal-quick-import`);
}
async getImportTableList() {
await this.get().locator(`.ant-collapse-header`).nth(0).waitFor();
let tr = await this.get().locator(`.ant-collapse-header`);
let rowCount = await tr.count();
let tableList = [];
for (let i = 0; i < rowCount; i++) {
let tableName = await tr.nth(i).innerText();
tableList.push(tableName);
}
return tableList;
}
async getImportColumnList() {
// return an array
let columnList = [];
let tr = await this.get().locator(`tr.ant-table-row-level-0:visible`);
let rowCount = await tr.count();
for (let i = 0; i < rowCount; i++) {
// replace \n and \t from innerText
let columnType = await tr
.nth(i)
.innerText()
.then((text) => text.replace(/\n|\t/g, ""));
let columnName = await tr
.nth(i)
.locator(`input[type="text"]`)
.inputValue();
columnList.push({ type: columnType, name: columnName });
}
return columnList;
}
async import({ file, result }: { file: string; result: any }) {
let importFile = this.get().locator(`input[type="file"]`);
await importFile.setInputFiles(file);
await this.importButton.click();
let tblList = await this.getImportTableList();
for (let i = 0; i < result.length; i++) {
expect(tblList[i]).toBe(result[i].name);
let columnList = await this.getImportColumnList();
expect(columnList).toEqual(result[i].columns);
if (i < result.length - 1) {
await this.expandTableList({ index: i + 1 });
}
}
await this.get().locator('button:has-text("Back"):visible').waitFor();
await this.get().locator('button:has-text("Import"):visible').click();
}
private async expandTableList(param: { index: number }) {
await this.get().locator(`.ant-collapse-header`).nth(param.index).click();
await this.rootPage.waitForTimeout(1000);
}
}

2
scripts/playwright/pages/Dashboard/index.ts

@ -13,6 +13,7 @@ import { GalleryPage } from "./Gallery";
import { KanbanPage } from "./Kanban";
import { ToolbarPage } from "./common/Toolbar";
import { ImportAirtablePage } from "./Import/Airtable";
import { ImportTemplatePage } from "./Import/ImportTemplate";
import { WebhookFormPage } from "./WebhookForm";
export class DashboardPage extends BasePage {
@ -31,6 +32,7 @@ export class DashboardPage extends BasePage {
readonly settings: SettingsPage;
readonly viewSidebar: ViewSidebarPage;
readonly importAirtable: ImportAirtablePage;
readonly importTemplate = new ImportTemplatePage(this);
constructor(rootPage: Page, project: any) {
super(rootPage);

33
scripts/playwright/tests/import.spec.ts

@ -25,15 +25,40 @@ test.describe("Import", () => {
baseId: apiBase!,
});
await dashboard.rootPage.waitForTimeout(1000);
await quickVerify({dashboard, airtableImport: true, context});
await quickVerify({ dashboard, airtableImport: true, context });
});
test("CSV", async () => {
await dashboard.treeView.quickImport({ title: "CSV file" });
});
test("Excel", async () => {
const col = [
{ type: "Number", name: "number" },
{ type: "Decimal", name: "float" },
{ type: "SingleLineText", name: "text" },
];
const expected = [
{ name: "Sheet2", columns: col },
{ name: "Sheet3", columns: col },
{ name: "Sheet4", columns: col },
];
await dashboard.treeView.quickImport({ title: "Microsoft Excel" });
});
await dashboard.importTemplate.import({
file: `${process.cwd()}/fixtures/sampleFiles/simple.xlsx`,
result: expected,
});
test("CSV", async () => {
await dashboard.treeView.quickImport({ title: "CSV file" });
let recordCells = { Number: "1", Float: "1.10", Text: "abc" };
for (let [key, value] of Object.entries(recordCells)) {
await dashboard.grid.cell.verify({
index: 0,
columnHeader: key,
value,
});
}
});
test("JSON", async () => {

Loading…
Cancel
Save