Browse Source

test: pagination class verification fix

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
ec0de9bb32
  1. 94
      scripts/playwright/pages/Dashboard/Grid/index.ts

94
scripts/playwright/pages/Dashboard/Grid/index.ts

@ -1,10 +1,10 @@
// playwright-dev-page.ts // playwright-dev-page.ts
import { Locator, expect } from '@playwright/test'; import { Locator, expect } from "@playwright/test";
import { DashboardPage } from '..'; import { DashboardPage } from "..";
import BasePage from '../../Base'; import BasePage from "../../Base";
import { CellPageObject } from './Cell'; import { CellPageObject } from "./Cell";
import { ColumnPageObject } from './Column'; import { ColumnPageObject } from "./Column";
import { ToolbarPage } from './Toolbar'; import { ToolbarPage } from "./Toolbar";
export class GridPage extends BasePage { export class GridPage extends BasePage {
readonly dashboard: DashboardPage; readonly dashboard: DashboardPage;
@ -17,7 +17,7 @@ export class GridPage extends BasePage {
constructor(dashboardPage: DashboardPage) { constructor(dashboardPage: DashboardPage) {
super(dashboardPage.rootPage); super(dashboardPage.rootPage);
this.dashboard = dashboardPage; this.dashboard = dashboardPage;
this.addNewTableButton = dashboardPage.get().locator('.nc-add-new-table'); this.addNewTableButton = dashboardPage.get().locator(".nc-add-new-table");
this.column = new ColumnPageObject(this); this.column = new ColumnPageObject(this);
this.cell = new CellPageObject(this); this.cell = new CellPageObject(this);
this.toolbar = new ToolbarPage(this); this.toolbar = new ToolbarPage(this);
@ -32,69 +32,87 @@ export class GridPage extends BasePage {
} }
async rowCount() { async rowCount() {
await this.get().locator('.nc-grid-row').count(); await this.get().locator(".nc-grid-row").count();
} }
async verifyRowCount({count}: {count: number}) { async verifyRowCount({ count }: { count: number }) {
return expect(await this.get().locator('.nc-grid-row').count()).toBe(count); return expect(await this.get().locator(".nc-grid-row").count()).toBe(count);
} }
async addNewRow({index = 0, title}: {index?: number, title?: string} = {}) { async addNewRow({
const rowCount = await this.get().locator('.nc-grid-row').count(); index = 0,
await this.get().locator('.nc-grid-add-new-cell').click(); title,
if(rowCount + 1 !== await this.get().locator('.nc-grid-row').count()) { }: { index?: number; title?: string } = {}) {
await this.get().locator('.nc-grid-add-new-cell').click(); const rowCount = await this.get().locator(".nc-grid-row").count();
await this.get().locator(".nc-grid-add-new-cell").click();
if (rowCount + 1 !== (await this.get().locator(".nc-grid-row").count())) {
await this.get().locator(".nc-grid-add-new-cell").click();
} }
const cell = this.cell.get({index, columnHeader: 'Title'}); const cell = this.cell.get({ index, columnHeader: "Title" });
await this.cell.dblclick({ await this.cell.dblclick({
index, index,
columnHeader: 'Title' columnHeader: "Title",
}); });
await cell.locator("input").fill(title ?? `Row ${index}`);
await cell.locator('input').fill(title ?? `Row ${index}`); await cell.locator("input").press("Enter");
await cell.locator('input').press('Enter');
} }
async verifyRow({index}: {index: number}) { async verifyRow({ index }: { index: number }) {
await this.get().locator(`td[data-pw="cell-Title-${index}"]`).waitFor({state: 'visible'}); await this.get()
expect(await this.get().locator(`td[data-pw="cell-Title-${index}"]`).count()).toBe(1); .locator(`td[data-pw="cell-Title-${index}"]`)
.waitFor({ state: "visible" });
expect(
await this.get().locator(`td[data-pw="cell-Title-${index}"]`).count()
).toBe(1);
} }
async verifyRowDoesNotExist({index}: {index: number}) { async verifyRowDoesNotExist({ index }: { index: number }) {
await this.get().locator(`td[data-pw="cell-Title-${index}"]`).waitFor({state: 'hidden'}); await this.get()
return expect(await this.get().locator(`td[data-pw="cell-Title-${index}"]`).count()).toBe(0); .locator(`td[data-pw="cell-Title-${index}"]`)
.waitFor({ state: "hidden" });
return expect(
await this.get().locator(`td[data-pw="cell-Title-${index}"]`).count()
).toBe(0);
} }
async deleteRow(index: number) { async deleteRow(index: number) {
await this.get().locator(`td[data-pw="cell-Title-${index}"]`).click({ await this.get().locator(`td[data-pw="cell-Title-${index}"]`).click({
button: 'right' button: "right",
}); });
// Click text=Delete Row // Click text=Delete Row
await this.rootPage.locator('text=Delete Row').click(); await this.rootPage.locator("text=Delete Row").click();
// todo: improve selector // todo: improve selector
await this.rootPage.locator('span.ant-dropdown-menu-title-content > nc-project-menu-item').waitFor({state: 'hidden'}); await this.rootPage
.locator("span.ant-dropdown-menu-title-content > nc-project-menu-item")
.waitFor({ state: "hidden" });
await this.rootPage.waitForTimeout(300); await this.rootPage.waitForTimeout(300);
} }
async openExpandedRow({index}:{index: number}) { async openExpandedRow({ index }: { index: number }) {
await this.row(index).locator(`td[pw-data="cell-id-${index}"]`).hover(); await this.row(index).locator(`td[pw-data="cell-id-${index}"]`).hover();
await this.row(index).locator(`div[pw-data="nc-expand-${index}"]`).click(); await this.row(index).locator(`div[pw-data="nc-expand-${index}"]`).click();
} }
async selectAll() { async selectAll() {
await this.get().locator('[pw-data="nc-check-all"]').hover(); await this.get().locator('[pw-data="nc-check-all"]').hover();
await this.get().locator('[pw-data="nc-check-all"]').locator('input[type="checkbox"]').click(); await this.get()
.locator('[pw-data="nc-check-all"]')
.locator('input[type="checkbox"]')
.click();
} }
async deleteAll() { async deleteAll() {
await this.selectAll(); await this.selectAll();
await this.get().locator('[pw-data="nc-check-all"]').locator('input[type="checkbox"]').click({ await this.get()
button: 'right' .locator('[pw-data="nc-check-all"]')
}); .locator('input[type="checkbox"]')
await this.rootPage.locator('text=Delete Selected Rows').click(); .click({
button: "right",
});
await this.rootPage.locator("text=Delete Selected Rows").click();
} }
async pagination({ page }: { page: string }) { async pagination({ page }: { page: string }) {
@ -111,6 +129,8 @@ export class GridPage extends BasePage {
} }
async verifyActivePage({ page }: { page: string }) { async verifyActivePage({ page }: { page: string }) {
expect(await this.pagination({ page })).toHaveClass("ant-pagination-item-active"); expect(await this.pagination({ page })).toHaveClass(
/ant-pagination-item-active/
);
} }
} }

Loading…
Cancel
Save