Skip to content

Commit

Permalink
Merge pull request #1485 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Fix Feedback-Usersnap, add proposal auth, fix incompatible wallets, update wallet support and remove GA 'learn more' action test
  • Loading branch information
pmbinapps authored Jul 5, 2024
2 parents 3b12b54 + 76b0459 commit 4de6bd2
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 67 deletions.
2 changes: 1 addition & 1 deletion scripts/govtool/config/templates/docker-compose.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ services:
logging: *logging
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.frontend-csp.headers.contentSecurityPolicy=default-src 'self'; img-src *.usersnap.com https://www.googletagmanager.com 'self' data:; script-src *.usersnap.com 'self' https://www.googletagmanager.com https://browser.sentry-cdn.com; style-src *.usersnap.com *.googleapis.com 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src *.usersnap.com https://s3.eu-central-1.amazonaws.com/upload.usersnap.com 'self' *.ingest.sentry.io *.google-analytics.com *.api.pdf.gov.tools; font-src *.usersnap.com *.gstatic.com 'self' https://fonts.gstatic.com data:; worker-src blob:"
- "traefik.http.middlewares.frontend-csp.headers.contentSecurityPolicy=default-src 'self'; img-src *.usersnap.com https://www.googletagmanager.com 'self' data:; script-src 'unsafe-inline' *.usersnap.com 'self' https://www.googletagmanager.com https://browser.sentry-cdn.com; style-src *.usersnap.com *.googleapis.com 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src *.usersnap.com https://s3.eu-central-1.amazonaws.com/upload.usersnap.com 'self' *.sentry.io *.google-analytics.com *.api.pdf.gov.tools; font-src *.usersnap.com *.gstatic.com 'self' https://fonts.gstatic.com data:; worker-src blob:"
- "traefik.http.routers.to-frontend.rule=Host(`<DOMAIN>`)"
- "traefik.http.routers.to-frontend.entrypoints=websecure"
- "traefik.http.routers.to-frontend.tls.certresolver=myresolver"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CardanoTestWallet,
CardanoTestWalletConfig,
CardanoTestWalletJson,
} from "@cardanoapi/cardano-test-wallet/types";
import { ShelleyWallet } from "@helpers/crypto";
import { Page } from "@playwright/test";
Expand All @@ -12,7 +13,7 @@ export default async function createWallet(
const wallet = (await ShelleyWallet.generate()).json();

const initScriptArgs: {
wallet: CardanoTestWallet;
wallet: CardanoTestWalletJson;
config: CardanoTestWalletConfig;
} = {
wallet,
Expand All @@ -23,12 +24,12 @@ export default async function createWallet(
window["cardanoTestWallet"] = {
...window["cardanoTestWallet"],
wallet: wallet,
};
} as CardanoTestWallet;
if (config) {
window["cardanoTestWallet"]["config"] = {
...window["cardanoTestWallet"]["config"],
...config,
};
} as CardanoTestWallet;
}
}, initScriptArgs);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types";
import { CardanoTestWalletJson } from "@cardanoapi/cardano-test-wallet/types";
import { Page } from "@playwright/test";
import { StaticWallet } from "@types";

