Skip to content

Commit 68f7292

Browse files
authored
Merge pull request #3691 from IntersectMBO/tests/budget-proposal-filter
Tests: budget proposal filter
2 parents 52b1e8a + 374b880 commit 68f7292

File tree

4 files changed

+103
-17
lines changed

4 files changed

+103
-17
lines changed

tests/govtool-frontend/playwright/lib/constants/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { faker } from "@faker-js/faker";
2-
import { InvalidMetadataType } from "@types";
2+
import { BudgetProposalFilterTypes, InvalidMetadataType } from "@types";
33

44
export const SECURITY_RELEVANT_PARAMS_MAP: Record<string, string> = {
55
maxBlockBodySize: "max_block_size",
@@ -61,3 +61,15 @@ export const InvalidMetadata: InvalidMetadataType[] = [
6161
hash: "e71bf6171adda3754a87fff5c2d8d9e404eb3366428a5be13f7e76357a39004f",
6262
},
6363
];
64+
65+
export const budgetProposalfilterOptionNames: Array<BudgetProposalFilterTypes> =
66+
[
67+
"Newest",
68+
"Oldest",
69+
"Most comments",
70+
"Least comments",
71+
"Name A-Z",
72+
"Name Z-A",
73+
"Proposer A-Z",
74+
"Proposer Z-A",
75+
];

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
22
import { expect, Locator, Page } from "@playwright/test";
3-
import { BudgetDiscussionEnum, ProposedGovAction } from "@types";
3+
import {
4+
BudgetDiscussionEnum,
5+
BudgetProposalFilterTypes,
6+
ProposedGovAction,
7+
} from "@types";
48
import environments from "lib/constants/environments";
59
import BudgetDiscussionDetailsPage from "./budgetDiscussionDetailsPage";
610

@@ -140,16 +144,29 @@ export default class BudgetDiscussionPage {
140144
}
141145

