Skip to content

Commit 442caa8

Browse files
committed
Added ServiceNotFound object for use in cancel-date-range.spec.ts
1 parent ac8e931 commit 442caa8

2 files changed

Lines changed: 35 additions & 33 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type Locator, type Page } from '@playwright/test';
2+
import RootPage from './root';
3+
4+
export default class ServiceNotFoundPage extends RootPage {
5+
readonly title: Locator;
6+
7+
constructor(page: Page) {
8+
super(page);
9+
this.title = page.getByRole('heading', {
10+
name: 'Sorry, there is a problem with this service',
11+
});
12+
}
13+
}

src/client/testing/tests/change-availability/cancel-date-range.spec.ts

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { OAuthLoginPage, RootPage } from '@testing-page-objects';
22
import { Site } from '@types';
33
import { test, expect, overrideFeatureFlag } from '../../fixtures';
4+
import ServiceNotFoundPage from '@e2etests/page-objects';
45

56
let rootPage: RootPage;
67
let oAuthPage: OAuthLoginPage;
@@ -46,10 +47,9 @@ test.describe.configure({ mode: 'serial' });
4647
});
4748

4849
test('Cancel a date range monthly page', async ({ page }) => {
50+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
4951
if (!CancelADateRangeFlagEnabled) {
50-
expect(
51-
page.getByRole('button', { name: 'Change availability' }),
52-
).not.toBeVisible();
52+
await expect(serviceNotFoundPage.title).toBeVisible();
5353
return;
5454
}
5555

@@ -77,10 +77,9 @@ test.describe.configure({ mode: 'serial' });
7777
.getByRole('link')
7878
.click();
7979

80+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
8081
if (!CancelADateRangeFlagEnabled) {
81-
expect(
82-
page.getByRole('button', { name: 'Change availability' }),
83-
).not.toBeVisible();
82+
await expect(serviceNotFoundPage.title).toBeVisible();
8483
return;
8584
}
8685

@@ -122,10 +121,9 @@ test.describe.configure({ mode: 'serial' });
122121
),
123122
);
124123

124+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
125125
if (!CancelADateRangeFlagEnabled) {
126-
expect(
127-
page.getByRole('button', { name: 'Change availability' }),
128-
).not.toBeVisible();
126+
await expect(serviceNotFoundPage.title).toBeVisible();
129127
return;
130128
}
131129

@@ -170,10 +168,9 @@ test.describe.configure({ mode: 'serial' });
170168
test('Select dates to cancel error, mandatory field validation', async ({
171169
page,
172170
}) => {
171+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
173172
if (!CancelADateRangeFlagEnabled) {
174-
expect(
175-
page.getByRole('button', { name: 'Change availability' }),
176-
).not.toBeVisible();
173+
await expect(serviceNotFoundPage.title).toBeVisible();
177174
return;
178175
}
179176

@@ -217,10 +214,9 @@ test.describe.configure({ mode: 'serial' });
217214
test('Select dates to cancel error, must be in the future', async ({
218215
page,
219216
}) => {
217+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
220218
if (!CancelADateRangeFlagEnabled) {
221-
expect(
222-
page.getByRole('button', { name: 'Change availability' }),
223-
).not.toBeVisible();
219+
await expect(serviceNotFoundPage.title).toBeVisible();
224220
return;
225221
}
226222

@@ -280,10 +276,9 @@ test.describe.configure({ mode: 'serial' });
280276
test('Select dates to cancel error, end date must be after the start date', async ({
281277
page,
282278
}) => {
279+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
283280
if (!CancelADateRangeFlagEnabled) {
284-
expect(
285-
page.getByRole('button', { name: 'Change availability' }),
286-
).not.toBeVisible();
281+
await expect(serviceNotFoundPage.title).toBeVisible();
287282
return;
288283
}
289284

@@ -335,9 +330,7 @@ test.describe.configure({ mode: 'serial' });
335330
.filter({ hasText: 'End date' });
336331
await expect(
337332
errorContainer.locator('.nhsuk-error-message'),
338-
).toContainText(/End date must be on or after the start date/i, {
339-
timeout: 15000,
340-
});
333+
).toContainText(/End date must be on or after the start date/i);
341334

342335
await expect(
343336
page.getByRole('link', { name: 'Back', exact: true }),
@@ -351,10 +344,9 @@ test.describe.configure({ mode: 'serial' });
351344
test('Select dates to cancel error within 3 months - 90 days or less', async ({
352345
page,
353346
}) => {
347+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
354348
if (!CancelADateRangeFlagEnabled) {
355-
expect(
356-
page.getByRole('button', { name: 'Change availability' }),
357-
).not.toBeVisible();
349+
await expect(serviceNotFoundPage.title).toBeVisible();
358350
return;
359351
}
360352

@@ -408,10 +400,9 @@ test.describe.configure({ mode: 'serial' });
408400
test('Select dates to cancel error within 3 months - greater than 90 days', async ({
409401
page,
410402
}) => {
403+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
411404
if (!CancelADateRangeFlagEnabled) {
412-
expect(
413-
page.getByRole('button', { name: 'Change availability' }),
414-
).not.toBeVisible();
405+
await expect(serviceNotFoundPage.title).toBeVisible();
415406
return;
416407
}
417408

@@ -513,10 +504,9 @@ test.describe.configure({ mode: 'serial' });
513504
test('Cannot cancel these sessions - Return to view availability', async ({
514505
page,
515506
}) => {
507+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
516508
if (!CancelADateRangeFlagEnabled) {
517-
expect(
518-
page.getByRole('button', { name: 'Change availability' }),
519-
).not.toBeVisible();
509+
await expect(serviceNotFoundPage.title).toBeVisible();
520510
return;
521511
}
522512

@@ -576,10 +566,9 @@ test.describe.configure({ mode: 'serial' });
576566
test('Cannot cancel these sessions - Select different dates', async ({
577567
page,
578568
}) => {
569+
const serviceNotFoundPage = new ServiceNotFoundPage(page);
579570
if (!CancelADateRangeFlagEnabled) {
580-
expect(
581-
page.getByRole('button', { name: 'Change availability' }),
582-
).not.toBeVisible();
571+
await expect(serviceNotFoundPage.title).toBeVisible();
583572
return;
584573
}
585574

0 commit comments

Comments
 (0)