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.
137 lines
5.2 KiB
137 lines
5.2 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import { DashboardPage } from '.';
|
||
|
import BasePage from '../Base';
|
||
2 years ago
|
|
||
2 years ago
|
export class TreeViewPage extends BasePage {
|
||
|
readonly dashboard: DashboardPage;
|
||
2 years ago
|
readonly project: any;
|
||
2 years ago
|
readonly quickImportButton: Locator;
|
||
2 years ago
|
readonly inviteTeamButton: Locator;
|
||
2 years ago
|
|
||
2 years ago
|
constructor(dashboard: DashboardPage, project: any) {
|
||
|
super(dashboard.rootPage);
|
||
|
this.dashboard = dashboard;
|
||
2 years ago
|
this.project = project;
|
||
2 years ago
|
this.quickImportButton = dashboard.get().locator('.nc-import-menu');
|
||
|
this.inviteTeamButton = dashboard.get().locator('.nc-share-base');
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
2 years ago
|
return this.dashboard.get().locator('.nc-treeview-container');
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async focusTable({ title }: { title: string }) {
|
||
|
await this.get().locator(`.nc-project-tree-tbl-${title}`).focus();
|
||
|
}
|
||
|
|
||
2 years ago
|
// assumption: first view rendered is always GRID
|
||
|
//
|
||
2 years ago
|
async openTable({ title, mode = 'standard' }: { title: string; mode?: string }) {
|
||
|
if ((await this.get().locator('.active.nc-project-tree-tbl').count()) > 0) {
|
||
|
if ((await this.get().locator('.active.nc-project-tree-tbl').innerText()) === title) {
|
||
2 years ago
|
// table already open
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
await this.waitForResponse({
|
||
2 years ago
|
uiAction: this.get().locator(`.nc-project-tree-tbl-${title}`).click(),
|
||
2 years ago
|
httpMethodsToMatch: ['GET'],
|
||
2 years ago
|
requestUrlPathToMatch: `/api/v1/db/data/noco/`,
|
||
2 years ago
|
responseJsonMatcher: json => json.pageInfo,
|
||
2 years ago
|
});
|
||
2 years ago
|
await this.dashboard.waitForTabRender({ title, mode });
|
||
2 years ago
|
}
|
||
|
|
||
|
async createTable({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator('.nc-add-new-table').click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.dashboard.get().locator('.nc-modal-table-create').locator('.ant-modal-body').waitFor();
|
||
2 years ago
|
|
||
2 years ago
|
await this.dashboard.get().locator('[placeholder="Enter table name"]').fill(title);
|
||
2 years ago
|
|
||
|
await this.waitForResponse({
|
||
2 years ago
|
uiAction: this.dashboard.get().locator('button:has-text("Submit")').click(),
|
||
|
httpMethodsToMatch: ['POST'],
|
||
2 years ago
|
requestUrlPathToMatch: `/api/v1/db/meta/projects/`,
|
||
2 years ago
|
responseJsonMatcher: json => json.title === title && json.type === 'table',
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await this.dashboard.waitForTabRender({ title });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verifyTable({ title, index, exists = true }: { title: string; index?: number; exists?: boolean }) {
|
||
2 years ago
|
if (exists) {
|
||
2 years ago
|
await expect(this.get().locator(`.nc-project-tree-tbl-${title}`)).toBeVisible();
|
||
2 years ago
|
|
||
|
if (index) {
|
||
2 years ago
|
await expect(await this.get().locator('.nc-tbl-title').nth(index)).toHaveText(title);
|
||
2 years ago
|
}
|
||
|
} else {
|
||
2 years ago
|
await expect(this.get().locator(`.nc-project-tree-tbl-${title}`)).toHaveCount(0);
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
|
async deleteTable({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator(`.nc-project-tree-tbl-${title}`).click({ button: 'right' });
|
||
|
await this.dashboard.get().locator('div.nc-project-menu-item:has-text("Delete")').click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.waitForResponse({
|
||
2 years ago
|
uiAction: this.dashboard.get().locator('button:has-text("Yes")').click(),
|
||
2 years ago
|
httpMethodsToMatch: ['DELETE'],
|
||
2 years ago
|
requestUrlPathToMatch: `/api/v1/db/meta/tables/`,
|
||
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await expect
|
||
|
.poll(
|
||
|
async () =>
|
||
|
await this.dashboard.tabBar
|
||
2 years ago
|
.locator('.ant-tabs-tab', {
|
||
2 years ago
|
hasText: title,
|
||
|
})
|
||
|
.isVisible()
|
||
|
)
|
||
|
.toBe(false);
|
||
|
|
||
2 years ago
|
(await this.rootPage.locator('.nc-container').last().elementHandle())?.waitForElementState('stable');
|
||
2 years ago
|
}
|
||
|
|
||
|
async renameTable({ title, newTitle }: { title: string; newTitle: string }) {
|
||
2 years ago
|
await this.get().locator(`.nc-project-tree-tbl-${title}`).click({ button: 'right' });
|
||
|
await this.dashboard.get().locator('div.nc-project-menu-item:has-text("Rename")').click();
|
||
|
await this.dashboard.get().locator('[placeholder="Enter table name"]').fill(newTitle);
|
||
2 years ago
|
await this.dashboard.get().locator('button:has-text("Submit")').click();
|
||
2 years ago
|
await this.verifyToast({ message: 'Table renamed successfully' });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async reorderTables({ sourceTable, destinationTable }: { sourceTable: string; destinationTable: string }) {
|
||
2 years ago
|
await this.dashboard
|
||
|
.get()
|
||
2 years ago
|
.locator(`[data-nc="tree-view-table-draggable-handle-${sourceTable}"]`)
|
||
|
.dragTo(this.get().locator(`[data-nc="tree-view-table-${destinationTable}"]`));
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async quickImport({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator('.nc-add-new-table').hover();
|
||
2 years ago
|
await this.quickImportButton.click();
|
||
2 years ago
|
const importMenu = this.dashboard.get().locator('.nc-dropdown-import-menu');
|
||
|
await importMenu.locator(`.ant-dropdown-menu-title-content:has-text("${title}")`).click();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async validateRoleAccess(param: { role: string }) {
|
||
|
// Add new table button
|
||
2 years ago
|
await expect(this.get().locator(`.nc-add-new-table`)).toHaveCount(param.role === 'creator' ? 1 : 0);
|
||
2 years ago
|
// Import menu
|
||
2 years ago
|
await expect(this.get().locator(`.nc-import-menu`)).toHaveCount(param.role === 'creator' ? 1 : 0);
|
||
2 years ago
|
// Invite Team button
|
||
2 years ago
|
await expect(this.get().locator(`.nc-share-base`)).toHaveCount(param.role === 'creator' ? 1 : 0);
|
||
2 years ago
|
// Right click context menu
|
||
|
await this.get().locator(`.nc-project-tree-tbl-Country`).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
2 years ago
|
await expect(this.rootPage.locator(`.nc-dropdown-tree-view-context-menu:visible`)).toHaveCount(
|
||
|
param.role === 'creator' ? 1 : 0
|
||
|
);
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|