mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
80 lines
2.7 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import BasePage from '../../Base';
|
||
|
import { DashboardPage } from '..';
|
||
2 years ago
|
|
||
|
export class ImportTemplatePage extends BasePage {
|
||
|
readonly dashboard: DashboardPage;
|
||
|
readonly importButton: Locator;
|
||
|
|
||
|
constructor(dashboard: DashboardPage) {
|
||
|
super(dashboard.rootPage);
|
||
|
this.dashboard = dashboard;
|
||
2 years ago
|
this.importButton = dashboard.get().locator('.nc-btn-import');
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
|
return this.dashboard.get().locator(`.nc-modal-quick-import`);
|
||
|
}
|
||
|
|
||
|
async getImportTableList() {
|
||
|
await this.get().locator(`.ant-collapse-header`).nth(0).waitFor();
|
||
2 years ago
|
const tr = await this.get().locator(`.ant-collapse-header`);
|
||
|
const rowCount = await tr.count();
|
||
|
const tableList: string[] = [];
|
||
2 years ago
|
for (let i = 0; i < rowCount; i++) {
|
||
2 years ago
|
const tableName = await tr.nth(i).innerText();
|
||
2 years ago
|
tableList.push(tableName);
|
||
|
}
|
||
|
return tableList;
|
||
|
}
|
||
|
|
||
|
async getImportColumnList() {
|
||
|
// return an array
|
||
2 years ago
|
const columnList: { type: string; name: string }[] = [];
|
||
|
const tr = await this.get().locator(`tr.ant-table-row-level-0:visible`);
|
||
|
const rowCount = await tr.count();
|
||
2 years ago
|
for (let i = 0; i < rowCount; i++) {
|
||
|
// replace \n and \t from innerText
|
||
2 years ago
|
const columnType = await tr
|
||
2 years ago
|
.nth(i)
|
||
|
.innerText()
|
||
2 years ago
|
.then(text => text.replace(/\n|\t/g, ''));
|
||
|
const columnName = await tr.nth(i).locator(`input[type="text"]`).inputValue();
|
||
2 years ago
|
columnList.push({ type: columnType, name: columnName });
|
||
|
}
|
||
|
return columnList;
|
||
|
}
|
||
|
|
||
2 years ago
|
// todo: Add polling logic to assertions
|
||
2 years ago
|
async import({ file, result }: { file: string; result: any }) {
|
||
2 years ago
|
const importFile = this.get().locator(`input[type="file"]`);
|
||
2 years ago
|
await importFile.setInputFiles(file);
|
||
|
await this.importButton.click();
|
||
|
|
||
2 years ago
|
const tblList = await this.getImportTableList();
|
||
2 years ago
|
for (let i = 0; i < result.length; i++) {
|
||
2 years ago
|
await expect(tblList[i]).toBe(result[i].name);
|
||
2 years ago
|
const columnList = await this.getImportColumnList();
|
||
2 years ago
|
await expect(columnList).toEqual(result[i].columns);
|
||
2 years ago
|
if (i < result.length - 1) {
|
||
|
await this.expandTableList({ index: i + 1 });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
await this.get().locator('button:has-text("Back"):visible').waitFor();
|
||
2 years ago
|
await this.waitForResponse({
|
||
|
requestUrlPathToMatch: '/api/v1/db/data/noco/',
|
||
|
httpMethodsToMatch: ['GET'],
|
||
2 years ago
|
uiAction: this.get().locator('button:has-text("Import"):visible').click(),
|
||
2 years ago
|
});
|
||
|
await this.dashboard.waitForTabRender({
|
||
|
title: tblList[0],
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
private async expandTableList(param: { index: number }) {
|
||
|
await this.get().locator(`.ant-collapse-header`).nth(param.index).click();
|
||
|
await this.rootPage.waitForTimeout(1000);
|
||
|
}
|
||
|
}
|