From cc0d9c728a0c423ec0fe4b3d1aaebcf6ea5474cb Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Sun, 19 May 2024 12:50:44 +0545 Subject: [PATCH 1/7] Refactor dRep tests title --- .../dRepRegistration.dRep.spec.ts | 6 +++--- .../dRepRegistration.loggedin.spec.ts | 15 +++++---------- .../3-drep-registration/dRepRegistration.spec.ts | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts index 82fb8ceb6..4e2c1930b 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts @@ -28,7 +28,7 @@ test.describe("Logged in DReps", () => { test.use({ storageState: ".auth/dRep01.json", wallet: dRep01Wallet }); // Skipped: No option to update metadata - test.skip("3H. Should be able to update metadata @slow", async ({ page }) => { + test.skip("3H. Should be able to update metadata", async ({ page }) => { page.getByTestId("change-metadata-button").click(); page.getByTestId("url-input").fill("https://google.com"); page.getByTestId("hash-input").fill(crypto.randomBytes(32).toString("hex")); @@ -37,7 +37,7 @@ test.describe("Logged in DReps", () => { }); test.describe("Temporary DReps", () => { - test("3G. Should show confirmation message with link to view transaction, when DRep registration txn is submitted @slow ", async ({ + test("3G. Should show confirmation message with link to view transaction, when DRep registration txn is submitted", async ({ page, browser, }, testInfo) => { @@ -67,7 +67,7 @@ test.describe("Temporary DReps", () => { ).toBeVisible(); }); - test("3I. Should verify retire as DRep @slow", async ({ + test("3I. Should verify retire as DRep", async ({ page, browser, }, testInfo) => { diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts index a263302a8..50f6903ca 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts @@ -9,18 +9,14 @@ test.use({ wallet: user01Wallet, }); -test("3B. Should access DRep registration page @fast @smoke", async ({ - page, -}) => { +test("3B. Should access DRep registration page", async ({ page }) => { await page.goto("/"); await page.getByTestId("register-button").click(); await expect(page.getByText("Become a DRep")).toBeVisible(); }); -test("3D.Verify DRep registration functionality with Wallet Connected State State @fast @smoke", async ({ - page, -}) => { +test("3D. Verify DRep registration form", async ({ page }) => { const dRepRegistrationPage = new DRepRegistrationPage(page); await dRepRegistrationPage.goto(); @@ -32,8 +28,7 @@ test("3D.Verify DRep registration functionality with Wallet Connected State Stat await expect(dRepRegistrationPage.continueBtn).toBeVisible(); }); -// Skipped: Because there are no fields for url and hash inputs. -test.skip("3E. Should reject invalid data and accept valid data @smoke @fast", async ({ +test("3E. Should reject invalid data in DRep form", async ({ page, }) => { const dRepRegistrationPage = new DRepRegistrationPage(page); @@ -44,13 +39,13 @@ test.skip("3E. Should reject invalid data and accept valid data @smoke @fast", a .multiple(() => faker.internet.displayName(), { count: 100 }) .forEach(async (dRepName) => { await dRepRegistrationPage.nameInput.fill(dRepName); - await dRepRegistrationPage.nameInput.clear({ force: true }); + await dRepRegistrationPage.nameInput.clear(); }); // Validity test }); -test("3F. Should create proper DRep registration request, when registered with data @slow", async ({ +test("3F. Should create proper DRep registration request, when registered with data", async ({ page, }) => { const urlToIntercept = "**/utxo?**"; diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.spec.ts index 9daf86969..3a8e72b6a 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.spec.ts @@ -1,6 +1,6 @@ -import { test, expect } from "@playwright/test"; +import { expect, test } from "@playwright/test"; -test("3C. Should open wallet connection popup, when Register as DRep from wallet unconnected state @smoke @fast", async ({ +test("3C. Should open wallet connection popup on DRep registration in disconnected state", async ({ page, }) => { await page.goto("/"); From 674dc25d153373b65febbc8010379d7458a00eeb Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Sun, 19 May 2024 15:27:28 +0545 Subject: [PATCH 2/7] test: DRep Form validity --- .../lib/pages/dRepRegistrationPage.ts | 40 ++++++++++++++++++- .../dRepRegistration.loggedin.spec.ts | 37 +++++++++-------- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts b/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts index fa089d0ef..58b208305 100644 --- a/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts @@ -1,10 +1,20 @@ import { downloadMetadata } from "@helpers/metadata"; -import { Download, Page } from "@playwright/test"; +import { Download, Page, expect } from "@playwright/test"; import metadataBucketService from "@services/metadataBucketService"; import { IDRepInfo } from "@types"; import environments from "lib/constants/environments"; import { withTxConfirmation } from "lib/transaction.decorator"; +const formErrors = { + dRepName: [ + "max-80-characters-error", + "this-field-is-required-error", + "nickname-can-not-contain-whitespaces-error", + ], + email: "invalid-email-address-error", + link: "invalid-url-error", +}; + export default class DRepRegistrationPage { readonly registerBtn = this.page.getByTestId("register-button"); readonly skipBtn = this.page.getByTestId("skip-button"); @@ -65,4 +75,32 @@ export default class DRepRegistrationPage { const download: Download = await this.page.waitForEvent("download"); return downloadMetadata(download); } + + async validateForm(name: string, email: string, bio: string, link: string) { + await this.nameInput.fill(name); + await this.emailInput.fill(email); + await this.bioInput.fill(bio); + await this.linkInput.fill(link); + + for (const err of formErrors.dRepName) { + await expect( + this.page.getByTestId(err), + `Invalid name: ${name}` + ).toBeHidden(); + } + + await expect( + this.page.getByTestId(formErrors.email), + `Invalid email: ${email}` + ).toBeHidden(); + + expect( + await this.bioInput.textContent(), + "Bio exceeded 500 characters" + ).toEqual(bio); + + await expect(this.page.getByTestId(formErrors.link)).toBeHidden(); + + await expect(this.continueBtn).toBeEnabled(); + } } diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts index 50f6903ca..8c7546a66 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts @@ -28,33 +28,38 @@ test("3D. Verify DRep registration form", async ({ page }) => { await expect(dRepRegistrationPage.continueBtn).toBeVisible(); }); -test("3E. Should reject invalid data in DRep form", async ({ - page, -}) => { +test("3E. Should accept valid data in DRep form", async ({ page }) => { const dRepRegistrationPage = new DRepRegistrationPage(page); await dRepRegistrationPage.goto(); - // Invalidity test - faker.helpers - .multiple(() => faker.internet.displayName(), { count: 100 }) - .forEach(async (dRepName) => { - await dRepRegistrationPage.nameInput.fill(dRepName); - await dRepRegistrationPage.nameInput.clear(); - }); + for (let i = 0; i < 100; i++) { + await dRepRegistrationPage.validateForm( + faker.internet.displayName(), + faker.internet.email(), + faker.lorem.paragraph(), + faker.internet.url() + ); + } - // Validity test + for (let i = 0; i < 6; i++) { + await expect(dRepRegistrationPage.addLinkBtn).toBeVisible(); + await dRepRegistrationPage.addLinkBtn.click(); + } + + await expect(dRepRegistrationPage.addLinkBtn).toBeHidden(); }); test("3F. Should create proper DRep registration request, when registered with data", async ({ page, }) => { - const urlToIntercept = "**/utxo?**"; - const dRepRegistrationPage = new DRepRegistrationPage(page); await dRepRegistrationPage.goto(); - await dRepRegistrationPage.register({ name: "Test_dRep" }); + await dRepRegistrationPage.register({ name: "Test" }).catch((err) => { + // Fails because real tx is not submitted + }); - const response = await page.waitForResponse(urlToIntercept); - expect(response.body.length).toEqual(0); + await expect( + page.getByTestId("registration-transaction-error-modal") + ).toBeVisible(); }); From 2650db5ea7e63ecacb90caebf142bf7e96789198 Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Sun, 19 May 2024 15:30:46 +0545 Subject: [PATCH 3/7] Remove tags from tests --- .../proposalVisibility.loggedin.spec.ts | 10 +++++----- .../4-proposal-visibility/proposalVisibility.spec.ts | 4 ++-- .../proposalFunctionality.dRep.spec.ts | 8 ++++---- .../6-miscellaneous/miscellaneous.loggedin.spec.ts | 6 ++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts index e59f2e588..16622803d 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts @@ -24,7 +24,7 @@ enum SortOption { test.use({ storageState: ".auth/user01.json", wallet: user01Wallet }); -test("4A.1: Should access Governance Actions page with connecting wallet @smoke @fast", async ({ +test("4A.1: Should access Governance Actions page with connecting wallet", async ({ page, }) => { await page.goto("/"); @@ -36,7 +36,7 @@ test("4A.1: Should access Governance Actions page with connecting wallet @smoke await expect(page.getByText(/Governance Actions/i)).toHaveCount(2); }); -test("4B.1: Should restrict voting for users who are not registered as DReps (with wallet connected) @fast", async ({ +test("4B.1: Should restrict voting for users who are not registered as DReps (with wallet connected)", async ({ page, }) => { const govActionsPage = new GovernanceActionsPage(page); @@ -46,7 +46,7 @@ test("4B.1: Should restrict voting for users who are not registered as DReps (wi await expect(govActionDetailsPage.voteBtn).not.toBeVisible(); }); -test("4C.1: Should filter Governance Action Type on governance actions page @slow", async ({ +test("4C.1: Should filter Governance Action Type on governance actions page", async ({ page, }) => { test.slow(); @@ -73,7 +73,7 @@ test("4C.1: Should filter Governance Action Type on governance actions page @slo } }); -test("4C.2: Should sort Governance Action Type on governance actions page @slow", async ({ +test("4C.2: Should sort Governance Action Type on governance actions page", async ({ page, }) => { test.slow(); @@ -102,7 +102,7 @@ test("4C.2: Should sort Governance Action Type on governance actions page @slow" ); }); -test("4D: Should filter and sort Governance Action Type on governance actions page @slow", async ({ +test("4D: Should filter and sort Governance Action Type on governance actions page", async ({ page, }) => { test.slow(); diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.spec.ts index 19b5e5364..5a5cf5f01 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.spec.ts @@ -1,7 +1,7 @@ import GovernanceActionsPage from "@pages/governanceActionsPage"; import { expect, test } from "@playwright/test"; -test("4A.2: Should access Governance Actions page without connecting wallet @smoke @fast", async ({ +test("4A.2: Should access Governance Actions page without connecting wallet", async ({ page, }) => { await page.goto("/"); @@ -10,7 +10,7 @@ test("4A.2: Should access Governance Actions page without connecting wallet @smo await expect(page.getByText(/Governance actions/i)).toHaveCount(2); }); -test("4B.2: Should restrict voting for users who are not registered as DReps (without wallet connected) @flaky @fast", async ({ +test("4B.2: Should restrict voting for users who are not registered as DReps (without wallet connected)", async ({ page, }) => { const govActionsPage = new GovernanceActionsPage(page); diff --git a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts index cb9a458e5..ce023031b 100644 --- a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts @@ -23,7 +23,7 @@ test.describe("Proposal checks", () => { govActionDetailsPage = await govActionsPage.viewFirstProposal(); }); - test("5A. Should show relevant details about governance action as DRep @slow", async () => { + test("5A. Should show relevant details about governance action as DRep", async () => { await expect(govActionDetailsPage.governanceActionType).toBeVisible(); await expect(govActionDetailsPage.submittedDate).toBeVisible(); await expect(govActionDetailsPage.expiryDate).toBeVisible(); @@ -37,11 +37,11 @@ test.describe("Proposal checks", () => { await expect(govActionDetailsPage.abstainRadio).toBeVisible(); }); - test("5B. Should view Vote button on governance action item on registered as DRep @slow", async () => { + test("5B. Should view Vote button on governance action item on registered as DRep", async () => { await expect(govActionDetailsPage.voteBtn).toBeVisible(); }); - test("5C. Should show required field in proposal voting on registered as DRep @slow", async () => { + test("5C. Should show required field in proposal voting on registered as DRep", async () => { await expect(govActionDetailsPage.voteBtn).toBeVisible(); await expect(govActionDetailsPage.yesVoteRadio).toBeVisible(); await expect(govActionDetailsPage.noVoteRadio).toBeVisible(); @@ -57,7 +57,7 @@ test.describe("Proposal checks", () => { }); // Skipped: No url/hash input to validate - test.skip("5D. Should validate proposal voting @slow", async () => { + test.skip("5D. Should validate proposal voting", async () => { // const invalidURLs = ["testdotcom", "https://testdotcom", "https://test.c"]; // invalidURLs.forEach(async (url) => { // govActionDetailsPage.urlInput.fill(url); diff --git a/tests/govtool-frontend/playwright/tests/6-miscellaneous/miscellaneous.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/6-miscellaneous/miscellaneous.loggedin.spec.ts index 0cfd4cc9c..09ae840ff 100644 --- a/tests/govtool-frontend/playwright/tests/6-miscellaneous/miscellaneous.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/6-miscellaneous/miscellaneous.loggedin.spec.ts @@ -7,9 +7,7 @@ import { expect } from "@playwright/test"; test.use({ storageState: ".auth/user01.json", wallet: user01Wallet }); // Skipped: No dRepId to validate -test.skip("6B. Provides error for invalid format @fast @smoke", async ({ - page, -}) => { +test.skip("6B. Provides error for invalid format", async ({ page }) => { // invalid dRep delegation const delegationPage = new DelegationPage(page); await delegationPage.goto(); @@ -27,7 +25,7 @@ test.skip("6B. Provides error for invalid format @fast @smoke", async ({ // await expect(dRepRegistrationPage.hashInputError).toBeVisible(); }); -test("6D: Proper label and recognition of the testnet network @fast @smoke", async ({ +test("6D: Proper label and recognition of the testnet network", async ({ page, }) => { await page.goto("/"); From 10c6f7668a0415ed330a8cb318efaf8512aa912f Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Sun, 19 May 2024 15:47:58 +0545 Subject: [PATCH 4/7] fix (sorting): Add delay to address slow loading of proposals --- .../playwright/lib/pages/governanceActionsPage.ts | 2 ++ .../4-proposal-visibility/proposalVisibility.loggedin.spec.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/govtool-frontend/playwright/lib/pages/governanceActionsPage.ts b/tests/govtool-frontend/playwright/lib/pages/governanceActionsPage.ts index 94429fc40..312ecc0ba 100644 --- a/tests/govtool-frontend/playwright/lib/pages/governanceActionsPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/governanceActionsPage.ts @@ -64,6 +64,7 @@ export default class GovernanceActionsPage { } async getAllProposals() { + await this.page.waitForTimeout(2000); return this.page.locator('[data-test-id$="-card"]').all(); } @@ -118,6 +119,7 @@ export default class GovernanceActionsPage { } }); + await this.page.waitForTimeout(2000); // Frontend validation const proposalCards = await Promise.all( filterKeys.map((key) => diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts index 16622803d..5504673b0 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts @@ -130,7 +130,6 @@ test("4H. Should verify none of the displayed governance actions have expired", const govActionsPage = new GovernanceActionsPage(page); await govActionsPage.goto(); - await page.waitForTimeout(4000); // BUG: Delay to load governance actions const proposalCards = await govActionsPage.getAllProposals(); for (const proposalCard of proposalCards) { From c513d2c4e48954758da6647f7f6606998c1c78d4 Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Sun, 19 May 2024 16:03:12 +0545 Subject: [PATCH 5/7] fix: Conflict in open-drawer test-id --- .../playwright/lib/helpers/mobile.ts | 4 ---- .../playwright/lib/pages/loginPage.ts | 15 ++++----------- .../tests/2-delegation/delegation.drep.spec.ts | 17 +++++++++++++++++ .../tests/2-delegation/delegation.spec.ts | 13 ------------- .../proposalVisibility.loggedin.spec.ts | 4 ++-- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/tests/govtool-frontend/playwright/lib/helpers/mobile.ts b/tests/govtool-frontend/playwright/lib/helpers/mobile.ts index b0c0329ca..7552e09e9 100644 --- a/tests/govtool-frontend/playwright/lib/helpers/mobile.ts +++ b/tests/govtool-frontend/playwright/lib/helpers/mobile.ts @@ -8,9 +8,5 @@ export function isMobile(page: Page) { } export async function openDrawer(page: Page) { - await page.getByRole("img", { name: "drawer-icon" }).click(); //BUG testId -} - -export async function openDrawerLoggedIn(page: Page) { await page.getByTestId("open-drawer-button").click(); } diff --git a/tests/govtool-frontend/playwright/lib/pages/loginPage.ts b/tests/govtool-frontend/playwright/lib/pages/loginPage.ts index 964b14ff8..6ebbc3dba 100644 --- a/tests/govtool-frontend/playwright/lib/pages/loginPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/loginPage.ts @@ -2,7 +2,7 @@ import { CIP30Instance, Cip95Instance, } from "@cardanoapi/cardano-test-wallet/types"; -import { isMobile, openDrawer, openDrawerLoggedIn } from "@helpers/mobile"; +import { isMobile, openDrawer } from "@helpers/mobile"; import { Page, expect } from "@playwright/test"; export default class LoginPage { @@ -23,14 +23,7 @@ export default class LoginPage { async login() { await this.goto(); - if (isMobile(this.page)) { - await openDrawer(this.page); - await this.page - .getByRole("button", { name: "Connect your wallet" }) // BUG testId should be same as connect-wallet-button - .click(); - } else { - await this.connectWalletBtn.click(); - } + await this.connectWalletBtn.click(); await this.demosWalletBtn.click({ force: true }); await this.acceptSanchoNetInfoBtn.click({ force: true }); @@ -62,14 +55,14 @@ export default class LoginPage { async logout() { if (isMobile(this.page)) { - await openDrawerLoggedIn(this.page); + await openDrawer(this.page); } await this.disconnectWalletBtn.click(); } async isLoggedIn() { if (isMobile(this.page)) { - await openDrawerLoggedIn(this.page); + await openDrawer(this.page); } await expect(this.disconnectWalletBtn).toBeVisible(); } diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.drep.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.drep.spec.ts index 2f9088c58..74b21fe22 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.drep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.drep.spec.ts @@ -4,6 +4,7 @@ import { createTempDRepAuth } from "@datafactory/createAuth"; import { faker } from "@faker-js/faker"; import { test } from "@fixtures/walletExtension"; import { ShelleyWallet } from "@helpers/crypto"; +import { isMobile, openDrawer } from "@helpers/mobile"; import { createNewPageWithWallet } from "@helpers/page"; import extractDRepFromWallet from "@helpers/shellyWallet"; import { transferAdaForWallet } from "@helpers/transaction"; @@ -11,6 +12,22 @@ import DRepDirectoryPage from "@pages/dRepDirectoryPage"; import DRepRegistrationPage from "@pages/dRepRegistrationPage"; import { expect } from "@playwright/test"; +test("2C. Should open wallet connection popup on delegate in disconnected state", async ({ + page, +}) => { + await page.goto("/"); + if (isMobile(page)) { + openDrawer(page); + } + + await page.getByTestId("view-drep-directory-button").click(); + await page + .locator('[data-testid$="-connect-to-delegate-button"]') + .first() + .click(); + await expect(page.getByTestId("connect-your-wallet-modal")).toBeVisible(); +}); + test("2L. Should copy DRepId", async ({ page, context }) => { await context.grantPermissions(["clipboard-read", "clipboard-write"]); diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts index 33de50626..daa7bade1 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.spec.ts @@ -3,19 +3,6 @@ import DRepDirectoryPage from "@pages/dRepDirectoryPage"; import { expect, test } from "@playwright/test"; import { DRepStatus } from "@types"; -test("2C. Should open wallet connection popup on delegate in disconnected state", async ({ - page, -}) => { - await page.goto("/"); - - await page.getByTestId("view-drep-directory-button").click(); - await page - .locator('[data-testid$="-connect-to-delegate-button"]') - .first() - .click(); - await expect(page.getByTestId("connect-your-wallet-modal")).toBeVisible(); -}); - test("2J. Should search by DRep id", async ({ page }) => { const dRepDirectory = new DRepDirectoryPage(page); await dRepDirectory.goto(); diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts index 5504673b0..646dd688b 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.loggedin.spec.ts @@ -1,7 +1,7 @@ import { user01Wallet } from "@constants/staticWallets"; import { test } from "@fixtures/walletExtension"; import extractExpiryDateFromText from "@helpers/extractExpiryDateFromText"; -import { isMobile, openDrawerLoggedIn } from "@helpers/mobile"; +import { isMobile, openDrawer } from "@helpers/mobile"; import removeAllSpaces from "@helpers/removeAllSpaces"; import GovernanceActionsPage from "@pages/governanceActionsPage"; import { expect } from "@playwright/test"; @@ -29,7 +29,7 @@ test("4A.1: Should access Governance Actions page with connecting wallet", async }) => { await page.goto("/"); if (isMobile(page)) { - await openDrawerLoggedIn(page); + await openDrawer(page); } await page.getByTestId("governance-actions-link").click(); From 4badeaa9d8ae4fb017ea57ad1f969c756ed68ccd Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Mon, 20 May 2024 10:49:44 +0545 Subject: [PATCH 6/7] test: DRep form invalidity --- .../lib/pages/dRepRegistrationPage.ts | 40 ++++++++++++++++ .../dRepRegistration.loggedin.spec.ts | 47 +++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts b/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts index 58b208305..8eee69979 100644 --- a/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/dRepRegistrationPage.ts @@ -103,4 +103,44 @@ export default class DRepRegistrationPage { await expect(this.continueBtn).toBeEnabled(); } + + async inValidateForm(name: string, email: string, bio: string, link: string) { + await this.nameInput.fill(name); + await this.emailInput.fill(email); + await this.bioInput.fill(bio); + await this.linkInput.fill(link); + + function convertTestIdToText(testId: string) { + let text = testId.replace("-error", ""); + text = text.replace(/-/g, " "); + return text[0].toUpperCase() + text.substring(1); + } + + const regexPattern = new RegExp( + formErrors.dRepName.map(convertTestIdToText).join("|") + ); + + const nameErrors = await this.page + .locator('[data-testid$="-error"]') + .filter({ + hasText: regexPattern, + }) + .all(); + + expect(nameErrors.length, `Valid name: ${name}`).toEqual(1); + + await expect( + this.page.getByTestId(formErrors.email), + `Valid email: ${email}` + ).toBeVisible(); + + expect( + await this.bioInput.textContent(), + "Bio less than 500 characters" + ).not.toEqual(bio); + + await expect(this.page.getByTestId(formErrors.link)).toBeVisible(); + + await expect(this.continueBtn).toBeDisabled(); + } } diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts index 8c7546a66..f91ca65cf 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.loggedin.spec.ts @@ -49,6 +49,53 @@ test("3E. Should accept valid data in DRep form", async ({ page }) => { await expect(dRepRegistrationPage.addLinkBtn).toBeHidden(); }); +test("3L. Should reject invalid data in DRep form", async ({ page }) => { + const dRepRegistrationPage = new DRepRegistrationPage(page); + await dRepRegistrationPage.goto(); + + function generateInvalidEmail() { + const choice = faker.number.int({ min: 1, max: 3 }); + + if (choice === 1) { + return faker.lorem.word() + faker.number + "@invalid.com"; + } else if (choice == 2) { + return faker.lorem.word() + "@"; + } + return faker.lorem.word() + "@gmail_com"; + } + function generateInvalidUrl() { + const choice = faker.number.int({ min: 1, max: 3 }); + + if (choice === 1) { + return faker.internet.url().replace("https://", "http://"); + } else if (choice === 2) { + return faker.lorem.word() + ".invalid"; + } + return faker.lorem.word() + ".@com"; + } + function generateInvalidName() { + const choice = faker.number.int({ min: 1, max: 3 }); + if (choice === 1) { + // space invalid + return faker.lorem.word() + " " + faker.lorem.word(); + } else if (choice === 2) { + // maximum 80 words invalid + return faker.lorem.paragraphs().replace(/\s+/g, ""); + } + // empty invalid + return " "; + } + + for (let i = 0; i < 100; i++) { + await dRepRegistrationPage.inValidateForm( + generateInvalidName(), + generateInvalidEmail(), + faker.lorem.paragraph(40), + generateInvalidUrl() + ); + } +}); + test("3F. Should create proper DRep registration request, when registered with data", async ({ page, }) => { From 15bef45021cd7feb93f41dcb7d5b2033c100607e Mon Sep 17 00:00:00 2001 From: Nabin Kawan Date: Mon, 20 May 2024 11:01:56 +0545 Subject: [PATCH 7/7] Refactor transactions & Add missing test-ids --- .../playwright/lib/constants/environments.ts | 3 +- .../playwright/lib/helpers/page.ts | 2 +- .../playwright/lib/helpers/transaction.ts | 8 ++++ .../lib/pages/governanceActionDetailsPage.ts | 2 +- .../2-delegation/delegation.loggedin.spec.ts | 4 +- ...delegationFunctionality.delegation.spec.ts | 4 +- .../dRepRegistration.dRep.spec.ts | 41 ++++++------------- .../proposalVisibility.dRep.spec.ts | 20 +++------ .../proposalFunctionality.dRep.spec.ts | 35 +++++----------- 9 files changed, 44 insertions(+), 75 deletions(-) diff --git a/tests/govtool-frontend/playwright/lib/constants/environments.ts b/tests/govtool-frontend/playwright/lib/constants/environments.ts index da17f1974..85aa51f79 100644 --- a/tests/govtool-frontend/playwright/lib/constants/environments.ts +++ b/tests/govtool-frontend/playwright/lib/constants/environments.ts @@ -10,8 +10,7 @@ const environments = { apiKey: process.env.FAUCET_API_KEY || "", }, kuber: { - apiUrl: - process.env.KUBER_API_URL || "https://sanchonet.kuber.cardanoapi.io", + apiUrl: process.env.KUBER_API_URL || "https://kuber-govtool.cardanoapi.io", apiKey: process.env.KUBER_API_KEY || "", }, txTimeOut: parseInt(process.env.TX_TIMEOUT) || 240000, diff --git a/tests/govtool-frontend/playwright/lib/helpers/page.ts b/tests/govtool-frontend/playwright/lib/helpers/page.ts index 7a20d6d80..d3aca4d4b 100644 --- a/tests/govtool-frontend/playwright/lib/helpers/page.ts +++ b/tests/govtool-frontend/playwright/lib/helpers/page.ts @@ -1,6 +1,6 @@ import { importWallet } from "@fixtures/importWallet"; import loadDemosExtension from "@fixtures/loadExtension"; -import { Browser, Page } from "@playwright/test"; +import { Browser, Page, expect } from "@playwright/test"; import { ShelleyWallet } from "./crypto"; interface BrowserConfig { diff --git a/tests/govtool-frontend/playwright/lib/helpers/transaction.ts b/tests/govtool-frontend/playwright/lib/helpers/transaction.ts index 4f24984e7..009f0766a 100644 --- a/tests/govtool-frontend/playwright/lib/helpers/transaction.ts +++ b/tests/govtool-frontend/playwright/lib/helpers/transaction.ts @@ -105,3 +105,11 @@ export async function transferAdaForWallet( ); await pollTransaction(txId, lockInfo); } + +export async function registerDRepForWallet(wallet: ShelleyWallet) { + const registrationRes = await kuberService.dRepRegistration( + convertBufferToHex(wallet.stakeKey.private), + convertBufferToHex(wallet.stakeKey.pkh) + ); + await pollTransaction(registrationRes.txId, registrationRes.lockInfo); +} diff --git a/tests/govtool-frontend/playwright/lib/pages/governanceActionDetailsPage.ts b/tests/govtool-frontend/playwright/lib/pages/governanceActionDetailsPage.ts index c3f3498c1..8b079d8ef 100644 --- a/tests/govtool-frontend/playwright/lib/pages/governanceActionDetailsPage.ts +++ b/tests/govtool-frontend/playwright/lib/pages/governanceActionDetailsPage.ts @@ -31,7 +31,7 @@ export default class GovernanceActionDetailsPage { readonly voteSuccessModal = this.page.getByTestId("alert-success"); readonly externalLinkModal = this.page.getByTestId("external-link-modal"); - readonly contextInput = this.page.getByPlaceholder("Provide context"); // BUG testId + readonly contextInput = this.page.getByTestId("provide-context-input"); readonly cancelModalBtn = this.page.getByTestId("cancel-modal-button"); constructor(private readonly page: Page) {} diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.loggedin.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.loggedin.spec.ts index 2f04ab093..a76dcd622 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegation.loggedin.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegation.loggedin.spec.ts @@ -38,7 +38,9 @@ test("2I. Should check validity of DRep Id", async ({ page }) => { await expect(dRepDirectory.getDRepCard(invalidDRepId)).not.toBeVisible(); }); -test("2D. Should show delegation options in connected state", async ({ page }) => { +test("2D. Should show delegation options in connected state", async ({ + page, +}) => { const dRepDirectoryPage = new DRepDirectoryPage(page); await dRepDirectoryPage.goto(); diff --git a/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts b/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts index 98f26652f..aea64a817 100644 --- a/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts +++ b/tests/govtool-frontend/playwright/tests/2-delegation/delegationFunctionality.delegation.spec.ts @@ -1,5 +1,5 @@ import environments from "@constants/environments"; -import { adaHolder01Wallet } from "@constants/staticWallets"; +import { adaHolder01Wallet, dRep01Wallet } from "@constants/staticWallets"; import { createTempDRepAuth } from "@datafactory/createAuth"; import { test } from "@fixtures/walletExtension"; import { ShelleyWallet } from "@helpers/crypto"; @@ -26,7 +26,7 @@ test.describe("Delegate to others", () => { }, testInfo) => { test.setTimeout(testInfo.timeout + 2 * environments.txTimeOut); - const dRepId = "drep1qzw234c0ly8csamxf8hrhfahvzwpllh2ckuzzvl38d22wwxxquu"; + const dRepId = dRep01Wallet.dRepId; const dRepDirectoryPage = new DRepDirectoryPage(page); await dRepDirectoryPage.goto(); diff --git a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts index 4e2c1930b..8a2a75ee8 100644 --- a/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts @@ -3,14 +3,16 @@ import { dRep01Wallet } from "@constants/staticWallets"; import { createTempDRepAuth } from "@datafactory/createAuth"; import { faker } from "@faker-js/faker"; import { test } from "@fixtures/walletExtension"; -import convertBufferToHex from "@helpers/convertBufferToHex"; import { ShelleyWallet } from "@helpers/crypto"; import { createNewPageWithWallet } from "@helpers/page"; -import { pollTransaction, waitForTxConfirmation } from "@helpers/transaction"; +import { + registerDRepForWallet, + transferAdaForWallet, + waitForTxConfirmation, +} from "@helpers/transaction"; import DRepRegistrationPage from "@pages/dRepRegistrationPage"; import GovernanceActionsPage from "@pages/governanceActionsPage"; import { expect } from "@playwright/test"; -import kuberService from "@services/kuberService"; import * as crypto from "crypto"; test.describe("Logged in DReps", () => { @@ -44,11 +46,7 @@ test.describe("Temporary DReps", () => { test.setTimeout(testInfo.timeout + environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const res = await kuberService.transferADA( - [wallet.addressBech32(environments.networkId)], - 600 - ); - await pollTransaction(res.txId, res.lockInfo); + await transferAdaForWallet(wallet, 600); const tempDRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { @@ -74,11 +72,7 @@ test.describe("Temporary DReps", () => { test.setTimeout(testInfo.timeout + environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const registrationRes = await kuberService.dRepRegistration( - convertBufferToHex(wallet.stakeKey.private), - convertBufferToHex(wallet.stakeKey.pkh) - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); + await registerDRepForWallet(wallet); const tempDRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { @@ -89,7 +83,7 @@ test.describe("Temporary DReps", () => { await dRepPage.goto("/"); await dRepPage.getByTestId("retire-button").click(); - await dRepPage.getByTestId("retire-button").click(); // BUG testId -> continue-retire-button + await dRepPage.getByTestId("continue-retirement-button").click(); await expect( dRepPage.getByTestId("retirement-transaction-error-modal") @@ -103,16 +97,9 @@ test.describe("Temporary DReps", () => { test.setTimeout(testInfo.timeout + 3 * environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const registrationRes = await kuberService.dRepRegistration( - convertBufferToHex(wallet.stakeKey.private), - convertBufferToHex(wallet.stakeKey.pkh) - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); + await registerDRepForWallet(wallet); - const res = await kuberService.transferADA([ - wallet.addressBech32(environments.networkId), - ]); - await pollTransaction(res.txId, res.lockInfo); + await transferAdaForWallet(wallet); const dRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { @@ -123,7 +110,7 @@ test.describe("Temporary DReps", () => { await dRepPage.goto("/"); await dRepPage.getByTestId("retire-button").click(); - await dRepPage.getByTestId("retire-button").click(); // BUG: testId -> continue-retire-button + await dRepPage.getByTestId("continue-retirement-button").click(); await expect( dRepPage.getByTestId("retirement-transaction-submitted-modal") ).toBeVisible(); @@ -145,11 +132,7 @@ test.describe("Temporary DReps", () => { const wallet = await ShelleyWallet.generate(); - const res = await kuberService.transferADA( - [wallet.addressBech32(environments.networkId)], - 600 - ); - await pollTransaction(res.txId, res.lockInfo); + await transferAdaForWallet(wallet, 600); const dRepAuth = await createTempDRepAuth(page, wallet); const dRepPage = await createNewPageWithWallet(browser, { diff --git a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.dRep.spec.ts index d32ec8500..a0f5140af 100644 --- a/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.dRep.spec.ts @@ -4,13 +4,14 @@ import { createTempDRepAuth } from "@datafactory/createAuth"; import { faker } from "@faker-js/faker"; import { test } from "@fixtures/walletExtension"; import { lovelaceToAda } from "@helpers/cardano"; -import convertBufferToHex from "@helpers/convertBufferToHex"; import { ShelleyWallet } from "@helpers/crypto"; import { createNewPageWithWallet } from "@helpers/page"; -import { pollTransaction } from "@helpers/transaction"; +import { + registerDRepForWallet, + transferAdaForWallet, +} from "@helpers/transaction"; import GovernanceActionsPage from "@pages/governanceActionsPage"; import { Page, expect } from "@playwright/test"; -import kuberService from "@services/kuberService"; import { FilterOption, IProposal } from "@types"; test.describe("Logged in DRep", () => { @@ -52,17 +53,8 @@ test.describe("Temporary DReps", async () => { test.setTimeout(testInfo.timeout + 2 * environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const registrationRes = await kuberService.dRepRegistration( - convertBufferToHex(wallet.stakeKey.private), - convertBufferToHex(wallet.stakeKey.pkh) - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); - - const res = await kuberService.transferADA( - [wallet.addressBech32(environments.networkId)], - 40 - ); - await pollTransaction(res.txId, registrationRes.lockInfo); + await registerDRepForWallet(wallet); + await transferAdaForWallet(wallet, 40); const tempDRepAuth = await createTempDRepAuth(page, wallet); diff --git a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts index ce023031b..cf3c7400d 100644 --- a/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts +++ b/tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts @@ -2,10 +2,13 @@ import environments from "@constants/environments"; import { dRep01Wallet } from "@constants/staticWallets"; import { createTempDRepAuth } from "@datafactory/createAuth"; import { test } from "@fixtures/walletExtension"; -import convertBufferToHex from "@helpers/convertBufferToHex"; import { ShelleyWallet } from "@helpers/crypto"; import { createNewPageWithWallet } from "@helpers/page"; -import { pollTransaction, waitForTxConfirmation } from "@helpers/transaction"; +import { + registerDRepForWallet, + transferAdaForWallet, + waitForTxConfirmation, +} from "@helpers/transaction"; import GovernanceActionDetailsPage from "@pages/governanceActionDetailsPage"; import GovernanceActionsPage from "@pages/governanceActionsPage"; import { expect } from "@playwright/test"; @@ -110,17 +113,8 @@ test.describe("Perform voting", () => { test.setTimeout(testInfo.timeout + 2 * environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const registrationRes = await kuberService.dRepRegistration( - convertBufferToHex(wallet.stakeKey.private), - convertBufferToHex(wallet.stakeKey.pkh) - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); - - const res = await kuberService.transferADA( - [wallet.addressBech32(environments.networkId)], - 40 - ); - await pollTransaction(res.txId, registrationRes.lockInfo); + await registerDRepForWallet(wallet); + await transferAdaForWallet(wallet, 40); const tempDRepAuth = await createTempDRepAuth(page, wallet); @@ -191,17 +185,8 @@ test.describe("Check voting power", () => { test.setTimeout(testInfo.timeout + 2 * environments.txTimeOut); const wallet = await ShelleyWallet.generate(); - const registrationRes = await kuberService.dRepRegistration( - convertBufferToHex(wallet.stakeKey.private), - convertBufferToHex(wallet.stakeKey.pkh) - ); - await pollTransaction(registrationRes.txId, registrationRes.lockInfo); - - const res = await kuberService.transferADA( - [wallet.addressBech32(environments.networkId)], - 40 - ); - await pollTransaction(res.txId, registrationRes.lockInfo); + await registerDRepForWallet(wallet); + await transferAdaForWallet(wallet, 40); const tempDRepAuth = await createTempDRepAuth(page, wallet); @@ -213,7 +198,7 @@ test.describe("Check voting power", () => { await dRepPage.goto("/"); await dRepPage.getByTestId("retire-button").click(); - await dRepPage.getByTestId("retire-button").click(); // BUG: testId -> continue-retire-button + await dRepPage.getByTestId("continue-retirement-button").click(); await expect( dRepPage.getByTestId("retirement-transaction-submitted-modal") ).toBeVisible();