From 56df4f1fe27b6b5a7d7321032b06453f79d6b39f Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Thu, 13 Oct 2022 21:41:23 +0530 Subject: [PATCH] test: formula Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../pages/Dashboard/Grid/Column/index.ts | 38 ++++-- scripts/playwright/tests/formula.spec.ts | 119 ++++++++++++++++++ .../tests/virtualColumnRelational.spec.ts | 1 + 3 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 scripts/playwright/tests/formula.spec.ts diff --git a/scripts/playwright/pages/Dashboard/Grid/Column/index.ts b/scripts/playwright/pages/Dashboard/Grid/Column/index.ts index c0a1a60779..b17c734e58 100644 --- a/scripts/playwright/pages/Dashboard/Grid/Column/index.ts +++ b/scripts/playwright/pages/Dashboard/Grid/Column/index.ts @@ -20,16 +20,18 @@ export class ColumnPageObject extends BasePage { async create({ title, type = "SingleLineText", + formula = "", }: { title: string; type?: string; + formula?: string; }) { await this.grid.get().locator(".nc-column-add").click(); - // await this.get().waitFor(); - + await this.rootPage.waitForTimeout(500); await this.fillTitle({ title }); - + await this.rootPage.waitForTimeout(500); await this.selectType({ type }); + await this.rootPage.waitForTimeout(500); switch (type) { case "SingleTextLine": @@ -47,6 +49,9 @@ export class ColumnPageObject extends BasePage { skipColumnModal: true, }); break; + case "Formula": + await this.get().locator(".nc-formula-input").fill(formula); + break; default: break; } @@ -92,20 +97,35 @@ export class ColumnPageObject extends BasePage { .waitFor({ state: "hidden" }); } - async openEdit({ title }: { title: string }) { - // todo: Improve this selector + async openEdit({ + title, + type = "SingleLineText", + formula = "", + }: { + title: string; + type?: string; + formula?: string; + }) { await this.grid .get() - .locator(`text=#Title${title} >> svg >> nth=3`) + .locator(`th[data-title="${title}"] .nc-ui-dt-dropdown`) .click(); await this.rootPage.locator('li[role="menuitem"]:has-text("Edit")').click(); - await this.get().waitFor({state: 'visible'}); + await this.get().waitFor({ state: "visible" }); // todo: Hack to wait for the modal to be fully loaded - await this.fillTitle({title: "dummy"}); - await this.fillTitle({title}); + await this.fillTitle({ title: "dummy" }); + await this.fillTitle({ title }); await this.get().locator('label[title="Column Name"]').click(); + + switch (type) { + case "Formula": + await this.get().locator(".nc-formula-input").fill(formula); + break; + default: + break; + } } async save({ isUpdated }: { isUpdated?: boolean } = {}) { diff --git a/scripts/playwright/tests/formula.spec.ts b/scripts/playwright/tests/formula.spec.ts new file mode 100644 index 0000000000..83acaa14d1 --- /dev/null +++ b/scripts/playwright/tests/formula.spec.ts @@ -0,0 +1,119 @@ +import { test } from "@playwright/test"; +import { DashboardPage } from "../pages/Dashboard"; +import setup from "../setup"; + +// Add formula to be verified here & store expected results for 5 rows +// Column data from City table (Sakila DB) +/** + * City LastUpdate Address List Country + * A Corua (La Corua) 2006-02-15 04:45:25 939 Probolinggo Loop Spain + * Abha 2006-02-15 04:45:25 733 Mandaluyong Place Saudi Arabia + * Abu Dhabi 2006-02-15 04:45:25 535 Ahmadnagar Manor United Arab Emirates + * Acua 2006-02-15 04:45:25 1789 Saint-Denis Parkway Mexico + * Adana 2006-02-15 04:45:25 663 Baha Blanca Parkway Turkey + */ +const formulaData = [ + { + formula: "1 + 1", + result: ["2", "2", "2", "2", "2"], + }, + { + formula: + "ADD({CityId}, {CountryId}) + AVG({CityId}, {CountryId}) + LEN({City})", + result: ["150", "130", "165", "100", "158"], + }, + { + formula: `WEEKDAY("2022-07-19")`, + result: ["1", "1", "1", "1", "1"], + }, + { + formula: `WEEKDAY("2022-07-19", "sunday")`, + result: ["2", "2", "2", "2", "2"], + }, + { + formula: `CONCAT(UPPER({City}), LOWER({City}), TRIM(' trimmed '))`, + result: [ + '"A CORUA (LA CORUA)a corua (la corua)trimmed"', + '"ABHAabhatrimmed"', + '"ABU DHABIabu dhabitrimmed"', + '"ACUAacuatrimmed"', + '"ADANAadanatrimmed"', + ], + }, + { + formula: `CEILING(1.4) + FLOOR(1.6) + ROUND(2.5) + MOD({CityId}, 3) + MIN({CityId}, {CountryId}) + MAX({CityId}, {CountryId})`, + result: ['"95"', '"92"', '"110"', '"71"', '"110"'], + }, + { + formula: `LOG({CityId}) + EXP({CityId}) + POWER({CityId}, 3) + SQRT({CountryId})`, + result: [ + "13.04566088154786", + "25.137588417628013", + "58.23402483297667", + "127.73041108667896", + "284.8714548168068", + ], + }, + { + formula: `NOW()`, + result: ["1", "1", "1", "1", "1"], + }, +]; + +test.describe("Virtual Columns", () => { + let dashboard: DashboardPage; + let context: any; + + test.beforeEach(async ({ page }) => { + context = await setup({ page }); + dashboard = new DashboardPage(page, context.project); + }); + + async function formulaResultVerify({ + title, + result, + }: { + title: string; + result: string[]; + }) { + for (let i = 0; i < result.length; i++) { + await dashboard.grid.cell.verify({ + index: i, + columnHeader: title, + value: result[i], + }); + } + } + + test("Formula", async () => { + // close 'Team & Auth' tab + await dashboard.closeTab({ title: "Team & Auth" }); + + await dashboard.treeView.openTable({ title: "City" }); + + // Create formula column + await dashboard.grid.column.create({ + title: "NC_MATH_0", + type: "Formula", + formula: formulaData[1].formula, + }); + + // verify different formula's + for (let i = 1; i < formulaData.length; i++) { + await dashboard.grid.column.openEdit({ + title: "NC_MATH_0", + type: "Formula", + formula: formulaData[i].formula, + }); + await dashboard.grid.column.save({ isUpdated: true }); + if (formulaData[i].formula !== `NOW()`) { + await formulaResultVerify({ + title: "NC_MATH_0", + result: formulaData[i].result, + }); + } + } + + await dashboard.closeTab({ title: "City" }); + }); +}); diff --git a/scripts/playwright/tests/virtualColumnRelational.spec.ts b/scripts/playwright/tests/virtualColumnRelational.spec.ts index fdd277a5d6..5607ee1f6c 100644 --- a/scripts/playwright/tests/virtualColumnRelational.spec.ts +++ b/scripts/playwright/tests/virtualColumnRelational.spec.ts @@ -13,6 +13,7 @@ test.describe("Relational Columns", () => { test("Relational columns: HM, BT, MM", async () => { // close 'Team & Auth' tab + await dashboard.closeTab({ title: "Team & Auth" }); ///////////// Has many //