Browse Source

test: grid share view

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
0d631fe6f7
  1. 4
      scripts/playwright/fixtures/expectedData.txt
  2. 13
      scripts/playwright/package-lock.json
  3. 3
      scripts/playwright/package.json
  4. 8
      scripts/playwright/pages/Dashboard/Grid/Column/index.ts
  5. 3
      scripts/playwright/pages/Dashboard/Grid/Toolbar/Filter.ts
  6. 5
      scripts/playwright/pages/Dashboard/Grid/Toolbar/Sort.ts
  7. 33
      scripts/playwright/pages/Dashboard/Grid/Toolbar/index.ts
  8. 128
      scripts/playwright/tests/gridViewShare.spec.ts

4
scripts/playwright/fixtures/expectedData.txt

@ -0,0 +1,4 @@
Address,District,PostalCode,Phone,Location,Customer List,Staff List,City,Staff List1
1661 Abha Drive,Tamil Nadu,14400,270456873752,"{""x"":78.8214191,""y"":10.3812871}",1,,Pudukkottai,
1993 Tabuk Lane,Tamil Nadu,64221,648482415405,"{""x"":80.1270701,""y"":12.9246028}",2,,Tambaram,
381 Kabul Way,Taipei,87272,55477302294,"{""x"":0,""y"":0}",2,,Hsichuh,

13
scripts/playwright/package-lock.json generated

@ -8,6 +8,9 @@
"name": "playwright",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"fs": "^0.0.1-security"
},
"devDependencies": {
"@playwright/test": "^1.26.1",
"axios": "^0.24.0",
@ -173,6 +176,11 @@
}
}
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -1074,6 +1082,11 @@
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true
},
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",

3
scripts/playwright/package.json

@ -17,5 +17,8 @@
"dotenv": "^16.0.3",
"mysql2": "^2.3.3",
"promised-sqlite3": "^1.2.0"
},
"dependencies": {
"fs": "^0.0.1-security"
}
}

8
scripts/playwright/pages/Dashboard/Grid/Column/index.ts

@ -213,13 +213,13 @@ export class ColumnPageObject extends BasePage {
}
async verify({ title, isVisible }: { title: string; isVisible?: boolean }) {
if (isVisible) {
if (false === isVisible) {
return expect(
await this.rootPage.locator(`th[data-title="${title}"]`).count()
).toBe(0);
}
await expect(this.rootPage.locator(`th[data-title="${title}"]`)).toHaveText(
title
);
await expect(
this.rootPage.locator(`th[data-title="${title}"]`)
).toContainText(title);
}
}

3
scripts/playwright/pages/Dashboard/Grid/Toolbar/Filter.ts