export async function importWallet(
page: Page,
wallet: StaticWallet | CardanoTestWallet
wallet: StaticWallet | CardanoTestWalletJson
) {
await page.addInitScript((wallet) => {
// @ts-ignore
Expand Down
24 changes: 16 additions & 8 deletions tests/govtool-frontend/playwright/lib/fixtures/loadExtension.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CardanoTestWalletConfig } from "@cardanoapi/cardano-test-wallet/types";
import {
CardanoTestWallet,
CardanoTestWalletConfig,
} from "@cardanoapi/cardano-test-wallet/types";
import environments from "@constants/environments";
import { Page } from "@playwright/test";

import path = require("path");

export default async function loadDemosExtension(
page: Page,
enableStakeSigning = false
enableStakeSigning?: boolean,
supportedExtensions?: Record<string, number>[]
) {
const demosBundleScriptPath = path.resolve(
__dirname,
Expand All @@ -17,12 +21,16 @@ export default async function loadDemosExtension(
kuberApiUrl: environments.kuber.apiUrl,
kuberApiKey: environments.kuber.apiKey,
};
await page.addInitScript((walletConfig) => {
window["cardanoTestWallet"] = {
walletName: "demos",
config: walletConfig,
};
}, walletConfig);
await page.addInitScript(
({ walletConfig, supportedExtensions }) => {
window["cardanoTestWallet"] = {
walletName: "demos",
supportedExtensions,
config: walletConfig,
} as CardanoTestWallet;
},
{ walletConfig, supportedExtensions }
);

await page.addInitScript({ path: demosBundleScriptPath });
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import loadDemosExtension from "./loadExtension";
type WalletExtensionTestOptions = {
wallet?: StaticWallet;
enableStakeSigning: boolean;
supportedExtensions: Record<string, number>[];
};

export const test = base.extend<WalletExtensionTestOptions>({
wallet: [null, { option: true }],

enableStakeSigning: [true, { option: true }],

page: async ({ page, wallet, enableStakeSigning }, use) => {
await loadDemosExtension(page, enableStakeSigning);
supportedExtensions: [[{ cip: 95 }], { option: true }],

page: async (
{ page, wallet, enableStakeSigning, supportedExtensions },
use
) => {
await loadDemosExtension(page, enableStakeSigning, supportedExtensions);

if (wallet) {
await importWallet(page, wallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const monthNames = [
];

export default function extractExpiryDateFromText(text: string): Date | null {
const regex = /(\d{1,2})th ([\w]{3}) (\d{4})/;
const regex = /(\d{1,2})(st|nd|rd|th) ([\w]{3}) (\d{4})/;
const match = text.match(regex);

if (match) {
const day = parseInt(match[1]);
const month = match[2];
const year = parseInt(match[3]);
const month = match[3];
const year = parseInt(match[4]);

return new Date(year, monthNames.indexOf(month), day);
} else {
Expand Down
18 changes: 13 additions & 5 deletions tests/govtool-frontend/playwright/lib/helpers/page.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types";
import { importWallet } from "@fixtures/importWallet";
import loadDemosExtension from "@fixtures/loadExtension";
import { Browser, Page } from "@playwright/test";
import { StaticWallet } from "@types";

interface BrowserConfig {
storageState: string;
interface NewPageConfig {
storageState?: string;
wallet: StaticWallet;
enableStakeSigning?: boolean;
supportedExtensions?: Record<string, number>[];
}

export async function createNewPageWithWallet(
browser: Browser,
{ storageState, wallet, enableStakeSigning }: BrowserConfig
newPageConfig: NewPageConfig
): Promise<Page> {
const { storageState, wallet, ...extensionConfig } = newPageConfig;

const context = await browser.newContext({
storageState: storageState,
storageState,
});
const newPage = await context.newPage();

await loadDemosExtension(newPage, enableStakeSigning);
await loadDemosExtension(
newPage,
extensionConfig.enableStakeSigning,
extensionConfig.supportedExtensions
);
await importWallet(newPage, wallet);

return newPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { faker } from "@faker-js/faker";
import { generateWalletAddress } from "@helpers/cardano";
import { extractProposalIdFromUrl } from "@helpers/string";
import { Page } from "@playwright/test";
import { ProposalCreateRequest } from "@services/proposalDiscussion/types";
import environments from "lib/constants/environments";
import ProposalDiscussionDetailsPage from "./proposalDiscussionDetailsPage";
import {ProposalCreateRequest} from "@types";

export default class ProposalDiscussionPage {
// Buttons
Expand All @@ -24,6 +24,9 @@ export default class ProposalDiscussionPage {
readonly showLessBtn = this.page.getByRole("button", { name: "Show less" });
readonly infoRadio = this.page.getByLabel("Info");
readonly treasuryRadio = this.page.getByLabel("Treasury");
readonly verifyIdentityBtn = this.page.getByRole("button", {
name: "Verify your identity",
});

constructor(private readonly page: Page) {}

Expand Down
22 changes: 20 additions & 2 deletions tests/govtool-frontend/playwright/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CardanoTestWallet } from "@cardanoapi/cardano-test-wallet/types";
import { CardanoTestWalletJson } from "@cardanoapi/cardano-test-wallet/types";

export type StaticWallet = CardanoTestWallet & {
export type StaticWallet = CardanoTestWalletJson & {
dRepId: string;
address: string;
};
Expand Down Expand Up @@ -122,3 +122,21 @@ export type CommentResponse = {
subcommens_number: number;
};
};


export type ProposalLink = {
prop_link: string;
prop_link_text: string;
};

export type ProposalCreateRequest = {
proposal_links: Array<ProposalLink>;
gov_action_type_id: number;
prop_name: string;
prop_abstract: string;
prop_motivation: string;
prop_rationale: string;
prop_receiving_address?: string;
prop_amount?: string;
is_draft: boolean;
};
14 changes: 7 additions & 7 deletions tests/govtool-frontend/playwright/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/govtool-frontend/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"generate-wallets": "ts-node ./generate_wallets.ts 11"
},
"dependencies": {
"@cardanoapi/cardano-test-wallet": "^1.2.0",
"@cardanoapi/cardano-test-wallet": "^2.0.0",
"@faker-js/faker": "^8.4.1",
"@noble/curves": "^1.3.0",
"@noble/ed25519": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test } from "@fixtures/walletExtension";
import { setAllureEpic } from "@helpers/allure";
import convertBufferToHex from "@helpers/convertBufferToHex";
import { ShelleyWallet } from "@helpers/crypto";
import { createNewPageWithWallet } from "@helpers/page";
import LoginPage from "@pages/loginPage";
import { expect } from "@playwright/test";

Expand Down Expand Up @@ -54,13 +55,16 @@ test("1D. Should reject wallet connection in mainnet", async ({ page }) => {
});

test("1E. Should hide incompatible wallets when connecting", async ({
page,
browser,
}) => {
// Disabling cip95 support for wallet
await createWallet(page, { supportedExtensions: [] });
const wallet = (await ShelleyWallet.generate()).json();
const newPage = await createNewPageWithWallet(browser, {
wallet,
supportedExtensions: [],
});

await page.goto("/");
await page.getByTestId("connect-wallet-button").click();
await newPage.goto("/");
await newPage.getByTestId("connect-wallet-button").click();

await expect(page.getByTestId("demos-wallet-button")).not.toBeVisible();
await expect(newPage.getByTestId("demos-wallet-button")).not.toBeVisible();
});
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ test.describe("Temporary DReps", () => {
.click();

await expect(
dRepPage.locator("span").filter({ hasText: "In Progress" })
dRepPage.locator("span").filter({ hasText: /^In Progress$/ })
).toBeVisible(); // BUG add proper testId for dRep registration card
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,4 @@ test("6D. Should open Sanchonet docs in a new tab when clicking `Learn More` on
page.getByTestId("lear-more-about-sole-voter-button").click(),
]);
await expect(directVoterLearnMorepage).toHaveURL(DIRECT_VOTER_DOC_URL);

const [proposed_GA_VoterLearnMorepage] = await Promise.all([
context.waitForEvent("page"),
page.getByRole("button", { name: "Learn more" }).nth(3).click(), // BUG missing test id
]);
await expect(proposed_GA_VoterLearnMorepage).toHaveURL(
PROPOSE_GOVERNANCE_ACTION_DOC_URL
);
});
34 changes: 17 additions & 17 deletions tests/govtool-frontend/playwright/tests/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ setup("Create AdaHolder 06 auth", async ({ page, context }) => {
await context.storageState({ path: adaHolder06AuthFile });
});

/**
* TODO: Uncomment this
* This has been commented to temporarily disable pdf-tests
*/
// setup("Create Proposal 01 auth", async ({ page, context }) => {
// await importWallet(page, proposal01Wallet);

// const loginPage = new LoginPage(page);
// await loginPage.login();
// await loginPage.isLoggedIn();

// const proposalDiscussionPage = new ProposalDiscussionPage(page);
// await proposalDiscussionPage.goto();
// await proposalDiscussionPage.setUsername(faker.internet.userName());

// await context.storageState({ path: proposal01AuthFile });
// });
setup("Create Proposal 01 auth", async ({ page, context }) => {
await importWallet(page, proposal01Wallet);

const loginPage = new LoginPage(page);
await loginPage.login();
await loginPage.isLoggedIn();

const proposalDiscussionPage = new ProposalDiscussionPage(page);
await proposalDiscussionPage.goto();
await proposalDiscussionPage.verifyIdentityBtn.click();

await proposalDiscussionPage.setUsername(
faker.internet.userName().toLowerCase()
);

await context.storageState({ path: proposal01AuthFile });
});

0 comments on commit 4de6bd2

Please sign in to comment.