Skip to content

Commit e964180

Browse files
committed
tests: search budget proposal by title
1 parent 78c1f23 commit e964180

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Page } from "@playwright/test";
1+
import { waitedLoop } from "@helpers/waitedLoop";
2+
import { expect, Page } from "@playwright/test";
23
import environments from "lib/constants/environments";
34

45
export default class BudgetDiscussionPage {
@@ -9,6 +10,9 @@ export default class BudgetDiscussionPage {
910
);
1011
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
1112

13+
// input
14+
readonly searchInput = this.page.getByTestId("search-input");
15+
1216
constructor(private readonly page: Page) {}
1317

1418
get currentPage(): Page {
@@ -20,4 +24,19 @@ export default class BudgetDiscussionPage {
2024
// wait for the proposal cards to load
2125
await this.page.waitForTimeout(2_000);
2226
}
27+
28+
async getAllProposals() {
29+
const proposalCardSelector =
30+
'[data-testid^="budget-discussion-"][data-testid$="-card"]';
31+
32+
await waitedLoop(async () => {
33+
const count = await this.page.locator(proposalCardSelector).count();
34+
return count > 0;
35+
});
36+
const proposalCards = await this.page.locator(proposalCardSelector).all();
37+
38+
expect(true, "No budget proposals found.").toBeTruthy();
39+
40+
return proposalCards;
41+
}
2342
}

tests/govtool-frontend/playwright/tests/11-proposal-budget/proposalBudget.spec.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { test } from "@fixtures/walletExtension";
22
import { setAllureEpic } from "@helpers/allure";
3+
import { functionWaitedAssert } from "@helpers/waitedLoop";
34
import BudgetDiscussionPage from "@pages/budgetDiscussionPage";
45
import { expect } from "@playwright/test";
56

67
test.beforeEach(async ({}) => {
78
await setAllureEpic("11. Proposal Budget");
89
});
910

10-
test("11A. Should access budget proposal page in disconnect state", async ({ page }) => {
11+
test("11A. Should access budget proposal page in disconnect state", async ({
12+
page,
13+
}) => {
1114
const budgetDiscussionPage = new BudgetDiscussionPage(page);
1215
await budgetDiscussionPage.goto();
1316

@@ -17,7 +20,58 @@ test("11A. Should access budget proposal page in disconnect state", async ({ pag
1720
});
1821

1922
test.describe("Budget proposal list manipulation", () => {
20-
test("11B_1. Should search for budget proposals by title", async ({}) => {});
23+
test("11B_1. Should search for budget proposals by title", async ({
24+
page,
25+
}) => {
26+
let proposalName = "EchoFeed";
27+
let proposalNameSet = false;
28+
29+
await page.route("**/api/bds?**", async (route) => {
30+
const response = await route.fetch();
31+
const json = await response.json();
32+
if (!proposalNameSet && "data" in json && json["data"].length > 0) {
33+
const randomIndex = Math.floor(Math.random() * json["data"].length);
34+
proposalName =
35+
json["data"][randomIndex]["attributes"]["bd_proposal_detail"]["data"][
36+
"attributes"
37+
]["proposal_name"];
38+
proposalNameSet = true;
39+
}
40+
await route.fulfill({
41+
status: 200,
42+
contentType: "application/json",
43+
body: JSON.stringify(json),
44+
});
45+
});
46+
47+
const responsePromise = page.waitForResponse("**/api/bds?**");
48+
const budgetDiscussionPage = new BudgetDiscussionPage(page);
49+
await budgetDiscussionPage.goto();
50+
51+
await responsePromise;
52+
53+
await budgetDiscussionPage.searchInput.fill(proposalName);
54+
55+
await page.waitForTimeout(2000);
56+
57+
await functionWaitedAssert(
58+
async () => {
59+
const proposalCards = await budgetDiscussionPage.getAllProposals();
60+
for (const proposalCard of proposalCards) {
61+
await expect(proposalCard).toBeVisible();
62+
const proposalTitle = await proposalCard
63+
.getByTestId("budget-discussion-title")
64+
.textContent();
65+
expect(proposalTitle.toLowerCase()).toContain(
66+
proposalName.toLowerCase()
67+
);
68+
}
69+
},
70+
{
71+
message: `A proposal card does not contain the search term ${proposalName}`,
72+
}
73+
);
74+
});
2175

2276
test("11B_2. Should filter budget proposals by categories", async ({}) => {});
2377

0 commit comments

Comments
 (0)