@ -29,11 +29,10 @@ export class ToolbarFilterPage extends BasePage {
await this.rootPage.locator(".nc-filter-field-select").last().click();
await this.rootPage
.locator("div.ant-select-dropdown.nc-dropdown-toolbar-field-list")
.locator(`div[label="${columnTitle}"][aria-selected="false"]`)
.locator(`div[label="${columnTitle}"][aria-selected="false"]:visible`)
.click();
await this.rootPage.locator(".nc-filter-operation-select").last().click();
// await this.rootPage.locator('.nc-dropdown-filter-comp-op').locator(`.ant-select-item:has-text("${opType}")`).scrollIntoViewIfNeeded();
await this.rootPage
.locator(".nc-dropdown-filter-comp-op")
.locator(`.ant-select-item:has-text("${opType}")`)

5
scripts/playwright/pages/Dashboard/Grid/Toolbar/Sort.ts

@ -25,13 +25,14 @@ export class ToolbarSortPage extends BasePage {
await this.get().locator(`button:has-text("Add Sort Option")`).click();
await this.rootPage.locator(".nc-sort-field-select").click();
await this.rootPage.locator(".nc-sort-field-select").last().click();
await this.rootPage
.locator("div.ant-select-dropdown.nc-dropdown-toolbar-field-list")
.locator(`div[label="${columnTitle}"]`)
.last()
.click();
await this.rootPage.locator(".nc-sort-dir-select").click();
await this.rootPage.locator(".nc-sort-dir-select").last().click();
await this.rootPage
.locator(".nc-dropdown-sort-dir")
.locator(".ant-select-item")

33
scripts/playwright/pages/Dashboard/Grid/Toolbar/index.ts

@ -1,9 +1,11 @@
import { expect } from "@playwright/test";
import BasePage from "../../../Base";
import { GridPage } from "..";
import { ToolbarFieldsPage } from "./Fields";
import { ToolbarSortPage } from "./Sort";
import { ToolbarFilterPage } from "./Filter";
import { ToolbarShareViewPage } from "./ShareView";
import fs from "fs";
export class ToolbarPage extends BasePage {
readonly grid: GridPage;
@ -31,7 +33,7 @@ export class ToolbarPage extends BasePage {
await this.get().locator(`button:has-text("Fields")`).click();
// Wait for the menu to close
if(menuOpen) await this.fields.get().waitFor({ state: "hidden" });
if (menuOpen) await this.fields.get().waitFor({ state: "hidden" });
}
async clickSort() {
@ -40,7 +42,7 @@ export class ToolbarPage extends BasePage {
await this.get().locator(`button:has-text("Sort")`).click();
// Wait for the menu to close
if(menuOpen) await this.sort.get().waitFor({ state: "hidden" });
if (menuOpen) await this.sort.get().waitFor({ state: "hidden" });
}
async clickFilter() {
@ -49,19 +51,40 @@ export class ToolbarPage extends BasePage {
await this.get().locator(`button:has-text("Filter")`).click();
// Wait for the menu to close
if(menuOpen) await this.filter.get().waitFor({ state: "hidden" });
if (menuOpen) await this.filter.get().waitFor({ state: "hidden" });
}
async clickShareView() {
const menuOpen = await this.shareView.get().isVisible();
await this.get().locator(`button:has-text("Share View")`).click();
// Wait for the menu to close
if(menuOpen) await this.shareView.get().waitFor({ state: "hidden" });
if (menuOpen) await this.shareView.get().waitFor({ state: "hidden" });
}
async clickAddNewRow() {
await this.get().locator(`.nc-toolbar-btn.nc-add-new-row-btn`).click();
}
async clickDownload(type: string, verificationFile: string) {
await this.get().locator(`.nc-toolbar-btn.nc-actions-menu-btn`).click();
const [download] = await Promise.all([
// Start waiting for the download
this.rootPage.waitForEvent("download"),
// Perform the action that initiates download
this.rootPage
.locator(`.nc-dropdown-actions-menu`)
.locator(`li.ant-dropdown-menu-item:has-text("${type}")`)
.click(),
]);
// Save downloaded file somewhere
await download.saveAs("./at.txt");
// verify downloaded content against expected content
const expectedData = fs.readFileSync("./fixtures/expectedData.txt", "utf8");
const file = fs.readFileSync("./at.txt", "utf8");
await expect(file).toEqual(expectedData);
}
}

128
scripts/playwright/tests/gridViewShare.spec.ts

@ -0,0 +1,128 @@
import { test } from "@playwright/test";
import { DashboardPage } from "../pages/Dashboard";
import setup from "../setup";
test.describe("Shared view", () => {
let dashboard: DashboardPage;
let context: any;
test.beforeEach(async ({ page }) => {
context = await setup({ page });
dashboard = new DashboardPage(page, context.project);
});
test("Grid share", async ({ page }) => {
// close 'Team & Auth' tab
await dashboard.closeTab({ title: "Team & Auth" });
await dashboard.treeView.openTable({ title: "Address" });
// hide column
await dashboard.grid.toolbar.fields.toggle({ title: "Address2" });
// sort
await dashboard.grid.toolbar.sort.addSort({
columnTitle: "District",
isAscending: false,
});
// filter
await dashboard.grid.toolbar.filter.addNew({
columnTitle: "Address",
value: "Ab",
opType: "is like",
});
const mainPageLink = page.url();
// share with password disabled, download enabled
await dashboard.grid.toolbar.clickShareView();
let link = await dashboard.grid.toolbar.shareView.getShareLink();
await page.goto(link);
const sharedPage = new DashboardPage(page, context.project);
let expectedColumns = [
{ title: "Address", isVisible: true },
{ title: "Address2", isVisible: false },
{ title: "District", isVisible: true },
{ title: "City", isVisible: true },
{ title: "PostalCode", isVisible: true },
{ title: "Phone", isVisible: true },
{ title: "LastUpdate", isVisible: true },
{ title: "Customer List", isVisible: true },
{ title: "Staff List", isVisible: true },
{ title: "City", isVisible: true },
];
for (const column of expectedColumns) {
await sharedPage.grid.column.verify(column);
}
const expectedRecords = [
{ index: 0, columnHeader: "Address", value: "1013 Tabuk Boulevard" },
{
index: 1,
columnHeader: "Address",
value: "1892 Nabereznyje Telny Lane",
},
{ index: 2, columnHeader: "Address", value: "1993 Tabuk Lane" },
{ index: 0, columnHeader: "District", value: "West Bengali" },
{ index: 1, columnHeader: "District", value: "Tutuila" },
{ index: 2, columnHeader: "District", value: "Tamil Nadu" },
{ index: 0, columnHeader: "PostalCode", value: "96203" },
{ index: 1, columnHeader: "PostalCode", value: "28396" },
{ index: 2, columnHeader: "PostalCode", value: "64221" },
{ index: 0, columnHeader: "Phone", value: "158399646978" },
{ index: 1, columnHeader: "Phone", value: "478229987054" },
{ index: 2, columnHeader: "Phone", value: "648482415405" },
];
// verify order of records (original sort & filter)
for (const record of expectedRecords) {
await sharedPage.grid.cell.verify(record);
}
// create new sort & filter criteria in shared view
await sharedPage.grid.toolbar.sort.addSort({
columnTitle: "Address",
isAscending: true,
});
await sharedPage.grid.toolbar.filter.addNew({
columnTitle: "District",
value: "Ta",
opType: "is like",
});
await sharedPage.grid.toolbar.fields.toggle({ title: "LastUpdate" });
expectedColumns[6].isVisible = false;
// verify new sort & filter criteria
for (const column of expectedColumns) {
await sharedPage.grid.column.verify(column);
}
const expectedRecords2 = [
{ index: 0, columnHeader: "Address", value: "1661 Abha Drive" },
{ index: 1, columnHeader: "Address", value: "1993 Tabuk Lane" },
{ index: 2, columnHeader: "Address", value: "381 Kabul Way" },
{ index: 0, columnHeader: "District", value: "Tamil Nadu" },
{ index: 1, columnHeader: "District", value: "Tamil Nadu" },
{ index: 2, columnHeader: "District", value: "Taipei" },
{ index: 0, columnHeader: "PostalCode", value: "14400" },
{ index: 1, columnHeader: "PostalCode", value: "64221" },
{ index: 2, columnHeader: "PostalCode", value: "87272" },
{ index: 0, columnHeader: "Phone", value: "270456873752" },
{ index: 1, columnHeader: "Phone", value: "648482415405" },
{ index: 2, columnHeader: "Phone", value: "55477302294" },
];
// verify order of records (original sort & filter)
for (const record of expectedRecords2) {
await sharedPage.grid.cell.verify(record);
}
// verify download
await sharedPage.grid.toolbar.clickDownload(
"Download as CSV",
"./expectedData.txt"
);
// await dashboard.closeTab({ title: "Address" });
});
});
Loading…
Cancel
Save