Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/tests to use cardano test plans #1165

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions tests/govtool-frontend/playwright/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { loadAmountFromFaucet } from "@services/faucetService";
import kuberService from "@services/kuberService";
import walletManager from "lib/walletManager";

const REGISTER_DREP_WALLETS = 9;
const DREP_WALLETS = 9;
mesudip marked this conversation as resolved.
Show resolved Hide resolved

async function generateWallets(num: number) {
return await Promise.all(
Array.from({ length: num }, () =>
Expand All @@ -14,24 +17,23 @@ async function generateWallets(num: number) {
}

async function globalSetup() {
const registeredDRepWallets = await generateWallets(9);
const registerDRepWallets = await generateWallets(9);
const dRepWallets = await generateWallets(DREP_WALLETS);
const registerDRepWallets = await generateWallets(REGISTER_DREP_WALLETS);

// faucet setup
const res = await loadAmountFromFaucet(faucetWallet.address);
await pollTransaction(res.txid);

// initialize wallets
const initializeRes = await kuberService.initializeWallets([
...registeredDRepWallets,
...dRepWallets,
...registerDRepWallets,
]);
await pollTransaction(initializeRes.txId, initializeRes.lockInfo);

// register dRep
const registrationRes = await kuberService.multipleDRepRegistration(
registeredDRepWallets
);
const registrationRes =
await kuberService.multipleDRepRegistration(dRepWallets);
await pollTransaction(registrationRes.txId, registrationRes.lockInfo);

// transfer 600 ADA for dRep registration
Expand All @@ -42,7 +44,7 @@ async function globalSetup() {
await pollTransaction(transferRes.txId, transferRes.lockInfo);

// save to file
await walletManager.writeWallets(registeredDRepWallets, "registeredDRep");
await walletManager.writeWallets(dRepWallets, "registeredDRep");
await walletManager.writeWallets(registerDRepWallets, "registerDRep");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class DRepDirectoryPage {
}
}
getDRepCard(dRepId: string) {
return this.page.getByRole("list").getByTestId(`${dRepId}-copy-id-button`);
return this.page.getByTestId(`${dRepId}-drep-card`);
}

async getAllListedDRepIds() {
Expand All @@ -130,4 +130,13 @@ export default class DRepDirectoryPage {
.locator('[data-testid$="-copy-id-button"]')
.all();
}

async getAllListedDReps() {
await this.page.waitForTimeout(2_000);

return await this.page
.getByRole("list")
.locator('[data-testid$="-drep-card"]')
.all();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class GovernanceActionsPage {
readonly filterBtn = this.page.getByTestId("filters-button");
readonly sortBtn = this.page.getByTestId("sort-button");
readonly votedTab = this.page.getByTestId("voted-tab");
readonly searchInput = this.page.getByTestId("search-input");

constructor(private readonly page: Page) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ test("2C. Should open wallet connection popup on delegate in disconnected state"
await expect(page.getByTestId("connect-your-wallet-modal")).toBeVisible();
});

test("2L. Should copy DRepId", async ({ page, context }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"]);

const dRepDirectory = new DRepDirectoryPage(page);
await dRepDirectory.goto();

await dRepDirectory.searchInput.fill(dRep01Wallet.dRepId);
await page.getByTestId(`${dRep01Wallet.dRepId}-copy-id-button`).click();
await expect(page.getByText("Copied to clipboard")).toBeVisible();

const copiedText = await page.evaluate(() => navigator.clipboard.readText());
expect(copiedText).toEqual(dRep01Wallet.dRepId);
});

test("2N. Should show DRep information on details page", async ({
page,
browser,
Expand Down Expand Up @@ -90,7 +76,9 @@ test("2N. Should show DRep information on details page", async ({
await dRepPage.getByTestId(`${wallet.dRepId}-view-details-button`).click();

// Verification
await expect(dRepPage.getByTestId("copy-drep-id-button")).toHaveText(wallet.dRepId);
await expect(dRepPage.getByTestId("copy-drep-id-button")).toHaveText(
wallet.dRepId
);
await expect(dRepPage.getByText("Active", { exact: true })).toBeVisible();
await expect(dRepPage.locator("dl").getByText("₳ 0")).toBeVisible();
await expect(dRepPage.getByText(email, { exact: true })).toBeVisible();
Expand Down Expand Up @@ -119,13 +107,18 @@ test("2P. Should enable sharing of DRep details", async ({ page, context }) => {
test("2Q. Should include DRep status and voting power on the DRep card", async ({
page,
}) => {
test.skip(); // Cannot access dRep card

const dRepDirectory = new DRepDirectoryPage(page);
await dRepDirectory.goto();

await dRepDirectory.searchInput.fill(dRep01Wallet.dRepId);
const dRepCard = dRepDirectory.getDRepCard(dRep01Wallet.dRepId);
await expect(dRepCard).toHaveText("20");

await expect(
dRepCard.getByTestId(`${dRep01Wallet.dRepId}-voting-power`)
).toBeVisible();
await expect(
dRepCard.getByTestId(`${dRep01Wallet.dRepId}-Active-pill`)
).toBeVisible();
});

test.describe("Insufficient funds", () => {
Expand Down Expand Up @@ -173,3 +166,29 @@ test("2J. Should search by DRep id", async ({ page }) => {
dRep01Wallet.dRepId
);
});

test("2D. Should show delegation options in connected state", async ({
page,
}) => {
const dRepDirectoryPage = new DRepDirectoryPage(page);
await dRepDirectoryPage.goto();

// Verifying automatic delegation options
await dRepDirectoryPage.automaticDelegationOptionsDropdown.click();
await expect(dRepDirectoryPage.abstainDelegationCard).toBeVisible();
await expect(dRepDirectoryPage.signalNoConfidenceCard).toBeVisible();

expect(await dRepDirectoryPage.delegateBtns.count()).toBeGreaterThanOrEqual(
2
);
});

test("2M. Should access dRep directory page on disconnected state", async ({
page,
}) => {
const dRepDirectoryPage = new DRepDirectoryPage(page);
await dRepDirectoryPage.goto();

const dRepCards = await dRepDirectoryPage.getAllListedDReps();
expect(dRepCards.length).toBeGreaterThan(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { user01Wallet } from "@constants/staticWallets";
import { test } from "@fixtures/walletExtension";
import { setAllureEpic } from "@helpers/allure";
import { isMobile } from "@helpers/mobile";
import DRepDirectoryPage from "@pages/dRepDirectoryPage";
import { expect } from "@playwright/test";

test.use({ storageState: ".auth/user01.json", wallet: user01Wallet });
Expand All @@ -23,19 +22,3 @@ test("2B. Should access DRep Directory page", async ({ page }) => {
).toBeVisible();
}
});

test("2D. Should show delegation options in connected state", async ({
page,
}) => {
const dRepDirectoryPage = new DRepDirectoryPage(page);
await dRepDirectoryPage.goto();

// Verifying automatic delegation options
await dRepDirectoryPage.automaticDelegationOptionsDropdown.click();
await expect(dRepDirectoryPage.abstainDelegationCard).toBeVisible();
await expect(dRepDirectoryPage.signalNoConfidenceCard).toBeVisible();

expect(await dRepDirectoryPage.delegateBtns.count()).toBeGreaterThanOrEqual(
2
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test.beforeEach(async () => {
await setAllureEpic("2. Delegation");
});

test("2M. Should sort DReps", async ({ page }) => {
test("2K_2. Should sort DReps", async ({ page }) => {
test.slow();

enum SortOption {
Expand Down Expand Up @@ -55,7 +55,7 @@ test("2O. Should load more DReps on show more", async ({ page }) => {
}
});

test("2K. Should filter DReps", async ({ page }) => {
test("2K_1. Should filter DReps", async ({ page }) => {
const dRepFilterOptions: DRepStatus[] = ["Active", "Inactive", "Retired"];

const dRepDirectory = new DRepDirectoryPage(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ test.describe("Delegate to others", () => {
wallet: adaHolder01Wallet,
});

test.describe.configure({ mode: "serial" });

test("2A. Should show delegated DRep Id (on Dashboard, and DRep Directory) after delegation", async ({
page,
}, testInfo) => {
Expand All @@ -53,6 +55,32 @@ test.describe("Delegate to others", () => {
await page.goto("/dashboard");
await expect(page.getByText(dRepId)).toBeVisible();
});

test("2H. Should prompt to change delegation after delegation", async ({
page,
}) => {
await page.goto("/");

await expect(
page.getByTestId("delegate-to-another-drep-button")
).toBeVisible();
});

test("2L. Should copy delegated DRepId", async ({ page, context }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"]);

const dRepDirectory = new DRepDirectoryPage(page);
await dRepDirectory.goto();

await dRepDirectory.searchInput.fill(dRep01Wallet.dRepId);
await page.getByTestId(`${dRep01Wallet.dRepId}-copy-id-button`).click();
await expect(page.getByText("Copied to clipboard")).toBeVisible();

const copiedTextDRepDirectory = await page.evaluate(() =>
navigator.clipboard.readText()
);
expect(copiedTextDRepDirectory).toEqual(dRep01Wallet.dRepId);
});
});

test.describe("Change delegation", () => {
Expand Down Expand Up @@ -83,7 +111,7 @@ test.describe("Change delegation", () => {
});
});

test.describe("Delegate to myself", () => {
test.describe("Register DRep state", () => {
let dRepPage: Page;
let wallet: StaticWallet;

Expand All @@ -103,6 +131,7 @@ test.describe("Delegate to myself", () => {
test("2E. Should register as Sole voter", async ({}, testInfo) => {
test.setTimeout(testInfo.timeout + environments.txTimeOut);

const wallet = await walletManager.popWallet("registeredDRep");
const dRepId = wallet.dRepId;

await dRepPage.goto("/");
Expand Down Expand Up @@ -155,6 +184,35 @@ test.describe("Delegate to myself", () => {
});
});

test("2G. Should delegate to myself", async ({ page, browser }, testInfo) => {
test.setTimeout(testInfo.timeout + environments.txTimeOut);

const wallet = await walletManager.popWallet("registeredDRep");
const dRepId = wallet.dRepId;

const dRepAuth = await createTempDRepAuth(page, wallet);
const dRepPage = await createNewPageWithWallet(browser, {
storageState: dRepAuth,
wallet,
enableStakeSigning: true,
});

const dRepDirectoryPage = new DRepDirectoryPage(dRepPage);
await dRepDirectoryPage.goto();

await dRepDirectoryPage.delegateToDRep(dRepId);

await expect(
dRepPage.getByTestId(`${dRepId}-delegate-button')`)
).not.toBeVisible();
await expect(dRepPage.getByTestId(`${dRepId}-copy-id-button`)).toHaveCount(
1,
{
timeout: 20_000,
}
);
});

test.describe("Multiple delegations", () => {
test.use({
storageState: ".auth/adaHolder05.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@ test.describe("Logged in DReps", () => {
page,
}) => {
await page.goto("/");

await expect(page.getByTestId("voting-power-chips")).toBeVisible();

await expect(page.getByTestId("dRep-id-display")).toContainText(
dRep01Wallet.dRepId
); // BUG: testId -> dRep-id-display-dashboard (It is taking sidebar dRep-id)

await page.goto(`${environments.frontendUrl}/governance_actions`);
await page
.locator('[data-testid^="govaction-"][data-testid$="-view-detail"]')
.first()
.click();

await expect(page.getByTestId("vote-button")).toBeVisible();
});

test("3H. Should Update DRep data", async ({ page }, testInfo) => {
Expand Down Expand Up @@ -84,7 +95,7 @@ test.describe("Temporary DReps", () => {
).toBeVisible();
});

test("3I. Should verify retire as DRep", async ({ page, browser }) => {
test("3J. Should verify retire as DRep", async ({ page, browser }) => {
const wallet = await walletManager.popWallet("registeredDRep");

const tempDRepAuth = await createTempDRepAuth(page, wallet);
Expand All @@ -99,11 +110,11 @@ test.describe("Temporary DReps", () => {
await dRepPage.getByTestId("continue-retirement-button").click();

await expect(
dRepPage.getByTestId("retirement-transaction-error-modal")
dRepPage.getByTestId("retirement-transaction-submitted-modal")
).toBeVisible();
});

test("3J. Verify DRep behavior in retired state", async ({
test("3K. Verify DRep behavior in retired state", async ({
page,
browser,
}, testInfo) => {
Expand All @@ -125,8 +136,12 @@ test.describe("Temporary DReps", () => {
dRepPage.getByTestId("retirement-transaction-submitted-modal")
).toBeVisible();
dRepPage.getByTestId("confirm-modal-button").click();

await waitForTxConfirmation(dRepPage);
await expect(dRepPage.getByText("Voting power:₳")).not.toBeVisible();

await expect(dRepPage.getByTestId("voting-power-chips")).not.toBeVisible();

await expect(dRepPage.getByTestId("dRep-id-display")).not.toBeVisible();

const governanceActionsPage = new GovernanceActionsPage(dRepPage);
await governanceActionsPage.goto();
Expand All @@ -135,7 +150,7 @@ test.describe("Temporary DReps", () => {
await expect(govActionDetailsPage.voteBtn).not.toBeVisible();
});

test("3K. Should display 'In Progress' status on dashboard until blockchain confirms DRep registration", async ({
test("3I. Should display 'In Progress' status on dashboard until blockchain confirms DRep registration", async ({
page,
browser,
}, testInfo) => {
Expand Down
Loading