diff --git a/tests/govtool-frontend/playwright/lib/_mock/outcome.json b/tests/govtool-frontend/playwright/lib/_mock/outcome.json new file mode 100644 index 000000000..37c973231 --- /dev/null +++ b/tests/govtool-frontend/playwright/lib/_mock/outcome.json @@ -0,0 +1,41 @@ +[ + { + "id": "320", + "tx_hash": "833382b22ebd07bb7dee60001cfdce78ede3b8397b1027daeb7996f61c072bde", + "index": "0", + "type": "InfoAction", + "description": { + "data": { + "tag": "InfoAction" + } + }, + "expiry_date": "2025-02-27T00:01:04.000Z", + "expiration": 856, + "time": "2025-01-27T16:15:21.000Z", + "epoch_no": 825, + "url": "https://bit.ly/3zCH2HL", + "data_hash": "99a19b124ceb89bbd92354e8d11f913d1aec7280ce19ac4c1c6cc72f0ea91884", + "proposal_params": null, + "title": null, + "abstract": null, + "motivation": null, + "rationale": null, + "yes_votes": "0", + "no_votes": "14333625476330", + "abstain_votes": "0", + "pool_yes_votes": "0", + "pool_no_votes": "0", + "pool_abstain_votes": "0", + "cc_yes_votes": "0", + "cc_no_votes": "0", + "cc_abstain_votes": "0", + "prev_gov_action_index": null, + "prev_gov_action_tx_hash": null, + "status": { + "ratified_epoch": null, + "enacted_epoch": null, + "dropped_epoch": 857, + "expired_epoch": 856 + } + } +] diff --git a/tests/govtool-frontend/playwright/lib/constants/index.ts b/tests/govtool-frontend/playwright/lib/constants/index.ts index e27231cee..407772241 100644 --- a/tests/govtool-frontend/playwright/lib/constants/index.ts +++ b/tests/govtool-frontend/playwright/lib/constants/index.ts @@ -1,3 +1,6 @@ +import { faker } from "@faker-js/faker"; +import { InvalidMetadataType } from "@types"; + export const SECURITY_RELEVANT_PARAMS_MAP: Record = { maxBlockBodySize: "max_block_size", maxTxSize: "max_tx_size", @@ -31,3 +34,30 @@ export const outcomeStatusType = [ "Enacted", "Live", ]; + +export const InvalidMetadata: InvalidMetadataType[] = [ + { + type: "Data Formatted Incorrectly", + reason: "hash is valid but incorrect metadata format.", + url: "https://metadata-govtool.cardanoapi.io/data/Lolita", + hash: "62a37df07103f0a69690c8975700e06b7c3c3069cb3d105abec00e820e831dda", + }, + { + type: "Data Missing", + reason: "metadata URL could not be found.", + url: faker.internet.url() + "/test.jsonld", + hash: "99a19b124ceb89bbd92354e8d11f913d1aec7280ce19ac4c1c6cc72f0ea91884", + }, + { + type: "Data Not Verifiable", + reason: "metadata hash and URL do not match.", + url: "https://metadata-govtool.cardanoapi.io/data/data.jsonld", + hash: "e71bf6171adda3754a87fff5c2d8d9e404eb3366428a5be13f7e76357a39004f", + }, + { + type: "Data Not Verifiable", + reason: "metadata hash and URL do not match and is incorrect ga format", + url: "https://metadata-govtool.cardanoapi.io/data/Lolita", + hash: "e71bf6171adda3754a87fff5c2d8d9e404eb3366428a5be13f7e76357a39004f", + }, +]; diff --git a/tests/govtool-frontend/playwright/lib/types.ts b/tests/govtool-frontend/playwright/lib/types.ts index ef277f297..f7fd09a8d 100644 --- a/tests/govtool-frontend/playwright/lib/types.ts +++ b/tests/govtool-frontend/playwright/lib/types.ts @@ -9,6 +9,13 @@ export type KuberValue = { [policyId: string]: Record | BigInt | number; }; +export interface PaginatedLiveProposal { + page: number; + pageSize: number; + total: number; + elements: IProposal[]; +} + export interface IProposal { id: string; txHash: string; @@ -302,3 +309,10 @@ interface outcomeMetadataBody { rationale: string; title: string; } + +export interface InvalidMetadataType { + type: string; + reason: string; + url: string; + hash: string; +} 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 ab36868fa..f86f2dfa5 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 @@ -10,18 +10,19 @@ import GovernanceActionDetailsPage from "@pages/governanceActionDetailsPage"; import GovernanceActionsPage from "@pages/governanceActionsPage"; import { expect } from "@playwright/test"; import { test } from "@fixtures/walletExtension"; -import { GovernanceActionType, IProposal } from "@types"; +import { GovernanceActionType, IProposal, PaginatedLiveProposal } from "@types"; import { injectLogger } from "@helpers/page"; import removeAllSpaces from "@helpers/removeAllSpaces"; import { functionWaitedAssert } from "@helpers/waitedLoop"; import extractExpiryDateFromText from "@helpers/extractExpiryDateFromText"; +import { InvalidMetadata } from "@constants/index"; test.beforeEach(async () => { await setAllureEpic("4. Proposal visibility"); await skipIfNotHardFork(); }); -const infoTypeProposal = require("../../lib/_mock/infoTypeProposal.json"); +const infoTypeProposal: PaginatedLiveProposal = require("../../lib/_mock/infoTypeProposal.json"); const filterOptionNames = [ "Protocol Parameter Change", @@ -298,3 +299,37 @@ test("4K. Should display correct vote counts on governance details page for disc }) ); }); + +test.describe("Invalid Live voting Metadata", () => { + InvalidMetadata.forEach(({ type, reason, url, hash }, index) => { + test(`4P_${index + 1}: Should display ${type} message in live voting when ${reason}`, async ({ + page, + }) => { + const proposal: IProposal = { + ...infoTypeProposal.elements[0], + url, + metadataHash: hash, + }; + const liveProposalResponse: PaginatedLiveProposal = { + ...infoTypeProposal, + elements: [proposal], + }; + + await page.route("**/proposal/list?**", async (route) => + route.fulfill({ + body: JSON.stringify(liveProposalResponse), + }) + ); + + const governanceActionPage = new GovernanceActionsPage(page); + await governanceActionPage.goto(); + await governanceActionPage.viewFirstProposal(); + + await expect(page.getByRole("heading", { name: type })).toBeVisible({ + timeout: 60_000, + }); + await expect(page.getByText("Learn more")).toBeVisible(); + await expect(page.getByTestId("external-modal-button")).toBeVisible(); + }); + }); +}); diff --git a/tests/govtool-frontend/playwright/tests/9-outcomes/outcomes.spec.ts b/tests/govtool-frontend/playwright/tests/9-outcomes/outcomes.spec.ts index 6a8108728..02758ce10 100644 --- a/tests/govtool-frontend/playwright/tests/9-outcomes/outcomes.spec.ts +++ b/tests/govtool-frontend/playwright/tests/9-outcomes/outcomes.spec.ts @@ -1,3 +1,4 @@ +import { InvalidMetadata } from "@constants/index"; import { test } from "@fixtures/walletExtension"; import { correctVoteAdaFormat } from "@helpers/adaFormat"; import { setAllureEpic } from "@helpers/allure"; @@ -15,6 +16,8 @@ import OutComesPage from "@pages/outcomesPage"; import { expect, Page } from "@playwright/test"; import { outcomeMetadata, outcomeProposal, outcomeType } from "@types"; +const invalidOutcomeProposals = require("../../lib/_mock/outcome.json"); + test.beforeEach(async () => { await setAllureEpic("9. Outcomes"); await skipIfNotHardFork(); @@ -400,3 +403,30 @@ test("9G. Should display correct vote counts on outcome details page", async ({ }) ); }); + +test.describe("Invalid Outcome Metadata", () => { + InvalidMetadata.forEach(({ type, reason, url, hash }, index) => { + test(`9H_${index + 1}: Should display "${type}" message in outcomes when ${reason}`, async ({ + page, + }) => { + const outcomeResponse = { + ...invalidOutcomeProposals[0], + url, + data_hash: hash, + }; + + await page.route(/.*\/governance-actions\/[a-f0-9]{64}\?.*/, (route) => + route.fulfill({ body: JSON.stringify([outcomeResponse]) }) + ); + + const outcomePage = new OutComesPage(page); + await outcomePage.goto(); + await outcomePage.viewFirstOutcomes(); + + await expect(page.getByRole("heading", { name: type })).toBeVisible({ + timeout: 60_000, + }); + await expect(page.getByText("Learn more")).toBeVisible(); + }); + }); +});