Skip to content

Commit d67b5b2

Browse files
committed
tests: sort budget proposal by asc and desc
1 parent 3a41668 commit d67b5b2

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
22
import { expect, Locator, Page } from "@playwright/test";
3-
import { BudgetProposalType } from "@types";
3+
import { BudgetProposalType, ProposedGovAction } from "@types";
44
import environments from "lib/constants/environments";
55

66
export default class BudgetDiscussionPage {
@@ -11,6 +11,7 @@ export default class BudgetDiscussionPage {
1111
);
1212
readonly verifyIdentityBtn = this.page.getByTestId("verify-identity-button");
1313
readonly filterBtn = this.page.getByTestId("filter-button");
14+
readonly sortBtn = this.page.getByTestId("sort-button");
1415

1516
// input
1617
readonly searchInput = this.page.getByTestId("search-input");
@@ -117,4 +118,30 @@ export default class BudgetDiscussionPage {
117118

118119
return filters.includes(govActionType);
119120
}
121+
122+
async sortAndValidate(
123+
option: "asc" | "desc",
124+
validationFn: (p1: ProposedGovAction, p2: ProposedGovAction) => boolean
125+
) {
126+
const responsePromise = this.page.waitForResponse((response) =>
127+
response
128+
.url()
129+
.includes(`&sort[createdAt]=${option}&populate[0]=bd_costing`)
130+
);
131+
132+
await this.sortBtn.click();
133+
const response = await responsePromise;
134+
135+
let proposals: ProposedGovAction[] = (await response.json()).data;
136+
137+
// API validation
138+
for (let i = 0; i <= proposals.length - 2; i++) {
139+
console.log(
140+
proposals[i].attributes.createdAt,
141+
proposals[i + 1].attributes.createdAt
142+
);
143+
const isValid = validationFn(proposals[i], proposals[i + 1]);
144+
expect(isValid).toBe(true);
145+
}
146+
}
120147
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ test.describe("Budget proposal list manipulation", () => {
9393
);
9494
});
9595

96-
test("11B_3. Should sort budget proposals", async ({}) => {});
96+
test("11B_3. Should sort budget proposals", async () => {
97+
await budgetDiscussionPage.sortAndValidate(
98+
"asc",
99+
(p1, p2) => p1.attributes.createdAt <= p2.attributes.createdAt
100+
);
101+
102+
await budgetDiscussionPage.sortAndValidate(
103+
"desc",
104+
(p1, p2) => p1.attributes.createdAt >= p2.attributes.createdAt
105+
);
106+
});
97107
});
98108
});
99109

0 commit comments

Comments
 (0)