mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-24 22:35:23 +00:00
test: import excel
Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
This commit is contained in:
committed by
Muhammed Mustafa
parent
165989bb60
commit
553cc043bc
BIN
scripts/playwright/fixtures/sampleFiles/simple.xlsx
Normal file
BIN
scripts/playwright/fixtures/sampleFiles/simple.xlsx
Normal file
Binary file not shown.
75
scripts/playwright/pages/Dashboard/Import/ImportTemplate.ts
Normal file
75
scripts/playwright/pages/Dashboard/Import/ImportTemplate.ts
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -25,17 +25,42 @@ test.describe("Import", () => {
|
||||
baseId: apiBase!,
|
||||
});
|
||||
await dashboard.rootPage.waitForTimeout(1000);
|
||||
await quickVerify({dashboard, airtableImport: true, context});
|
||||
});
|
||||
|
||||
test("Excel", async () => {
|
||||
await dashboard.treeView.quickImport({ title: "Microsoft Excel" });
|
||||
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,
|
||||
});
|
||||
|
||||
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 () => {
|
||||
await dashboard.treeView.quickImport({ title: "JSON file" });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user