Skip to content

Commit 8193c6f

Browse files
authored
test: added tests for sort functionality on not raised exceptions page (#1428)
1 parent 43922df commit 8193c6f

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

application/CohortManager/src/Web/app/components/sortExceptionsForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function SortExceptionsForm({
3838
className="nhsuk-button app-button--small"
3939
data-module="nhsuk-button"
4040
type="submit"
41+
data-testid="apply-button"
4142
>
4243
Apply
4344
</button>

application/CohortManager/src/Web/tests/features/notRaisedExceptionOverview.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ Feature: testing Breast screening - Not raisedexception overview page
3333
Scenario: verify navigation to cookies screen
3434
And the user clicks on cookies link
3535
Then they should navigate to 'Cookies on Cohort Manager - Cohort Manager - NHS'
36+
37+
@epic_4a @req_6975 @test_9966
38+
Scenario: verify sorting by with Date exception created (newest first)
39+
When the user sorts the exception summary table by 'Date exception created (newest first)'
40+
Then the exception summary table should be sorted by Date exception created in descending order
41+
42+
@epic_4a @req_6975 @test_9974
43+
Scenario: verify sorting by with Date exception created (oldest first)
44+
When the user sorts the exception summary table by 'Date exception created (oldest first)'
45+
Then the exception summary table should be sorted by Date exception created in ascending order
46+
47+
@epic_4a @req_6975 @test_9968
48+
Scenario: verify sorting by with unsupported sort option
49+
When the user sorts with unsupported options by 'exception created (oldest first)'
50+
Then the error message should thrown

application/CohortManager/src/Web/tests/features/pages/exceptionOverviewPage.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { expect, Locator, Page } from "@playwright/test";
22
import BasePage from "./basePage";
3-
4-
53
export class ExceptionOverviewPage extends BasePage {
64
readonly page!: Page;
75
readonly exceptionTable: Locator;
86
readonly exceptiontableHeaders: Locator;
97
readonly homepageLink: Locator;
108
readonly exceptionIDLink: Locator;
9+
readonly sortByDateExceptionCreated: Locator;
10+
readonly applyButton: Locator;
1111

1212
constructor(page: Page) {
1313
super(page)
@@ -17,6 +17,8 @@ export class ExceptionOverviewPage extends BasePage {
1717
this.homepageLink = page.getByRole('link', { name: 'Home', exact: true });
1818
this.exceptionIDLink = page.locator('[data-testid="exceptions-table"] tbody tr:first-child td:nth-child(1) a');
1919
//this.exceptionIDLink = page.locator('[data-testid="exceptions-table"] tbody tr:nth-child(2) td:nth-child(1) a');
20+
this.sortByDateExceptionCreated = page.locator('[data-testid="sort-not-raised-exceptions"]');
21+
this.applyButton = page.locator('[data-testid="apply-button"]');
2022
}
2123
async getTableHeaders(): Promise<string[]> {
2224
return this.page.$$eval('[data-testid="exceptions-table"] th', headers =>
@@ -39,11 +41,20 @@ export class ExceptionOverviewPage extends BasePage {
3941
// Optionally, check for clickable/sortable role
4042
const role = await headers.nth(i).getAttribute('role');
4143
expect(role).not.toBe('button');
42-
4344
}
4445
}
4546
async clickOnexceptionID() {
4647
await this.clickElement(this.exceptionIDLink)
4748
}
49+
async sortByDateExceptionCreatedDescending(optionText: string) {
50+
// Adjust selector to match your sortable column header
51+
await this.sortByDateExceptionCreated.selectOption({ label: optionText });
52+
await this.applyButton.click();
53+
}
54+
async getDateExceptionCreatedColumn(): Promise<Date[]> {
55+
// Adjust selector to match the correct column index for "Date exception created"
56+
const dateCells = await this.page.locator('[data-testid="exceptions-table"] tbody tr td:nth-child(3)').allTextContents();
57+
return dateCells.map(text => new Date(text.trim()));
58+
}
4859

4960
}

application/CohortManager/src/Web/tests/features/steps/exceptionoverviewSteps.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,43 @@ Given('the user navigate to not raised exception overview page', async ({ page }
4444
await page.waitForTimeout(3000);
4545

4646
});
47+
When('the user sorts the exception summary table by {string}', async ({ page }, sortOption: string) => {
48+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
49+
await exceptionOverviewPage.sortByDateExceptionCreatedDescending(sortOption);
50+
await page.waitForTimeout(3000);
51+
});
52+
Then('the exception summary table should be sorted by Date exception created in descending order', async ({ page }) => {
53+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
54+
const dates = await exceptionOverviewPage.getDateExceptionCreatedColumn();
55+
const sorted = [...dates].sort((a, b) => b.getTime() - a.getTime());
56+
expect(dates).toEqual(sorted);
57+
});
58+
Then('the exception summary table should be sorted by Date exception created in ascending order', async ({ page }) => {
59+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
60+
const dates = await exceptionOverviewPage.getDateExceptionCreatedColumn();
61+
const sorted = [...dates].sort((a, b) => a.getTime() - b.getTime());
62+
expect(dates).toEqual(sorted);
63+
});
64+
// Use a WeakMap to store sort errors per context
65+
const sortErrorMap = new WeakMap();
66+
When('the user sorts with unsupported options by {string}', async ({ page }, sortOption: string) => {
67+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
68+
try {
69+
await Promise.race([
70+
exceptionOverviewPage.sortByDateExceptionCreatedDescending(sortOption),
71+
new Promise((_, reject) => setTimeout(() => reject(new Error('Custom timeout')), 3000))
72+
]);
73+
sortErrorMap.set(page.context(), null);
74+
} catch (error) {
75+
sortErrorMap.set(page.context(), error);
76+
}
77+
});
78+
Then('the error message should thrown', async ({ page }) => {
79+
// Retrieve the error from the WeakMap for this context
80+
const error = sortErrorMap.get(page.context());
81+
expect(error).toBeDefined();
82+
expect(
83+
error.message.includes('did not find some options') ||
84+
error.message.includes('Custom timeout')
85+
).toBe(true);
86+
});

0 commit comments

Comments
 (0)