Skip to content

Commit

Permalink
Merge pull request #9 from sireto/feat/random-sort
Browse files Browse the repository at this point in the history
Add random dRep test and fix test 2K_2 due to status
  • Loading branch information
kneerose authored Sep 27, 2024
2 parents 8cba5c6 + 1382590 commit 443aec5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
14 changes: 9 additions & 5 deletions tests/govtool-frontend/playwright/lib/pages/dRepDirectoryPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,22 @@ export default class DRepDirectoryPage {

async sortDRep(option: string) {}

async sortAndValidate(
option: string,
validationFn: (p1: IDRep, p2: IDRep) => boolean
) {
async getDRepsResponseFromApi(option: string): Promise<IDRep[]> {
const responsePromise = this.page.waitForResponse((response) =>
response.url().includes(`&sort=${option}`)
);

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

const dRepList: IDRep[] = (await response.json()).elements;
return (await response.json()).elements;
}

async sortAndValidate(
option: string,
validationFn: (p1: IDRep, p2: IDRep) => boolean
) {
const dRepList = await this.getDRepsResponseFromApi(option);

// API validation
for (let i = 0; i <= dRepList.length - 2; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ import { setAllureEpic } from "@helpers/allure";
import { skipIfNotHardFork } from "@helpers/cardano";
import DRepDirectoryPage from "@pages/dRepDirectoryPage";
import { expect, test } from "@playwright/test";
import { DRepStatus } from "@types";
import { DRepStatus, IDRep } from "@types";

test.beforeEach(async () => {
await setAllureEpic("2. Delegation");
await skipIfNotHardFork();
});

enum SortOption {
Random = "Random",
RegistrationDate = "RegistrationDate",
VotingPower = "VotingPower",
Status = "Status",
}

const statusRank: Record<DRepStatus, number> = {
Active: 1,
Inactive: 2,
Retired: 3,
};

test("2K_2. Should sort DReps", async ({ page }) => {
test.slow();

enum SortOption {
RegistrationDate = "RegistrationDate",
VotingPower = "VotingPower",
Status = "Status",
}

const dRepDirectory = new DRepDirectoryPage(page);
await dRepDirectory.goto();

Expand All @@ -33,10 +40,40 @@ test("2K_2. Should sort DReps", async ({ page }) => {
(d1, d2) => d1.votingPower >= d2.votingPower
);

await dRepDirectory.sortAndValidate(
SortOption.Status,
(d1, d2) => d1.status >= d2.status
await dRepDirectory.sortAndValidate(SortOption.Status, (d1, d2) => {
return statusRank[d1.status] <= statusRank[d2.status];
});
});

test("2K_3. Should sort DReps randomly", async ({ page }) => {
const dRepDirectory = new DRepDirectoryPage(page);
await dRepDirectory.goto();

await dRepDirectory.sortBtn.click();

await page.getByTestId(`${SortOption.RegistrationDate}-radio`).click();

const dRepList1: IDRep[] = await dRepDirectory.getDRepsResponseFromApi(
SortOption.Random
);

await page.getByTestId(`${SortOption.RegistrationDate}-radio`).click();

const dRepList2: IDRep[] = await dRepDirectory.getDRepsResponseFromApi(
SortOption.Random
);

// Extract dRepIds from both lists
const dRepIdsList1 = dRepList1.map((dRep) => dRep.drepId);
const dRepIdsList2 = dRepList2.map((dRep) => dRep.drepId);

expect(dRepList1.length).toEqual(dRepList2.length);

const isOrderDifferent = dRepIdsList1.some(
(id, index) => id !== dRepIdsList2[index]
);

expect(isOrderDifferent).toBe(true);
});

test("2O. Should load more DReps on show more", async ({ page }) => {
Expand Down

0 comments on commit 443aec5

Please sign in to comment.