Skip to content

Commit db0dcb5

Browse files
authored
test: added tests for sort functionality for raised exceptions (#1439)
1 parent 5db5f34 commit db0dcb5

4 files changed

Lines changed: 53 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class ExceptionOverviewPage extends BasePage {
88
readonly exceptionIDLink: Locator;
99
readonly sortByDateExceptionCreated: Locator;
1010
readonly applyButton: Locator;
11+
readonly sortByexceptionstatus
1112

1213
constructor(page: Page) {
1314
super(page)
@@ -19,6 +20,7 @@ export class ExceptionOverviewPage extends BasePage {
1920
//this.exceptionIDLink = page.locator('[data-testid="exceptions-table"] tbody tr:nth-child(2) td:nth-child(1) a');
2021
this.sortByDateExceptionCreated = page.locator('[data-testid="sort-not-raised-exceptions"]');
2122
this.applyButton = page.locator('[data-testid="apply-button"]');
23+
this.sortByexceptionstatus = page.locator('[data-testid="sort-raised-exceptions"]');
2224
}
2325
async getTableHeaders(): Promise<string[]> {
2426
return this.page.$$eval('[data-testid="exceptions-table"] th', headers =>
@@ -46,15 +48,29 @@ export class ExceptionOverviewPage extends BasePage {
4648
async clickOnexceptionID() {
4749
await this.clickElement(this.exceptionIDLink)
4850
}
49-
async sortByDateExceptionCreatedDescending(optionText: string) {
51+
async sortOptionSelect(optionText: string) {
5052
// Adjust selector to match your sortable column header
51-
await this.sortByDateExceptionCreated.selectOption({ label: optionText });
53+
if (optionText.toLowerCase().includes('date exception created')) {
54+
// Use the locator for "Date exception created"
55+
await this.sortByDateExceptionCreated.selectOption({ label: optionText });
56+
} else {
57+
// Use the locator for another column (replace with your actual locator)
58+
await this.sortByexceptionstatus.selectOption({ label: optionText });
59+
}
5260
await this.applyButton.click();
5361
}
5462
async getDateExceptionCreatedColumn(): Promise<Date[]> {
5563
// Adjust selector to match the correct column index for "Date exception created"
5664
const dateCells = await this.page.locator('[data-testid="exceptions-table"] tbody tr td:nth-child(3)').allTextContents();
5765
return dateCells.map(text => new Date(text.trim()));
5866
}
67+
async getStatusUpdateDates(): Promise<Date[]> {
68+
const texts = await this.page.locator('[data-testid="exceptions-table"] tbody tr td:nth-child(5)').allTextContents();
69+
// Extract date from "Raised on 16 June 2025"
70+
return texts.map(text => {
71+
const match = text.match(/on (.+)$/); // match "on <date>"
72+
return match ? new Date(match[1]) : new Date(0); // fallback to epoch if no match
73+
});
74+
}
5975

6076
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ Feature: testing Breast screening - exception 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_6389 @test_9447
38+
Scenario: verify sorting by with Status last updated (most recent first)
39+
When the user sorts the exception summary table by 'Status last updated (most recent first)'
40+
Then the exceptions should be sorted by exception status last updated in descending order
41+
42+
@epic_4a @req_6389 @test_9437
43+
Scenario: verify sorting by with Status last updated (oldest first)
44+
When the user sorts the exception summary table by 'Status last updated (oldest first)'
45+
Then the exceptions should be sorted by exception status last updated in ascending order
46+
47+
@epic_4a @req_6389 @test_9449
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/steps/exceptionoverviewSteps.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Given('the user navigate to not raised exception overview page', async ({ page }
4646
});
4747
When('the user sorts the exception summary table by {string}', async ({ page }, sortOption: string) => {
4848
const exceptionOverviewPage = new ExceptionOverviewPage(page);
49-
await exceptionOverviewPage.sortByDateExceptionCreatedDescending(sortOption);
49+
await exceptionOverviewPage.sortOptionSelect(sortOption);
5050
await page.waitForTimeout(3000);
5151
});
5252
Then('the exception summary table should be sorted by Date exception created in descending order', async ({ page }) => {
@@ -61,13 +61,25 @@ Then('the exception summary table should be sorted by Date exception created in
6161
const sorted = [...dates].sort((a, b) => a.getTime() - b.getTime());
6262
expect(dates).toEqual(sorted);
6363
});
64+
Then('the exceptions should be sorted by exception status last updated in descending order', async ({ page }) => {
65+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
66+
const dates = await exceptionOverviewPage.getStatusUpdateDates();
67+
const isDescending = dates.every((d, i, arr) => i === 0 || arr[i - 1].getTime() >= d.getTime());
68+
expect(isDescending).toBe(true);
69+
});
70+
Then('the exceptions should be sorted by exception status last updated in ascending order', async ({ page }) => {
71+
const exceptionOverviewPage = new ExceptionOverviewPage(page);
72+
const dates = await exceptionOverviewPage.getStatusUpdateDates();
73+
const isAscending = dates.every((d, i, arr) => i === 0 || arr[i - 1].getTime() <= d.getTime());
74+
expect(isAscending).toBe(true);
75+
});
6476
// Use a WeakMap to store sort errors per context
6577
const sortErrorMap = new WeakMap();
6678
When('the user sorts with unsupported options by {string}', async ({ page }, sortOption: string) => {
6779
const exceptionOverviewPage = new ExceptionOverviewPage(page);
6880
try {
6981
await Promise.race([
70-
exceptionOverviewPage.sortByDateExceptionCreatedDescending(sortOption),
82+
exceptionOverviewPage.sortOptionSelect(sortOption),
7183
new Promise((_, reject) => setTimeout(() => reject(new Error('Custom timeout')), 3000))
7284
]);
7385
sortErrorMap.set(page.context(), null);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ export const { Given, When, Then } = createBdd(test);
1212
const { AfterScenario } = createBdd(test);
1313

1414
AfterScenario(async ({ page }) => {
15+
// Scroll to bottom
16+
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
17+
await page.waitForTimeout(1000); // Wait for video to capture the bottom
1518
// runs after each scenario
1619
await page.evaluate(() => window.scrollTo(0, 0));
1720
await page.waitForTimeout(1000);
21+
// Take a screenshot after each scenario
22+
const timestamp = Date.now();
23+
await page.screenshot({ path: `screenshots/afterScenario_${timestamp}.png`, fullPage: true });
1824
});

0 commit comments

Comments
 (0)