Skip to content

Commit

Permalink
chore: format vote ada for governance action
Browse files Browse the repository at this point in the history
  • Loading branch information
kneerose committed Nov 19, 2024
1 parent 4441d19 commit bc67776
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
15 changes: 15 additions & 0 deletions tests/govtool-frontend/playwright/lib/helpers/adaFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const LOVELACE = 1000000;

export const correctVoteAdaFormat = (
lovelace: number | undefined,
locale: string | undefined = undefined
) => {
if (lovelace) {
const ada = lovelace / LOVELACE;
return ada.toLocaleString(locale, {
minimumFractionDigits: 3,
maximumFractionDigits: 3,
});
}
return "0,000";
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@types";
import walletManager from "lib/walletManager";
import GovernanceActionDetailsPage from "@pages/governanceActionDetailsPage";
import { correctVoteAdaFormat } from "@helpers/adaFormat";

test.beforeEach(async () => {
await setAllureEpic("4. Proposal visibility");
Expand Down Expand Up @@ -77,7 +78,7 @@ test.describe("Logged in DRep", () => {
}) => {
for (let i = 0; i < 100; i++) {
const invalidUrl = mockInvalid.url(false);
await govActionDetailsPage.metadataUrlInput.fill(invalidUrl);
await govActionDetailsPage.metadataUrlInput.fill(invalidUrl);
if (invalidUrl.length <= 128) {
await expect(page.getByTestId("invalid-url-error")).toBeVisible();
} else {
Expand Down Expand Up @@ -161,24 +162,24 @@ test.describe("Check vote count", () => {

// check dRep votes
await expect(govActionDetailsPage.dRepYesVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepYesVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepYesVotes)}`
);
await expect(govActionDetailsPage.dRepAbstainVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepAbstainVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepAbstainVotes)}`
);
await expect(govActionDetailsPage.dRepNoVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepNoVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepNoVotes)}`
);

// check sPos votes
await expect(govActionDetailsPage.sPosYesVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolYesVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolYesVotes)}`
);
await expect(govActionDetailsPage.sPosAbstainVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolAbstainVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolAbstainVotes)}`
);
await expect(govActionDetailsPage.sPosNoVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolNoVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolNoVotes)}`
);

// check ccCommittee votes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { correctVoteAdaFormat } from "@helpers/adaFormat";
import { setAllureEpic } from "@helpers/allure";
import { lovelaceToAda, skipIfNotHardFork } from "@helpers/cardano";
import { skipIfNotHardFork } from "@helpers/cardano";
import GovernanceActionsPage from "@pages/governanceActionsPage";
import { expect, test } from "@playwright/test";
import { GrovernanceActionType, IProposal } from "@types";
Expand Down Expand Up @@ -57,24 +58,24 @@ test("4K. Should display correct vote counts on governance details page for disc

// check dRep votes
await expect(govActionDetailsPage.dRepYesVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepYesVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepYesVotes)}`
);
await expect(govActionDetailsPage.dRepAbstainVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepAbstainVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepAbstainVotes)}`
);
await expect(govActionDetailsPage.dRepNoVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.dRepNoVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.dRepNoVotes)}`
);

// check sPos votes
await expect(govActionDetailsPage.sPosYesVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolYesVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolYesVotes)}`
);
await expect(govActionDetailsPage.sPosAbstainVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolAbstainVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolAbstainVotes)}`
);
await expect(govActionDetailsPage.sPosNoVotes).toHaveText(
`₳ ${lovelaceToAda(proposalToCheck.poolNoVotes)}`
`₳ ${correctVoteAdaFormat(proposalToCheck.poolNoVotes)}`
);

// check ccCommittee votes
Expand Down

0 comments on commit bc67776

Please sign in to comment.