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.
281 lines
9.4 KiB
281 lines
9.4 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import { DashboardPage } from '..';
|
||
|
import BasePage from '../../Base';
|
||
|
import { CellPageObject } from '../common/Cell';
|
||
|
import { ColumnPageObject } from './Column';
|
||
|
import { ToolbarPage } from '../common/Toolbar';
|
||
|
import { ProjectMenuObject } from '../common/ProjectMenu';
|
||
2 years ago
|
|
||
2 years ago
|
export class GridPage extends BasePage {
|
||
|
readonly dashboard: DashboardPage;
|
||
2 years ago
|
readonly addNewTableButton: Locator;
|
||
2 years ago
|
readonly dashboardPage: DashboardPage;
|
||
2 years ago
|
readonly column: ColumnPageObject;
|
||
|
readonly cell: CellPageObject;
|
||
2 years ago
|
readonly toolbar: ToolbarPage;
|
||
2 years ago
|
readonly projectMenu: ProjectMenuObject;
|
||
2 years ago
|
|
||
2 years ago
|
constructor(dashboardPage: DashboardPage) {
|
||
|
super(dashboardPage.rootPage);
|
||
|
this.dashboard = dashboardPage;
|
||
2 years ago
|
this.addNewTableButton = dashboardPage.get().locator('.nc-add-new-table');
|
||
2 years ago
|
this.column = new ColumnPageObject(this);
|
||
|
this.cell = new CellPageObject(this);
|
||
2 years ago
|
this.toolbar = new ToolbarPage(this);
|
||
2 years ago
|
this.projectMenu = new ProjectMenuObject(this);
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
2 years ago
|
return this.dashboard.get().locator('[data-nc="nc-grid-wrapper"]');
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
row(index: number) {
|
||
2 years ago
|
return this.get().locator(`tr[data-nc="grid-row-${index}"]`);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async rowCount() {
|
||
2 years ago
|
return await this.get().locator('.nc-grid-row').count();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verifyRowCount({ count }: { count: number }) {
|
||
2 years ago
|
return await expect(this.get().locator('.nc-grid-row')).toHaveCount(count);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
private async _fillRow({ index, columnHeader, value }: { index: number; columnHeader: string; value: string }) {
|
||
2 years ago
|
const cell = this.cell.get({ index, columnHeader });
|
||
|
await this.cell.dblclick({
|
||
|
index,
|
||
|
columnHeader,
|
||
|
});
|
||
|
|
||
2 years ago
|
await cell.locator('input').fill(value);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async addNewRow({
|
||
|
index = 0,
|
||
2 years ago
|
columnHeader = 'Title',
|
||
2 years ago
|
value,
|
||
2 years ago
|
networkValidation = true,
|
||
2 years ago
|
}: {
|
||
|
index?: number;
|
||
|
columnHeader?: string;
|
||
|
value?: string;
|
||
2 years ago
|
networkValidation?: boolean;
|
||
2 years ago
|
} = {}) {
|
||
2 years ago
|
const rowValue = value ?? `Row ${index}`;
|
||
2 years ago
|
const rowCount = await this.get().locator('.nc-grid-row').count();
|
||
|
await this.get().locator('.nc-grid-add-new-cell').click();
|
||
2 years ago
|
|
||
2 years ago
|
await expect(this.get().locator('.nc-grid-row')).toHaveCount(rowCount + 1);
|
||
2 years ago
|
|
||
2 years ago
|
await this._fillRow({ index, columnHeader, value: rowValue });
|
||
|
|
||
2 years ago
|
const clickOnColumnHeaderToSave = this.get()
|
||
|
.locator(`[data-title="${columnHeader}"]`)
|
||
|
.locator(`span[title="${columnHeader}"]`)
|
||
|
.click();
|
||
2 years ago
|
|
||
2 years ago
|
if (networkValidation) {
|
||
|
await this.waitForResponse({
|
||
|
uiAction: clickOnColumnHeaderToSave,
|
||
2 years ago
|
requestUrlPathToMatch: 'api/v1/db/data/noco',
|
||
|
httpMethodsToMatch: ['POST'],
|
||
|
responseJsonMatcher: resJson => resJson?.[columnHeader] === value,
|
||
2 years ago
|
});
|
||
|
} else {
|
||
|
await this.rootPage.waitForTimeout(300);
|
||
|
}
|
||
2 years ago
|
|
||
|
await this.dashboard.waitForLoaderToDisappear();
|
||
2 years ago
|
}
|
||
|
|
||
|
async editRow({
|
||
|
index = 0,
|
||
2 years ago
|
columnHeader = 'Title',
|
||
2 years ago
|
value,
|
||
2 years ago
|
networkValidation = true,
|
||
2 years ago
|
}: {
|
||
|
index?: number;
|
||
|
columnHeader?: string;
|
||
|
value: string;
|
||
2 years ago
|
networkValidation?: boolean;
|
||
2 years ago
|
}) {
|
||
2 years ago
|
await this._fillRow({ index, columnHeader, value });
|
||
|
|
||
2 years ago
|
const clickOnColumnHeaderToSave = this.get()
|
||
|
.locator(`[data-title="${columnHeader}"]`)
|
||
|
.locator(`span[title="${columnHeader}"]`)
|
||
|
.click();
|
||
2 years ago
|
|
||
2 years ago
|
if (networkValidation) {
|
||
|
await this.waitForResponse({
|
||
|
uiAction: clickOnColumnHeaderToSave,
|
||
2 years ago
|
requestUrlPathToMatch: 'api/v1/db/data/noco',
|
||
|
httpMethodsToMatch: ['PATCH'],
|
||
|
responseJsonMatcher: resJson => resJson?.[columnHeader] === value,
|
||
2 years ago
|
});
|
||
|
} else {
|
||
|
await this.rootPage.waitForTimeout(300);
|
||
|
}
|
||
2 years ago
|
|
||
|
await this.dashboard.waitForLoaderToDisappear();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verifyRow({ index }: { index: number }) {
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-Title-${index}"]`).waitFor({ state: 'visible' });
|
||
|
await expect(this.get().locator(`td[data-nc="cell-Title-${index}"]`)).toHaveCount(1);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verifyRowDoesNotExist({ index }: { index: number }) {
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-Title-${index}"]`).waitFor({ state: 'hidden' });
|
||
|
return await expect(this.get().locator(`td[data-nc="cell-Title-${index}"]`)).toHaveCount(0);
|
||
2 years ago
|
}
|
||
|
|
||
|
async deleteRow(index: number) {
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-Title-${index}"]`).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
|
|
||
|
// Click text=Delete Row
|
||
2 years ago
|
await this.rootPage.locator('text=Delete Row').click();
|
||
2 years ago
|
// todo: improve selector
|
||
2 years ago
|
await this.rootPage
|
||
2 years ago
|
.locator('span.ant-dropdown-menu-title-content > nc-project-menu-item')
|
||
|
.waitFor({ state: 'hidden' });
|
||
2 years ago
|
|
||
2 years ago
|
await this.rootPage.waitForTimeout(300);
|
||
2 years ago
|
await this.dashboard.waitForLoaderToDisappear();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async addRowRightClickMenu(index: number) {
|
||
2 years ago
|
const rowCount = await this.get().locator('.nc-grid-row').count();
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-Title-${index}"]`).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
|
// Click text=Insert New Row
|
||
2 years ago
|
await this.rootPage.locator('text=Insert New Row').click();
|
||
|
await expect(await this.get().locator('.nc-grid-row')).toHaveCount(rowCount + 1);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async openExpandedRow({ index }: { index: number }) {
|
||
2 years ago
|
await this.row(index).locator(`td[data-nc="cell-Id-${index}"]`).hover();
|
||
|
await this.row(index).locator(`div[data-nc="nc-expand-${index}"]`).click();
|
||
2 years ago
|
await (await this.rootPage.locator('.ant-drawer-body').elementHandle())?.waitForElementState('stable');
|
||
2 years ago
|
}
|
||
|
|
||
|
async selectAll() {
|
||
2 years ago
|
await this.get().locator('[data-nc="nc-check-all"]').hover();
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator('[data-nc="nc-check-all"]').locator('input[type="checkbox"]').check({
|
||
2 years ago
|
force: true,
|
||
|
});
|
||
2 years ago
|
|
||
|
const rowCount = await this.rowCount();
|
||
2 years ago
|
for (let i = 0; i < rowCount; i++) {
|
||
2 years ago
|
await expect(this.row(i).locator(`[data-nc="cell-Id-${i}"]`).locator('span.ant-checkbox-checked')).toHaveCount(1);
|
||
2 years ago
|
}
|
||
|
await this.rootPage.waitForTimeout(300);
|
||
2 years ago
|
}
|
||
|
|
||
|
async deleteAll() {
|
||
|
await this.selectAll();
|
||
2 years ago
|
await this.get().locator('[data-nc="nc-check-all"]').nth(0).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
2 years ago
|
await this.rootPage.locator('text=Delete Selected Rows').click();
|
||
2 years ago
|
await this.dashboard.waitForLoaderToDisappear();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
private async pagination({ page }: { page: string }) {
|
||
2 years ago
|
await this.get().locator(`.nc-pagination`).waitFor();
|
||
|
|
||
2 years ago
|
if (page === '<') return this.get().locator('.nc-pagination > .ant-pagination-prev');
|
||
|
if (page === '>') return this.get().locator('.nc-pagination > .ant-pagination-next');
|
||
2 years ago
|
|
||
2 years ago
|
return this.get().locator(`.nc-pagination > .ant-pagination-item.ant-pagination-item-${page}`);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async clickPagination({ page }: { page: string }) {
|
||
2 years ago
|
await this.waitForResponse({
|
||
|
uiAction: (await this.pagination({ page })).click(),
|
||
2 years ago
|
httpMethodsToMatch: ['GET'],
|
||
|
requestUrlPathToMatch: '/views/',
|
||
|
responseJsonMatcher: resJson => resJson?.pageInfo,
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await this.waitLoading();
|
||
|
}
|
||
|
|
||
2 years ago
|
async verifyActivePage({ page }: { page: string }) {
|
||
2 years ago
|
await expect(await this.pagination({ page })).toHaveClass(/ant-pagination-item-active/);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async waitLoading() {
|
||
2 years ago
|
await this.dashboard.get().locator('[data-nc="grid-load-spinner"]').waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async verifyEditDisabled({ columnHeader = 'Title' }: { columnHeader?: string } = {}) {
|
||
2 years ago
|
// double click to toggle to edit mode
|
||
|
const cell = this.cell.get({ index: 0, columnHeader: columnHeader });
|
||
|
await this.cell.dblclick({
|
||
|
index: 0,
|
||
|
columnHeader: columnHeader,
|
||
|
});
|
||
2 years ago
|
await expect(await cell.locator('input')).not.toBeVisible();
|
||
2 years ago
|
|
||
|
// right click menu
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-${columnHeader}-0"]`).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
2 years ago
|
await expect(await this.rootPage.locator('text=Insert New Row')).not.toBeVisible();
|
||
2 years ago
|
|
||
|
// in cell-add
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).hover();
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).locator('.nc-action-icon.nc-plus')
|
||
2 years ago
|
).not.toBeVisible();
|
||
|
|
||
|
// expand row
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).hover();
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).locator('.nc-action-icon >> nth=0')
|
||
2 years ago
|
).not.toBeVisible();
|
||
|
}
|
||
|
|
||
2 years ago
|
async verifyEditEnabled({ columnHeader = 'Title' }: { columnHeader?: string } = {}) {
|
||
2 years ago
|
// double click to toggle to edit mode
|
||
|
const cell = this.cell.get({ index: 0, columnHeader: columnHeader });
|
||
|
await this.cell.dblclick({
|
||
|
index: 0,
|
||
|
columnHeader: columnHeader,
|
||
|
});
|
||
2 years ago
|
await expect(await cell.locator('input')).toBeVisible();
|
||
2 years ago
|
|
||
|
// right click menu
|
||
2 years ago
|
await this.get().locator(`td[data-nc="cell-${columnHeader}-0"]`).click({
|
||
2 years ago
|
button: 'right',
|
||
2 years ago
|
});
|
||
2 years ago
|
await expect(await this.rootPage.locator('text=Insert New Row')).toBeVisible();
|
||
2 years ago
|
|
||
|
// in cell-add
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).hover();
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).locator('.nc-action-icon.nc-plus')
|
||
2 years ago
|
).toBeVisible();
|
||
|
|
||
|
// expand row
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).hover();
|
||
2 years ago
|
await expect(
|
||
2 years ago
|
await this.cell.get({ index: 0, columnHeader: 'City List' }).locator('.nc-action-icon.nc-arrow-expand')
|
||
2 years ago
|
).toBeVisible();
|
||
|
}
|
||
2 years ago
|
|
||
|
async validateRoleAccess(param: { role: string }) {
|
||
|
await this.column.verifyRoleAccess(param);
|
||
|
await this.cell.verifyRoleAccess(param);
|
||
2 years ago
|
await expect(this.get().locator('.nc-grid-add-new-cell')).toHaveCount(
|
||
|
param.role === 'creator' || param.role === 'editor' ? 1 : 0
|
||
2 years ago
|
);
|
||
|
}
|
||
2 years ago
|
}
|