142146
async sortAndValidate(
143-
option: "asc" | "desc",
147+
type: BudgetProposalFilterTypes,
144148
validationFn: (p1: ProposedGovAction, p2: ProposedGovAction) => boolean
145149
) {
150+
const sortMappings = {
151+
"Proposer A-Z": "&sort[creator][govtool_username]=ASC",
152+
"Proposer Z-A": "&sort[creator][govtool_username]=DESC",
153+
"Name A-Z": "&sort[bd_proposal_detail][proposal_name]=ASC",
154+
"Name Z-A": "&sort[bd_proposal_detail][proposal_name]=DESC",
155+
"Most comments": "&sort[prop_comments_number]=DESC",
156+
"Least comments": "&sort[prop_comments_number]=ASC",
157+
Oldest: "&sort[createdAt]=ASC",
158+
Newest: "&sort[createdAt]=DESC",
159+
};
160+
161+
const urlParam = sortMappings[type];
162+
const populateParam = "&populate[0]=bd_costing";
163+
146164
const responsePromise = this.page.waitForResponse((response) =>
147-
response
148-
.url()
149-
.includes(`&sort[createdAt]=${option}&populate[0]=bd_costing`)
165+
response.url().includes(`${urlParam}${populateParam}`)
150166
);
151167

152168
await this.sortBtn.click();
169+
await this.page.getByTestId(`${type}-sort-option`).click();
153170
const response = await responsePromise;
154171

155172
let proposals: ProposedGovAction[] = (await response.json()).data;

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,29 @@ export type ProposalCreateRequest = {
196196
has_guardrails?: boolean;
197197
is_draft: boolean;
198198
};
199-
200199
export type ProposedGovAction = {
201200
id: number;
202201
attributes: {
203202
gov_action_type_name: string;
203+
prop_comments_number: number;
204204
createdAt: string;
205205
updatedAt: string;
206+
creator: {
207+
data: {
208+
id: number;
209+
attributes: {
210+
govtool_username: string;
211+
};
212+
};
213+
};
214+
bd_proposal_detail: {
215+
data: {
216+
id: number;
217+
attributes: {
218+
proposal_name: string;
219+
};
220+
};
221+
};
206222
};
207223
};
208224

@@ -521,3 +537,13 @@ export enum BudgetProposalStageEnum {
521537
}
522538

523539
export type VoterType = "DReps" | "SPOs" | "CC";
540+
541+
export type BudgetProposalFilterTypes =
542+
| "Newest"
543+
| "Oldest"
544+
| "Most comments"
545+
| "Least comments"
546+
| "Name A-Z"
547+
| "Name Z-A"
548+
| "Proposer A-Z"
549+
| "Proposer Z-A";

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import environments from "@constants/environments";
2+
import { budgetProposalfilterOptionNames } from "@constants/index";
23
import { faker } from "@faker-js/faker";
34
import { test } from "@fixtures/walletExtension";
45
import { setAllureEpic } from "@helpers/allure";
@@ -8,7 +9,11 @@ import { functionWaitedAssert } from "@helpers/waitedLoop";
89
import BudgetDiscussionDetailsPage from "@pages/budgetDiscussionDetailsPage";
910
import BudgetDiscussionPage from "@pages/budgetDiscussionPage";
1011
import { expect } from "@playwright/test";
11-
import { BudgetDiscussionEnum } from "@types";
12+
import {
13+
BudgetDiscussionEnum,
14+
BudgetProposalFilterTypes,
15+
ProposedGovAction,
16+
} from "@types";
1217

1318
const mockBudgetProposal = require("../../lib/_mock/budgetProposal.json");
1419
const mockPoll = require("../../lib/_mock/budgetProposalPoll.json");
@@ -103,15 +108,41 @@ test.describe("Budget proposal list manipulation", () => {
103108
});
104109

105110
test("11B_3. Should sort budget proposals", async () => {
106-
await budgetDiscussionPage.sortAndValidate(
107-
"asc",
108-
(p1, p2) => p1.attributes.createdAt <= p2.attributes.createdAt
109-
);
110-
111-
await budgetDiscussionPage.sortAndValidate(
112-
"desc",
113-
(p1, p2) => p1.attributes.createdAt >= p2.attributes.createdAt
114-
);
111+
const sortOptions = {
112+
Oldest: (p1: ProposedGovAction, p2: ProposedGovAction) =>
113+
p1.attributes.createdAt <= p2.attributes.createdAt,
114+
Newest: (p1: ProposedGovAction, p2: ProposedGovAction) =>
115+
p1.attributes.createdAt >= p2.attributes.createdAt,
116+
"Most comments": (p1: ProposedGovAction, p2: ProposedGovAction) =>
117+
p1.attributes.prop_comments_number >=
118+
p2.attributes.prop_comments_number,
119+
"Least comments": (p1: ProposedGovAction, p2: ProposedGovAction) =>
120+
p1.attributes.prop_comments_number <=
121+
p2.attributes.prop_comments_number,
122+
"Name A-Z": (p1: ProposedGovAction, p2: ProposedGovAction) =>
123+
p1.attributes.bd_proposal_detail.data.attributes.proposal_name.localeCompare(
124+
p2.attributes.bd_proposal_detail.data.attributes.proposal_name
125+
) <= 0,
126+
"Name Z-A": (p1: ProposedGovAction, p2: ProposedGovAction) =>
127+
p1.attributes.bd_proposal_detail.data.attributes.proposal_name.localeCompare(
128+
p2.attributes.bd_proposal_detail.data.attributes.proposal_name
129+
) >= 0,
130+
"Proposer A-Z": (p1: ProposedGovAction, p2: ProposedGovAction) =>
131+
p1.attributes.creator.data.attributes.govtool_username.localeCompare(
132+
p2.attributes.creator.data.attributes.govtool_username
133+
) <= 0,
134+
"Proposer Z-A": (p1: ProposedGovAction, p2: ProposedGovAction) =>
135+
p1.attributes.creator.data.attributes.govtool_username.localeCompare(
136+
p2.attributes.creator.data.attributes.govtool_username
137+
) >= 0,
138+
};
139+
140+
for (const [option, validationFn] of Object.entries(sortOptions)) {
141+
await budgetDiscussionPage.sortAndValidate(
142+
option as BudgetProposalFilterTypes,
143+
validationFn
144+
);
145+
}
115146
});
116147
});
117148
});

0 commit comments

Comments
 (0)