Skip to content

Commit 3a41668

Browse files
committed
tests: budget proposal filter
1 parent e964180 commit 3a41668

File tree

3 files changed

+109
-4
lines changed

3 files changed

+109
-4
lines changed

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

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { waitedLoop } from "@helpers/waitedLoop";
2-
import { expect, Page } from "@playwright/test";
1+
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
2+
import { expect, Locator, Page } from "@playwright/test";
3+
import { BudgetProposalType } from "@types";
34
import environments from "lib/constants/environments";
45

56
export default class BudgetDiscussionPage {
@@ -9,6 +10,7 @@ export default class BudgetDiscussionPage {
910
"propose-a-budget-discussion-button"
1011
);
1112
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
13+
readonly filterBtn = this.page.getByTestId("filter-button");
1214

1315
// input
1416
readonly searchInput = this.page.getByTestId("search-input");
@@ -39,4 +41,80 @@ export default class BudgetDiscussionPage {
3941

4042
return proposalCards;
4143
}
44+
45+
async clickRadioButtonsByNames(names: string[]) {
46+
for (const name of names) {
47+
const budgetProposalValue = Object.values(BudgetProposalType).includes(
48+
name as BudgetProposalType
49+
);
50+
if (budgetProposalValue) {
51+
await this.page.getByLabel(name).click();
52+
}
53+
}
54+
}
55+
56+
async filterProposalByNames(names: string[]) {
57+
await this.clickRadioButtonsByNames(names);
58+
}
59+
60+
async unFilterProposalByNames(names: string[]) {
61+
await this.clickRadioButtonsByNames(names);
62+
}
63+
64+
async applyAndValidateFilters(
65+
filters: string[],
66+
validateFunction: (proposalCard: any, filters: string[]) => Promise<boolean>
67+
) {
68+
await this.page.waitForTimeout(4_000); // wait for the proposals to load
69+
// single filter
70+
for (const filter of filters) {
71+
await this.filterProposalByNames([filter]);
72+
await this.validateFilters([filter], validateFunction);
73+
await this.unFilterProposalByNames([filter]);
74+
}
75+
76+
// multiple filter
77+
const multipleFilters = [...filters];
78+
while (multipleFilters.length > 1) {
79+
await this.filterProposalByNames(multipleFilters);
80+
await this.validateFilters(multipleFilters, validateFunction);
81+
await this.unFilterProposalByNames(multipleFilters);
82+
multipleFilters.pop();
83+
}
84+
}
85+
86+
async validateFilters(
87+
filters: string[],
88+
validateFunction: (proposalCard: any, filters: string[]) => Promise<boolean>
89+
) {
90+
await functionWaitedAssert(async () => {
91+
const proposalCards = await this.getAllProposals();
92+
93+
for (const proposalCard of proposalCards) {
94+
if (await proposalCard.isVisible()) {
95+
const type = await proposalCard
96+
.getByTestId("budget-proposal-type")
97+
.textContent();
98+
const hasFilter = await validateFunction(proposalCard, filters);
99+
100+
expect(
101+
hasFilter,
102+
!hasFilter &&
103+
`A budget proposal type ${type} does not contain on ${filters}`
104+
).toBe(true);
105+
}
106+
}
107+
});
108+
}
109+
110+
async _validateTypeFiltersInProposalCard(
111+
proposalCard: Locator,
112+
filters: string[]
113+
): Promise<boolean> {
114+
const govActionType = await proposalCard
115+
.getByTestId("budget-proposal-type")
116+
.textContent();
117+
118+
return filters.includes(govActionType);
119+
}
42120
}

tests/govtool-frontend/playwright/lib/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,11 @@ export interface InvalidMetadataType {
323323
url: string;
324324
hash: string;
325325
}
326+
327+
export enum BudgetProposalType {
328+
Core = "Core",
329+
Research = "Research",
330+
GovernanceSupport = "Governance Support",
331+
MarketingAndInnovation = "Marketing & Innovation",
332+
NoCategory = "No Category",
333+
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { setAllureEpic } from "@helpers/allure";
33
import { functionWaitedAssert } from "@helpers/waitedLoop";
44
import BudgetDiscussionPage from "@pages/budgetDiscussionPage";
55
import { expect } from "@playwright/test";
6+
import { BudgetProposalType } from "@types";
67

78
test.beforeEach(async ({}) => {
89
await setAllureEpic("11. Proposal Budget");
@@ -73,9 +74,27 @@ test.describe("Budget proposal list manipulation", () => {
7374
);
7475
});
7576

76-
test("11B_2. Should filter budget proposals by categories", async ({}) => {});
77+
test.describe("Filter and sort budget proposals", () => {
78+
let budgetDiscussionPage: BudgetDiscussionPage;
7779

78-
test("11B_3. Should sort budget proposals", async ({}) => {});
80+
test.beforeEach(async ({ page }) => {
81+
budgetDiscussionPage = new BudgetDiscussionPage(page);
82+
await budgetDiscussionPage.goto();
83+
});
84+
85+
test("11B_2. Should filter budget proposals by categories", async () => {
86+
test.slow();
87+
await budgetDiscussionPage.filterBtn.click();
88+
89+
// proposal type filter
90+
await budgetDiscussionPage.applyAndValidateFilters(
91+
Object.values(BudgetProposalType),
92+
budgetDiscussionPage._validateTypeFiltersInProposalCard
93+
);
94+
});
95+
96+
test("11B_3. Should sort budget proposals", async ({}) => {});
97+
});
7998
});
8099

81100
test("11C. Should show view-all categorized budget proposal", async ({}) => {});

0 commit comments

Comments
 (0)