Skip to content

Commit a38ed7f

Browse files
authored
Merge pull request #4031 : Vote Anchor Related Voting Tests.
2 parents aa83ac2 + c770507 commit a38ed7f

File tree

9 files changed

+108
-79
lines changed

9 files changed

+108
-79
lines changed

govtool/frontend/src/components/molecules/VoteActionForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export const VoteActionForm = ({
275275
border: !showWholeVoteContext ? "1px solid #E1E1E1" : "none",
276276
borderRadius: "4px",
277277
backgroundColor: !showWholeVoteContext ? fadedPurple.c50 : "transparent",
278-
padding: 2,
278+
padding: 2
279279
}}
280280
>
281281
<Typography
@@ -292,6 +292,7 @@ export const VoteActionForm = ({
292292
WebkitLineClamp: 2,
293293
}),
294294
}}
295+
data-testid="vote-rationale-context"
295296
>
296297
{finalVoteContextText}
297298
</Typography>
@@ -316,7 +317,7 @@ export const VoteActionForm = ({
316317
}}
317318
disableRipple
318319
variant="text"
319-
data-testid="external-modal-button"
320+
data-testid="show-more-button"
320321
>
321322
<Typography
322323
variant="body2"

govtool/frontend/src/components/organisms/VoteContext/VoteContextChoice.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ export const VoteContextChoice = ({
7070
variant="outlined"
7171
onClick={handleLetGovToolStore}
7272
sx={{ width: isMobile ? "100%" : "259px", whiteSpace: "nowrap", height: "48px", fontWeight: "500" }}
73+
data-testid="govtool-pins-data-to-ipfs-option-button"
7374
>
7475
{t("createGovernanceAction.govToolPinsDataToIPFS")}
7576
</Button>
7677
<Button
7778
variant="outlined"
7879
onClick={handleStoreItMyself}
7980
sx={{ width: isMobile ? "100%" : "287px", whiteSpace: "nowrap", height: "48px", fontWeight: "500" }}
81+
data-testid="download-and-store-yourself-option-button"
8082
>
8183
{t("createGovernanceAction.downloadAndStoreYourself")}
8284
</Button>

tests/govtool-frontend/playwright/lib/helpers/waitedLoop.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function waitedLoop(
99
const startTime = Date.now();
1010
while (Date.now() - startTime < timeout) {
1111
if (await conditionFn()) return true;
12-
Logger.info("Retring the function");
12+
Logger.info("Retrying the function");
1313
await new Promise((resolve) => setTimeout(resolve, interval));
1414
}
1515
return false;
@@ -36,9 +36,10 @@ export async function functionWaitedAssert(
3636
} catch (error) {
3737
if (Date.now() - startTime >= timeout) {
3838
const errorMessage = options.message || error.message;
39+
console.log(errorMessage);
3940
expect(false, { message: errorMessage }).toBe(true);
4041
}
41-
Logger.info(`Retring the function ${name}`);
42+
Logger.info(`Retrying the function ${name}`);
4243
await new Promise((resolve) => setTimeout(resolve, interval));
4344
}
4445
}

tests/govtool-frontend/playwright/lib/pages/governanceActionDetailsPage.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default class GovernanceActionDetailsPage {
2121
readonly externalModalBtn = this.page.getByTestId("external-modal-button");
2222
readonly governanceActionId = this.page.getByText("Governance Action ID:");
2323

24-
readonly contextBtn = this.page.getByTestId("provide-context-button");
2524
readonly metadataDownloadBtn = this.page.getByTestId(
2625
"metadata-download-button"
2726
);
@@ -31,6 +30,9 @@ export default class GovernanceActionDetailsPage {
3130
readonly continueModalBtn = this.page.getByTestId("continue-modal-button");
3231
readonly confirmModalBtn = this.page.getByTestId("confirm-modal-button");
3332

33+
readonly downloadAndStoreYourselfOptionBtn = this.page.getByTestId("download-and-store-yourself-option-button")
34+
readonly govtoolPinsDatatoIpfsBtn = this.page.getByTestId("govtool-pins-data-to-ipfs-option-button")
35+
3436
readonly voteSuccessModal = this.page.getByTestId("alert-success");
3537
readonly externalLinkModal = this.page.getByTestId("external-link-modal");
3638

@@ -76,37 +78,41 @@ export default class GovernanceActionDetailsPage {
7678
}
7779

7880
@withTxConfirmation
79-
async vote(context?: string, isAlreadyVoted: boolean = false) {
81+
async vote(context?: string, isAlreadyVoted: boolean = false , useIPFSforStorage : boolean = false ){
8082
if (!isAlreadyVoted) {
8183
await this.yesVoteRadio.click();
8284
}
8385

86+
await this.voteBtn.click()
87+
8488
if (context) {
85-
await this.contextBtn.click();
8689
await this.contextInput.fill(context);
87-
await this.confirmModalBtn.click();
88-
await this.page.getByRole("checkbox").click();
89-
await this.confirmModalBtn.click();
90-
91-
this.metadataDownloadBtn.click();
92-
const voteMetadata = await this.downloadVoteMetadata();
93-
const url = await metadataBucketService.uploadMetadata(
94-
voteMetadata.name,
95-
voteMetadata.data
96-
);
9790

98-
await this.metadataUrlInput.fill(url);
91+
this.confirmModalBtn.click()
92+
93+
if (useIPFSforStorage) {
94+
await this.govtoolPinsDatatoIpfsBtn.click()
95+
} else {
96+
97+
await this.downloadAndStoreYourselfOptionBtn.click()
98+
await this.page.getByRole("checkbox").click();
99+
await this.confirmModalBtn.click();
100+
101+
this.metadataDownloadBtn.click();
102+
const voteMetadata = await this.downloadVoteMetadata();
103+
const url = await metadataBucketService.uploadMetadata(
104+
voteMetadata.name,
105+
voteMetadata.data
106+
);
107+
await this.metadataUrlInput.fill(url);
108+
}
99109
await this.confirmModalBtn.click();
100110
await this.page.getByTestId("go-to-vote-modal-button").click();
101-
}
102-
103-
const isVoteButtonEnabled = await this.voteBtn.isEnabled();
104-
105-
await expect(this.voteBtn, {
106-
message: !isVoteButtonEnabled && "Vote button is not enabled",
107-
}).toBeEnabled({ timeout: 60_000 });
108111

109-
await this.voteBtn.click();
112+
}
113+
else {
114+
await this.confirmModalBtn.click()
115+
}
110116
}
111117

112118
async getDRepNotVoted(
@@ -165,5 +171,6 @@ export default class GovernanceActionDetailsPage {
165171
async reVote() {
166172
await this.noVoteRadio.click();
167173
await this.changeVoteBtn.click();
174+
await this.confirmModalBtn.click();
168175
}
169176
}

tests/govtool-frontend/playwright/lib/pages/governanceActionsPage.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export default class GovernanceActionsPage {
5555
async viewFirstProposalByGovernanceAction(
5656
governanceAction: GovernanceActionType
5757
): Promise<GovernanceActionDetailsPage> {
58-
const proposalCard = this.page
59-
.getByTestId(`govaction-${governanceAction}-card`)
60-
.first();
58+
const proposalCard = this.page
59+
.locator('[data-testid^="govaction-"][data-testid$="-card"]')
60+
.first();
6161

6262
const isVisible = await proposalCard.isVisible();
6363

@@ -76,6 +76,20 @@ export default class GovernanceActionsPage {
7676
}
7777
}
7878

79+
async getFirstProposal(
80+
) {
81+
await functionWaitedAssert(
82+
async () => {
83+
const proposalCard = this.page
84+
.locator('[data-testid^="govaction-"][data-testid$="-card"]')
85+
.first();
86+
87+
await expect(proposalCard
88+
.locator('[data-testid^="govaction-"][data-testid$="-view-detail"]')
89+
.first()).toBeVisible()
90+
}, { name: "Retrying to get the first proposal" });
91+
}
92+
7993
async viewVotedProposal(
8094
proposal: IProposal
8195
): Promise<GovernanceActionDetailsPage> {
@@ -122,7 +136,7 @@ export default class GovernanceActionsPage {
122136
expect(
123137
hasFilter,
124138
hasFilter == false &&
125-
`A proposal card does not contain any of the ${filters}`
139+
`A proposal card does not contain any of the ${filters}`
126140
).toBe(true);
127141
}
128142
}

tests/govtool-frontend/playwright/tests/3-drep-registration/dRepRegistration.dRep.spec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,12 @@ test.describe("Logged in DReps", () => {
4242
timeout: 60_000,
4343
});
4444

45-
await expect(
46-
page.getByTestId("dRep-id-display-card-dashboard")
47-
).toContainText(dRep01Wallet.dRepId, { timeout: 60_000 });
48-
45+
4946
const governanceActionsPage = new GovernanceActionsPage(page);
50-
47+
5148
await governanceActionsPage.goto();
52-
53-
await expect(page.getByText(/info action/i).first()).toBeVisible({
54-
timeout: 60_000,
55-
});
56-
49+
50+
await governanceActionsPage.getFirstProposal();
5751
const governanceActionDetailsPage =
5852
await governanceActionsPage.viewFirstProposalByGovernanceAction(
5953
GovernanceActionType.InfoAction

tests/govtool-frontend/playwright/tests/4-proposal-visibility/proposalVisibility.dRep.spec.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,32 +106,47 @@ test.describe("Temporary DReps", async () => {
106106

107107
test.beforeEach(async ({ page, browser }) => {
108108
const wallet = await walletManager.popWallet("registeredDRep");
109-
110109
const tempDRepAuth = await createTempDRepAuth(page, wallet);
111-
112110
dRepPage = await createNewPageWithWallet(browser, {
113111
storageState: tempDRepAuth,
114112
wallet,
115113
enableDRepSigning: true,
116114
});
117115
});
118116

119-
test("4J. Should include metadata anchor in the vote transaction", async ({}, testInfo) => {
117+
const verifyVoteWithMetadata = async (testInfo: any, useGovToolIPFS: boolean = false) => {
120118
test.setTimeout(testInfo.timeout + environments.txTimeOut);
121-
119+
122120
const govActionsPage = new GovernanceActionsPage(dRepPage);
123121
await govActionsPage.goto();
124-
122+
125123
const govActionDetailsPage = await govActionsPage.viewFirstProposal();
126-
await govActionDetailsPage.vote(faker.lorem.sentence(200));
127-
124+
const fakerContext = faker.lorem.sentence(200);
125+
126+
if (useGovToolIPFS) {
127+
await govActionDetailsPage.vote(fakerContext, false, true);
128+
} else {
129+
await govActionDetailsPage.vote(fakerContext);
130+
}
131+
132+
await dRepPage.reload();
128133
await dRepPage.waitForTimeout(5_000);
129-
130134
await govActionsPage.votedTab.click();
131-
await govActionsPage.viewFirstVotedProposal();
135+
136+
const votedGovActionDetailsPage = await govActionsPage.viewFirstVotedProposal();
137+
await votedGovActionDetailsPage.currentPage.getByTestId("show-more-button").click();
138+
await votedGovActionDetailsPage.currentPage.waitForTimeout(2000);
139+
140+
const voteRationaleContext = await votedGovActionDetailsPage.currentPage.getByTestId("vote-rationale-context");
141+
await expect(voteRationaleContext).toContainText(fakerContext);
142+
};
143+
144+
test("4J. Should include metadata anchor in the vote transaction (Download and store yourself)", async ({}, testInfo) => {
145+
await verifyVoteWithMetadata(testInfo, false);
146+
});
132147

133-
// Vote context is not displayed in UI to validate
134-
expect(false, "No vote context displayed").toBe(true);
148+
test("4k. Should include metadata anchor in the vote transaction (GovTool pins data to IPFS)", async ({}, testInfo) => {
149+
await verifyVoteWithMetadata(testInfo, true);
135150
});
136151
});
137152

tests/govtool-frontend/playwright/tests/5-proposal-functionality/proposalFunctionality.dRep.spec.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ test.describe("Proposal checks", () => {
7272
currentPage.getByTestId(`${cip129GovActionId}-id`)
7373
).toBeVisible();
7474

75-
await expect(govActionDetailsPage.contextBtn).toBeVisible();
7675
await expect(govActionDetailsPage.showVotesBtn).toBeVisible();
7776

7877
await expect(govActionDetailsPage.voteBtn).toBeVisible();
@@ -87,20 +86,22 @@ test.describe("Proposal checks", () => {
8786
await expect(govActionDetailsPage.noVoteRadio).toBeVisible();
8887
await expect(govActionDetailsPage.abstainRadio).toBeVisible();
8988

90-
await govActionDetailsPage.contextBtn.click();
89+
await govActionDetailsPage.yesVoteRadio.click();
90+
await govActionDetailsPage.voteBtn.click();
9191

9292
await expect(govActionDetailsPage.contextInput).toBeVisible();
9393
await govActionDetailsPage.cancelModalBtn.click();
9494

95-
await govActionDetailsPage.yesVoteRadio.click();
9695
await expect(govActionDetailsPage.voteBtn).toBeEnabled();
9796
});
9897

9998
test.describe("Validate provide context about vote", () => {
10099
const characters =
101100
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
102101
test("5D_1. Should accept valid data in provide context", async () => {
103-
await govActionDetailsPage.contextBtn.click();
102+
103+
await govActionDetailsPage.yesVoteRadio.click()
104+
await govActionDetailsPage.voteBtn.click()
104105

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

@@ -119,7 +120,8 @@ test.describe("Proposal checks", () => {
119120
});
120121

121122
test("5D_2. Should reject invalid data in provide context", async () => {
122-
await govActionDetailsPage.contextBtn.click();
123+
await govActionDetailsPage.yesVoteRadio.click()
124+
await govActionDetailsPage.voteBtn.click()
123125

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

@@ -245,32 +247,23 @@ test.describe("Perform voting", () => {
245247
).toBeVisible();
246248

247249
govActionDetailsPage = await governanceActionsPage.viewFirstVotedProposal();
248-
await govActionDetailsPage.vote(faker.lorem.sentence(200), true);
250+
251+
const fakerContext = faker.lorem.sentence(200)
252+
await govActionDetailsPage.vote(fakerContext, true);
249253

250254
await govActionDetailsPage.currentPage.reload();
251255

252256
await governanceActionsPage.votedTab.click();
253257

254-
const isYesVoteVisible = await govActionDetailsPage.currentPage
255-
.getByTestId("my-vote")
256-
.getByText("Yes")
257-
.isVisible();
258-
259-
const textContent = await govActionDetailsPage.currentPage
260-
.getByTestId("my-vote")
261-
.textContent();
262-
263-
await govActionDetailsPage.currentPage.evaluate(() =>
264-
window.scrollTo(0, 500)
265-
);
266-
await expect(
267-
govActionDetailsPage.currentPage.getByTestId("my-vote").getByText("Yes"),
268-
{
269-
message:
270-
!isYesVoteVisible &&
271-
`"Yes" vote not visible, current vote status: ${textContent.match(/My Vote:(Yes|No)/)[1]}`,
272-
}
273-
).toBeVisible({ timeout: 60_000 });
258+
govActionDetailsPage = await governanceActionsPage.viewFirstVotedProposal();
259+
260+
await govActionDetailsPage.currentPage.getByTestId("yes-radio").isVisible();
261+
262+
await govActionDetailsPage.currentPage.getByTestId("show-more-button").click();
263+
await govActionDetailsPage.currentPage.waitForTimeout(2000);
264+
265+
const voteRationaleContext = await govActionDetailsPage.currentPage.getByTestId("vote-rationale-context");
266+
await expect(voteRationaleContext).toContainText(fakerContext);
274267
});
275268

276269
test("5I. Should view the vote details,when viewing governance action already voted by the DRep", async ({}, testInfo) => {
@@ -282,7 +275,7 @@ test.describe("Perform voting", () => {
282275
govActionDetailsPage.currentPage
283276
);
284277

285-
await governanceActionsPage.currentPage.waitForTimeout(5_000);
278+
await governanceActionsPage.getFirstProposal();
286279

287280
await governanceActionsPage.votedTab.click();
288281
await expect(

tests/govtool-frontend/playwright/tests/dRep.setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import kuberService from "@services/kuberService";
1212
import walletManager from "lib/walletManager";
1313
import { functionWaitedAssert } from "@helpers/waitedLoop";
1414
import { StaticWallet } from "@types";
15+
import { Logger } from "@helpers/logger";
1516

1617
const REGISTER_DREP_WALLETS_COUNT = 6;
17-
const DREP_WALLETS_COUNT = 10;
18+
const DREP_WALLETS_COUNT = 11;
1819

1920
let dRepDeposit: number;
2021

@@ -73,6 +74,7 @@ setup("Register DRep of static wallets", async () => {
7374
});
7475

7576
setup("Setup temporary DRep wallets", async () => {
77+
7678
const totalRequiredBalanceForDRepSetup =
7779
(DREP_WALLETS_COUNT + REGISTER_DREP_WALLETS_COUNT) *
7880
(dRepDeposit / 1000000 + 22);

0 commit comments

Comments
 (0)