Skip to content
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
16 changes: 12 additions & 4 deletions tests/govtool-frontend/playwright/lib/helpers/adaFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ const LOVELACE = 1000000;

export const correctVoteAdaFormat = (
lovelace: number | undefined,
locale: string | undefined = undefined
precision = 2
) => {
if (lovelace) {
const ada = lovelace / LOVELACE;
return ada.toLocaleString(locale, {
maximumFractionDigits: 3,
});
if (ada < 1000)
return ada.toLocaleString("en-us", {
maximumFractionDigits: precision,
});
const suffixes = ["k", "M", "B", "T"];
const divisors = [1000, 1000000, 1000000000, 1000000000000];
for (let i = 0; i < suffixes.length; i++) {
if (ada < divisors[i] * 1000) {
return (ada / divisors[i]).toFixed(precision) + suffixes[i];
}
}
}
return "0";
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import environments from "@constants/environments";
import { downloadMetadata } from "@helpers/metadata";
import { Download, Page } from "@playwright/test";
import { Download, Page, Response } from "@playwright/test";
import metadataBucketService from "@services/metadataBucketService";
import { IProposal } from "@types";
import { withTxConfirmation } from "lib/transaction.decorator";

export default class GovernanceActionDetailsPage {
Expand Down Expand Up @@ -39,6 +40,9 @@ export default class GovernanceActionDetailsPage {

readonly dRepYesVotes = this.page.getByTestId("submitted-votes-dReps-yes");
readonly dRepNoVotes = this.page.getByTestId("submitted-votes-dReps-no");
readonly dRepNotVoted = this.page.getByTestId(
"submitted-votes-dReps-notVoted"
);
readonly dRepAbstainVotes = this.page.getByTestId(
"submitted-votes-dReps-abstain"
);
Expand Down Expand Up @@ -97,6 +101,29 @@ export default class GovernanceActionDetailsPage {
await this.voteBtn.click();
}

async getDRepNotVoted(
proposal: IProposal,
metricsResponsePromise: Promise<Response>
): Promise<number | undefined> {
const metricsResponses = await Promise.resolve(metricsResponsePromise);
const totalStakeControlledByDReps = await metricsResponses
.json()
.then((data) => data.totalStakeControlledByDReps);

if (
totalStakeControlledByDReps &&
typeof totalStakeControlledByDReps === "number"
) {
const dRepNotVoted =
totalStakeControlledByDReps -
proposal.dRepYesVotes -
proposal.dRepAbstainVotes -
proposal.dRepNoVotes;

return dRepNotVoted;
}
}

async downloadVoteMetadata() {
const download: Download = await this.page.waitForEvent("download");
return downloadMetadata(download);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ test.describe("Check vote count", () => {
)
);

const metricsResponsePromise = page.waitForResponse((response) =>
response.url().includes(`network/metrics`)
);

const governanceActionsPage = new GovernanceActionsPage(page);
await governanceActionsPage.goto();

Expand Down Expand Up @@ -180,6 +184,11 @@ test.describe("Check vote count", () => {
`${proposalToCheck.txHash}#${proposalToCheck.index}`
);

const dRepNotVoted = await govActionDetailsPage.getDRepNotVoted(
proposalToCheck,
metricsResponsePromise
);

await govActionDetailsPage.showVotesBtn.click();

// check dRep votes
Expand All @@ -193,6 +202,12 @@ test.describe("Check vote count", () => {
await expect(govActionDetailsPage.dRepNoVotes).toHaveText(
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepNoVotes)}`
);

if (dRepNotVoted) {
await expect(govActionDetailsPage.dRepNotVoted).toHaveText(
`₳ ${correctVoteAdaFormat(dRepNotVoted)}`
);
}
}

// check sPos votes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ test("4K. Should display correct vote counts on governance details page for disc
)
);

const metricsResponsePromise = page.waitForResponse((response) =>
response.url().includes(`network/metrics`)
);

const governanceActionsPage = new GovernanceActionsPage(page);
await governanceActionsPage.goto();
const responses = await Promise.all(responsesPromise);
Expand All @@ -71,6 +75,11 @@ test("4K. Should display correct vote counts on governance details page for disc
`${proposalToCheck.txHash}#${proposalToCheck.index}`
);

const dRepNotVoted = await govActionDetailsPage.getDRepNotVoted(
proposalToCheck,
metricsResponsePromise
);

// check dRep votes
if (await areDRepVoteTotalsDisplayed(proposalToCheck)) {
await expect(govActionDetailsPage.dRepYesVotes).toHaveText(
Expand All @@ -82,6 +91,12 @@ test("4K. Should display correct vote counts on governance details page for disc
await expect(govActionDetailsPage.dRepNoVotes).toHaveText(
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepNoVotes)}`
);

if (dRepNotVoted) {
await expect(govActionDetailsPage.dRepNotVoted).toHaveText(
`₳ ${correctVoteAdaFormat(dRepNotVoted)}`
);
}
}
// check sPos votes
if (await areSPOVoteTotalsDisplayed(proposalToCheck)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ test.describe("Proposal checks", () => {
});

test.describe("Validate provide context about vote", () => {
const characters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
test("5D_1. Should accept valid data in provide context", async () => {
await govActionDetailsPage.contextBtn.click();

await expect(govActionDetailsPage.contextInput).toBeVisible();

for (let i = 0; i < 100; i++) {
const randomContext = faker.lorem.paragraph(2);
const randomContext = faker.string.fromCharacters(characters, {
min: 1,
max: 9999,
});
await govActionDetailsPage.contextInput.fill(randomContext);
expect(await govActionDetailsPage.contextInput.textContent()).toEqual(
randomContext
Expand All @@ -118,7 +123,7 @@ test.describe("Proposal checks", () => {
await expect(govActionDetailsPage.contextInput).toBeVisible();

for (let i = 0; i < 100; i++) {
const randomContext = faker.lorem.paragraph(40);
const randomContext = faker.string.fromCharacters(characters, 10001);
await govActionDetailsPage.contextInput.fill(randomContext);
expect(
await govActionDetailsPage.contextInput.textContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test.describe("Proposal created logged in state", () => {
await proposalDiscussionDetailsPage.addComment(randComment);

await proposalDiscussionDetailsPage.replyComment(randReply);
await expect(page.getByText(randReply)).toBeVisible();
await expect(page.getByText(randReply)).toBeVisible({ timeout: 15_000 });
});
});

Expand Down Expand Up @@ -122,12 +122,12 @@ test.describe("Proposal created with poll enabled (user auth)", () => {
// vote must be changed
await expect(
page.getByTestId(`poll-${vote.toLowerCase()}-count`)
).not.toHaveText(`${vote}: (0%)`);
).toHaveText(`${vote}: (0%)`, { timeout: 15_000 });
// opposite of random choice vote
const oppositeVote = pollVotes[pollVotes.length - 1 - choice];
await expect(
page.getByTestId(`poll-${oppositeVote.toLowerCase()}-count`)
).not.toHaveText(`${oppositeVote}: (100%)`);
).toHaveText(`${oppositeVote}: (100%)`);
});
});

Expand Down