Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions tests/govtool-frontend/playwright/lib/pages/outcomesPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,15 @@ export default class OutComesPage {

async searchOutcomesById(governanceActionId: string) {
await this.searchInput.fill(governanceActionId);
await expect(
this.page.getByRole("progressbar").getByRole("img")
).toBeVisible();

try {
await expect(
this.page.getByRole("progressbar").getByRole("img")
).toBeVisible();
} catch (error) {
// Handle the case where the progress bar is not visible
console.warn("Progress bar not visible, proceeding with search.");
}
await functionWaitedAssert(
async () => {
const idSearchOutcomeCards = await this.getAllOutcomes();
Expand All @@ -480,9 +485,14 @@ export default class OutComesPage {

async searchOutcomesByTitle(governanceActionTitle: string) {
await this.searchInput.fill(governanceActionTitle);
await expect(
this.page.getByRole("progressbar").getByRole("img")
).toBeVisible();
try {
await expect(
this.page.getByRole("progressbar").getByRole("img")
).toBeVisible();
} catch (error) {
// Handle the case where the progress bar is not visible
console.warn("Progress bar not visible, proceeding with search.");
}

await functionWaitedAssert(
async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, Locator, Page } from "@playwright/test";
import { ProposalCreateRequest, ProposalType, ProposedGovAction } from "@types";
import {
ProposalCreateRequest,
ProposalDiscussionFilterTypes,
ProposalType,
ProposedGovAction,
} from "@types";
import environments from "lib/constants/environments";
import ProposalDiscussionDetailsPage from "./proposalDiscussionDetailsPage";
import { functionWaitedAssert, waitedLoop } from "@helpers/waitedLoop";
Expand Down Expand Up @@ -147,16 +152,30 @@ export default class ProposalDiscussionPage {
}

async sortAndValidate(
option: "asc" | "desc",
type: ProposalDiscussionFilterTypes,
validationFn: (p1: ProposedGovAction, p2: ProposedGovAction) => boolean
) {
const sortMappings = {
"Name A-Z": "&sort[prop_name]=ASC",
"Name Z-A": "&sort[prop_name]=DESC",
"Most comments": "&sort[proposal][prop_comments_number]=DESC",
"Least comments": "&sort[proposal][prop_comments_number]=ASC",
"Most likes": "&sort[proposal][prop_likes]=DESC",
"Least likes": "&sort[proposal][prop_likes]=ASC",
"Most dislikes": "&sort[proposal][prop_dislikes]=DESC",
"Least dislikes": "&sort[proposal][prop_dislikes]=ASC",
Oldest: "&sort[createdAt]=ASC",
Newest: "&sort[createdAt]=DESC",
};

const urlParam = sortMappings[type];
const populateParam = "&populate[0]=proposal_links";
const responsePromise = this.page.waitForResponse((response) =>
response
.url()
.includes(`&sort[createdAt]=${option}&populate[0]=proposal_links`)
response.url().includes(`${urlParam}${populateParam}`)
);

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

let proposals: ProposedGovAction[] = (await response.json()).data;
Expand Down
21 changes: 21 additions & 0 deletions tests/govtool-frontend/playwright/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,17 @@ export type ProposedGovAction = {
attributes: {
gov_action_type_name: string;
prop_comments_number: number;
prop_likes: number;
prop_dislikes: number;
createdAt: string;
updatedAt: string;
content: {
id: string;
attributes: {
proposal_id: string;
prop_name: string;
};
};
creator: {
data: {
id: number;
Expand Down Expand Up @@ -547,3 +556,15 @@ export type BudgetProposalFilterTypes =
| "Name Z-A"
| "Proposer A-Z"
| "Proposer Z-A";

export type ProposalDiscussionFilterTypes =
| "Newest"
| "Oldest"
| "Most likes"
| "Least likes"
| "Most dislikes"
| "Least dislikes"
| "Most comments"
| "Least comments"
| "Name A-Z"
| "Name Z-A";
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ test.describe("Check vote count", () => {
: GovernanceActionType;
const responsesPromise = Object.keys(voteWhiteListOption).map((filterKey) =>
page.waitForResponse((response) =>
response.url().includes(`&type[]=${voteWhiteListOption[filterKey]}`)
response
.url()
.includes(
`proposal/list?page=0&pageSize=7&type[]=${voteWhiteListOption[filterKey]}`
)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { functionWaitedAssert } from "@helpers/waitedLoop";
import ProposalDiscussionDetailsPage from "@pages/proposalDiscussionDetailsPage";
import ProposalDiscussionPage from "@pages/proposalDiscussionPage";
import { expect } from "@playwright/test";
import { ProposalType } from "@types";
import {
ProposalDiscussionFilterTypes,
ProposalType,
ProposedGovAction,
} from "@types";

const mockProposal = require("../../lib/_mock/proposal.json");
const mockPoll = require("../../lib/_mock/proposalPoll.json");
Expand Down Expand Up @@ -65,15 +69,41 @@ test.describe("Filter and sort proposals", () => {
});

test("8B_2. Should sort the list of proposed governance actions.", async () => {
await proposalDiscussionPage.sortAndValidate(
"asc",
(p1, p2) => p1.attributes.createdAt <= p2.attributes.createdAt
);

await proposalDiscussionPage.sortAndValidate(
"desc",
(p1, p2) => p1.attributes.createdAt >= p2.attributes.createdAt
);
const sortOptions = {
Oldest: (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.createdAt <= p2.attributes.createdAt,
Newest: (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.createdAt >= p2.attributes.createdAt,
"Most likes": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_likes >= p2.attributes.prop_likes,
"Least likes": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_likes <= p2.attributes.prop_likes,
"Most dislikes": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_dislikes >= p2.attributes.prop_dislikes,
"Least dislikes": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_dislikes <= p2.attributes.prop_dislikes,
"Most comments": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_comments_number >=
p2.attributes.prop_comments_number,
"Least comments": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.prop_comments_number <=
p2.attributes.prop_comments_number,
"Name A-Z": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.content.attributes.prop_name.localeCompare(
p2.attributes.content.attributes.prop_name
) <= 0,
"Name Z-A": (p1: ProposedGovAction, p2: ProposedGovAction) =>
p1.attributes.content.attributes.prop_name.localeCompare(
p2.attributes.content.attributes.prop_name
) >= 0,
};

for (const [sortOption, sortFunction] of Object.entries(sortOptions)) {
await proposalDiscussionPage.sortAndValidate(
sortOption as ProposalDiscussionFilterTypes,
sortFunction
);
}
});
});

Expand Down