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 #1054

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions tests/govtool-frontend/playwright/lib/helpers/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion tests/govtool-frontend/playwright/lib/helpers/page.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -65,4 +75,72 @@ 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();
}

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class GovernanceActionsPage {
}

async getAllProposals() {
await this.page.waitForTimeout(2000);
return this.page.locator('[data-test-id$="-card"]').all();
}

Expand Down Expand Up @@ -118,6 +119,7 @@ export default class GovernanceActionsPage {
}
});

await this.page.waitForTimeout(2000);
// Frontend validation
const proposalCards = await Promise.all(
filterKeys.map((key) =>
Expand Down
15 changes: 4 additions & 11 deletions tests/govtool-frontend/playwright/lib/pages/loginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 });

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ 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";
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"]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand Down
Loading