Skip to content

Commit 716d9f4

Browse files
authored
Merge pull request #3059 from IntersectMBO/bugfix/remaining-failing-test
Bugfix: remaining failing test
2 parents 04adf32 + ccd08e9 commit 716d9f4

File tree

12 files changed

+350
-158
lines changed

12 files changed

+350
-158
lines changed

tests/govtool-frontend/playwright/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ lib/_mock/registerDRepCopyWallets.json
2121
lib/_mock/registeredDRepCopyWallets.json
2222
lib/_mock/wallets.json
2323
lib/_mock/proposals.json
24+
lib/_mock/protocolParameter.json
2425
./lock_logs.txt

tests/govtool-frontend/playwright/lib/forms/dRepForm.ts

Lines changed: 104 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const formErrors = {
1313
linkDescription: "max-80-characters-error",
1414
email: "invalid-email-address-error",
1515
links: {
16-
url:"link-reference-description-1-error",
16+
url: "link-reference-description-1-error",
1717
description: "link-reference-description-1-error",
1818
},
1919
identity: {
@@ -160,21 +160,52 @@ export default class DRepForm {
160160
for (const err of formErrors.dRepName) {
161161
await expect(this.form.getByTestId(err)).toBeHidden();
162162
}
163+
const objectivesInputText = await this.objectivesInput.textContent();
164+
const motivationsInputText = await this.motivationsInput.textContent();
165+
const qualificationsInputText =
166+
await this.qualificationsInput.textContent();
167+
const isReferenceLinkErrorVisible = await this.form
168+
.getByTestId(formErrors.links.url)
169+
.isVisible();
170+
const isIdentityLinkErrorVisible = await this.form
171+
.getByTestId(formErrors.identity.url)
172+
.isVisible();
173+
const isPaymentAddressErrorVisible = await this.form
174+
.getByTestId(formErrors.paymentAddress)
175+
.isVisible();
163176

164-
expect(await this.objectivesInput.textContent()).toEqual(
165-
dRepInfo.objectives
166-
);
177+
expect(await this.objectivesInput.textContent(), {
178+
message:
179+
objectivesInputText !== dRepInfo.objectives &&
180+
`${dRepInfo.objectives} is not equal to ${await this.objectivesInput.textContent()}`,
181+
}).toEqual(dRepInfo.objectives);
167182

168-
expect(await this.motivationsInput.textContent()).toEqual(
169-
dRepInfo.motivations
170-
);
171-
expect(await this.qualificationsInput.textContent()).toEqual(
172-
dRepInfo.qualifications
173-
);
183+
expect(await this.motivationsInput.textContent(), {
184+
message:
185+
motivationsInputText !== dRepInfo.motivations &&
186+
`${dRepInfo.motivations} is not equal to ${await this.motivationsInput.textContent()}`,
187+
}).toEqual(dRepInfo.motivations);
188+
expect(await this.qualificationsInput.textContent(), {
189+
message:
190+
qualificationsInputText !== dRepInfo.qualifications &&
191+
`${dRepInfo.qualifications} is not equal to ${await this.qualificationsInput.textContent()}`,
192+
}).toEqual(dRepInfo.qualifications);
174193

175-
await expect(this.form.getByTestId(formErrors.links.url)).toBeHidden();
176-
await expect(this.form.getByTestId(formErrors.identity.url)).toBeHidden();
177-
await expect(this.form.getByTestId(formErrors.paymentAddress)).toBeHidden();
194+
await expect(this.form.getByTestId(formErrors.links.url), {
195+
message:
196+
isReferenceLinkErrorVisible &&
197+
`${dRepInfo.linksReferenceLinks[0].url} is an invalid url`,
198+
}).toBeHidden();
199+
await expect(this.form.getByTestId(formErrors.identity.url), {
200+
message:
201+
isIdentityLinkErrorVisible &&
202+
`${dRepInfo.identityReferenceLinks[0].url} is an invalid url`,
203+
}).toBeHidden();
204+
await expect(this.form.getByTestId(formErrors.paymentAddress), {
205+
message:
206+
isPaymentAddressErrorVisible &&
207+
`${dRepInfo.paymentAddress} is an invalid paymentAddress`,
208+
}).toBeHidden();
178209
await expect(this.continueBtn).toBeEnabled();
179210
}
180211

@@ -200,28 +231,68 @@ export default class DRepForm {
200231

201232
expect(nameErrors.length).toBeGreaterThanOrEqual(1);
202233

203-
await expect(
204-
this.form.getByTestId(formErrors.paymentAddress)
205-
).toBeVisible();
234+
const objectivesInputText = await this.objectivesInput.textContent();
235+
const motivationsInputText = await this.motivationsInput.textContent();
236+
const qualificationsInputText =
237+
await this.qualificationsInput.textContent();
238+
const isReferenceLinkErrorVisible = await this.form
239+
.getByTestId(formErrors.links.url)
240+
.isVisible();
241+
const isReferenceLinkDescriptionErrorVisible = await this.form
242+
.getByTestId(formErrors.links.description)
243+
.isVisible();
244+
const isIdentityLinkErrorVisible = await this.form
245+
.getByTestId(formErrors.identity.url)
246+
.isVisible();
247+
const isIdentityLinkDescriptionErrorVisible = await this.form
248+
.getByTestId(formErrors.identity.description)
249+
.isVisible();
250+
const isPaymentAddressErrorVisible = await this.form
251+
.getByTestId(formErrors.paymentAddress)
252+
.isVisible();
206253

207-
expect(await this.objectivesInput.textContent()).not.toEqual(
208-
dRepInfo.objectives
209-
);
210-
expect(await this.motivationsInput.textContent()).not.toEqual(
211-
dRepInfo.qualifications
212-
);
213-
expect(await this.qualificationsInput.textContent()).not.toEqual(
214-
dRepInfo.qualifications
215-
);
254+
await expect(this.form.getByTestId(formErrors.paymentAddress), {
255+
message:
256+
!isPaymentAddressErrorVisible &&
257+
`${dRepInfo.paymentAddress} is a valid paymentAddress`,
258+
}).toBeVisible();
259+
260+
expect(await this.objectivesInput.textContent(), {
261+
message:
262+
objectivesInputText === dRepInfo.objectives &&
263+
`${dRepInfo.objectives} is equal to ${await this.objectivesInput.textContent()}`,
264+
}).not.toEqual(dRepInfo.objectives);
265+
expect(await this.motivationsInput.textContent(), {
266+
message:
267+
motivationsInputText === dRepInfo.motivations &&
268+
`${dRepInfo.motivations} is equal to ${await this.motivationsInput.textContent()}`,
269+
}).not.toEqual(dRepInfo.qualifications);
270+
expect(await this.qualificationsInput.textContent(), {
271+
message:
272+
qualificationsInputText === dRepInfo.qualifications &&
273+
`${dRepInfo.qualifications} is equal to ${await this.qualificationsInput.textContent()}`,
274+
}).not.toEqual(dRepInfo.qualifications);
216275

217-
await expect(this.form.getByTestId(formErrors.links.url)).toBeVisible();
218-
await expect(
219-
this.form.getByTestId(formErrors.links.description)
220-
).toBeVisible();
221-
await expect(this.form.getByTestId(formErrors.identity.url)).toBeVisible();
222-
await expect(
223-
this.form.getByTestId(formErrors.identity.description)
224-
).toBeVisible();
276+
await expect(this.form.getByTestId(formErrors.links.url), {
277+
message:
278+
!isReferenceLinkErrorVisible &&
279+
`${dRepInfo.linksReferenceLinks[0].url} is a valid url`,
280+
}).toBeVisible();
281+
await expect(this.form.getByTestId(formErrors.links.description), {
282+
message:
283+
!isReferenceLinkDescriptionErrorVisible &&
284+
`${dRepInfo.linksReferenceLinks[0].description} is a valid description`,
285+
}).toBeVisible();
286+
await expect(this.form.getByTestId(formErrors.identity.url), {
287+
message:
288+
!isIdentityLinkErrorVisible &&
289+
`${dRepInfo.identityReferenceLinks[0].url} is a valid url`,
290+
}).toBeVisible();
291+
await expect(this.form.getByTestId(formErrors.identity.description), {
292+
message:
293+
!isIdentityLinkDescriptionErrorVisible &&
294+
`${dRepInfo.identityReferenceLinks[0].description} is a valid description`,
295+
}).toBeVisible();
225296

226297
await expect(this.continueBtn).toBeDisabled();
227298
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import kuberService from "@services/kuberService";
44
import { ProposalType, ProtocolParams } from "@types";
55
import { allure } from "allure-playwright";
66
import { bech32 } from "bech32";
7+
import { functionWaitedAssert } from "./waitedLoop";
8+
import { createFile, getFile } from "./file";
79

810
export function lovelaceToAda(lovelace: number) {
911
if (lovelace === 0) return 0;
@@ -17,8 +19,16 @@ export function generateWalletAddress() {
1719
}
1820

1921
export async function getProtocolParamsMajorVersion() {
20-
const protocolParameter: ProtocolParams =
21-
await kuberService.queryProtocolParams();
22+
let protocolParameter = await getFile("protocolParameter.json");
23+
if (protocolParameter === undefined) {
24+
await functionWaitedAssert(
25+
async () => {
26+
protocolParameter = await kuberService.queryProtocolParams();
27+
await createFile("protocolParameter.json", protocolParameter);
28+
},
29+
{ name: "queryProtocolParams" }
30+
);
31+
}
2232
return protocolParameter.protocolVersion.major;
2333
}
2434

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFile } from "fs";
1+
import { readFile, writeFile } from "fs";
22
const path = require("path");
33

44
const baseFilePath = path.resolve(__dirname, "../_mock");
@@ -18,3 +18,20 @@ export async function createFile(fileName: string, data?: any) {
1818
)
1919
);
2020
}
21+
22+
export async function getFile(fileName: string): Promise<any> {
23+
const data: string = await new Promise((resolve, reject) =>
24+
readFile(`${baseFilePath}/${fileName}`, "utf8", (err, data) => {
25+
if (err) {
26+
if (err.code === "ENOENT") {
27+
resolve(undefined);
28+
} else {
29+
reject(err);
30+
}
31+
} else {
32+
resolve(data);
33+
}
34+
})
35+
);
36+
return data ? JSON.parse(data) : undefined;
37+
}

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ export default class DRepDirectoryPage {
6868
async filterDReps(filterOptions: string[]) {
6969
for (const option of filterOptions) {
7070
await this.page.getByTestId(`${option}-checkbox`).click();
71-
if (option !== "Active" && filterOptions.length === 1) {
72-
await this.page.getByTestId(`Active-checkbox`).click();
73-
}
7471
}
7572
}
7673

@@ -143,20 +140,28 @@ export default class DRepDirectoryPage {
143140
const isValid = validationFn(dRepList[i], dRepList[i + 1]);
144141
expect(isValid).toBe(true);
145142
}
146-
// Frontend validation
147-
const cip105DRepListFE = await this.getAllListedCIP105DRepIds();
148-
const cip129DRepListFE = await this.getAllListedCIP129DRepIds();
149143

150-
const cip129DRepListApi = dRepList.map((dRep) =>
151-
convertDRepToCIP129(dRep.drepId, dRep.isScriptBased)
152-
);
144+
await functionWaitedAssert(
145+
async () => {
146+
// Frontend validation
147+
const cip105DRepListFE = await this.getAllListedCIP105DRepIds();
148+
const cip129DRepListFE = await this.getAllListedCIP129DRepIds();
153149

154-
for (let i = 0; i <= cip105DRepListFE.length - 1; i++) {
155-
await expect(cip129DRepListFE[i]).toHaveText(cip129DRepListApi[i]);
156-
await expect(cip105DRepListFE[i]).toHaveText(
157-
`(CIP-105) ${dRepList[i].view}`
158-
);
159-
}
150+
const cip129DRepListApi = dRepList.map((dRep) =>
151+
convertDRepToCIP129(dRep.drepId, dRep.isScriptBased)
152+
);
153+
154+
for (let i = 0; i <= cip105DRepListFE.length - 1; i++) {
155+
await expect(cip129DRepListFE[i], {
156+
message: `Cip129 dRep Id from Api:${cip129DRepListApi[i]} is not equal to ${await cip129DRepListFE[i].textContent()} on sort ${option}`,
157+
}).toHaveText(cip129DRepListApi[i]);
158+
await expect(cip105DRepListFE[i], {
159+
message: `Cip105 dRep Id from Api:${dRepList[i].view} is not equal to ${await cip105DRepListFE[i].textContent()} on sort ${option}`,
160+
}).toHaveText(`(CIP-105) ${dRepList[i].view}`);
161+
}
162+
},
163+
{ name: `frontend sort validation of ${option}` }
164+
);
160165
}
161166
getDRepCard(dRepId: string) {
162167
return this.page.getByTestId(`${dRepId}-drep-card`);
@@ -194,8 +199,15 @@ export default class DRepDirectoryPage {
194199
await this.goto();
195200

196201
await this.searchInput.fill(dRepId);
197-
198-
await expect(this.page.getByText("No DReps found")).toBeVisible({
202+
const isEmptyContainerVisible = await this.page
203+
.getByText("No DReps found")
204+
.isVisible();
205+
206+
await expect(this.page.getByText("No DReps found"), {
207+
message:
208+
!isEmptyContainerVisible &&
209+
`DRep with id ${dRepId} is found in the list`,
210+
}).toBeVisible({
199211
timeout: 20_000,
200212
});
201213
}

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

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GovernanceActionType, IProposal } from "@types";
44
import environments from "lib/constants/environments";
55
import GovernanceActionDetailsPage from "./governanceActionDetailsPage";
66
import { getEnumKeyByValue } from "@helpers/enum";
7-
import { waitedLoop } from "@helpers/waitedLoop";
7+
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
88

99
const MAX_SLIDES_DISPLAY_PER_TYPE = 6;
1010

@@ -106,18 +106,20 @@ export default class GovernanceActionsPage {
106106
}
107107

108108
async validateFilters(filters: string[]) {
109-
const proposalCards = await this.getAllProposals();
110-
111-
for (const proposalCard of proposalCards) {
112-
const hasFilter = await this._validateFiltersInProposalCard(
113-
proposalCard,
114-
filters
115-
);
116-
expect(
117-
hasFilter,
118-
"A proposal card does not contain any of the filters"
119-
).toBe(true);
120-
}
109+
await functionWaitedAssert(async () => {
110+
const proposalCards = await this.getAllProposals();
111+
112+
for (const proposalCard of proposalCards) {
113+
const hasFilter = await this._validateFiltersInProposalCard(
114+
proposalCard,
115+
filters
116+
);
117+
expect(
118+
hasFilter,
119+
`A proposal card does not contain any of the ${filters}`
120+
).toBe(true);
121+
}
122+
});
121123
}
122124

123125
async sortProposal(option: string) {
@@ -167,29 +169,36 @@ export default class GovernanceActionsPage {
167169
this.page.getByRole("progressbar").getByRole("img")
168170
).toBeHidden({ timeout: 20_000 });
169171

170-
// Frontend validation
171-
for (let dIdx = 0; dIdx <= proposalsByType.length - 1; dIdx++) {
172-
const proposals = proposalsByType[0] as IProposal[];
173-
const filterOptionKey = getEnumKeyByValue(
174-
GovernanceActionType,
175-
proposals[0].type
176-
);
177-
178-
const slides = await this.page
179-
.locator(`[data-testid="govaction-${filterOptionKey}-card"]`)
180-
.all();
181-
182-
const actualSlidesInDisplay =
183-
proposals.length > MAX_SLIDES_DISPLAY_PER_TYPE
184-
? MAX_SLIDES_DISPLAY_PER_TYPE
185-
: proposals.length;
186-
187-
expect(slides).toHaveLength(actualSlidesInDisplay);
188-
189-
for (let i = 0; i <= slides.length - 1; i++) {
190-
await expect(slides[i]).toContainText(`${proposals[i].txHash}`);
172+
await functionWaitedAssert(
173+
async () => {
174+
// Frontend validation
175+
for (let dIdx = 0; dIdx <= proposalsByType.length - 1; dIdx++) {
176+
const proposals = proposalsByType[0] as IProposal[];
177+
const filterOptionKey = getEnumKeyByValue(
178+
GovernanceActionType,
179+
proposals[0].type
180+
);
181+
182+
const slides = await this.page
183+
.locator(`[data-testid="govaction-${filterOptionKey}-card"]`)
184+
.all();
185+
186+
const actualSlidesInDisplay =
187+
proposals.length > MAX_SLIDES_DISPLAY_PER_TYPE
188+
? MAX_SLIDES_DISPLAY_PER_TYPE
189+
: proposals.length;
190+
191+
expect(slides).toHaveLength(actualSlidesInDisplay);
192+
193+
for (let i = 0; i <= slides.length - 1; i++) {
194+
await expect(slides[i]).toContainText(`${proposals[i].txHash}`);
195+
}
196+
}
197+
},
198+
{
199+
name: `frontend sort validation of ${sortOption} and filter ${filterKeys}`,
191200
}
192-
}
201+
);
193202
}
194203

195204
async _validateFiltersInProposalCard(

0 commit comments

Comments
 (0)