Skip to content

Commit f9aba7f

Browse files
committed
CCM-11148: add automated tests skeleton
1 parent 3f213f5 commit f9aba7f

File tree

7 files changed

+112
-25
lines changed

7 files changed

+112
-25
lines changed

frontend/src/__tests__/app/message-plans/page.test.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ import {
88
} from '@molecules/MessagePlans/MessagePlans';
99
import { serverIsFeatureEnabled } from '@utils/server-features';
1010
import MessagePlansPage, { generateMetadata } from '@app/message-plans/page';
11-
import { redirect } from 'next/navigation';
1211
import { ReactElement } from 'react';
1312
import { RoutingConfig } from 'nhs-notify-backend-client';
1413

15-
jest.mock('next/navigation');
1614
jest.mock('@utils/form-actions');
1715
jest.mock('@utils/server-features');
1816

1917
const countRoutingConfigsMock = jest.mocked(countRoutingConfigs);
2018
const serverIsFeatureEnabledMock = jest.mocked(serverIsFeatureEnabled);
2119
const getRoutingConfigsMock = jest.mocked(getRoutingConfigs);
22-
const redirectMock = jest.mocked(redirect);
2320

2421
const buildRoutingConfig = (rc: Partial<RoutingConfig>): RoutingConfig => ({
2522
campaignId: 'abc',
@@ -48,15 +45,6 @@ describe('MessagePlansPage', () => {
4845
});
4946
});
5047

51-
test('redirects to invalid page when routing feature is disabled', async () => {
52-
serverIsFeatureEnabledMock.mockReset();
53-
serverIsFeatureEnabledMock.mockResolvedValueOnce(false);
54-
55-
await MessagePlansPage();
56-
57-
expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
58-
});
59-
6048
test('renders the page with drafts and production routing plans', async () => {
6149
getRoutingConfigsMock.mockResolvedValueOnce([
6250
buildRoutingConfig({
@@ -88,8 +76,6 @@ describe('MessagePlansPage', () => {
8876

8977
expect(page.props).toBeDefined();
9078

91-
expect(redirectMock).not.toHaveBeenCalled();
92-
9379
expect(getRoutingConfigsMock).toHaveBeenCalledTimes(1);
9480

9581
expect(countRoutingConfigsMock).toHaveBeenNthCalledWith(1, 'DRAFT');

frontend/src/__tests__/components/molecules/__snapshots__/MessagePlans.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exports[`MessagePlans matches snapshot 1`] = `
1818
</h1>
1919
<details
2020
class="nhsuk-details"
21+
id="message-plans-status-info"
2122
>
2223
<summary
2324
class="nhsuk-details__summary"

frontend/src/app/message-plans/page.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import content from '@content/content';
44
import { MessagePlans } from '@molecules/MessagePlans/MessagePlans';
55
import { Metadata } from 'next';
66
import { countRoutingConfigs, getRoutingConfigs } from '@utils/form-actions';
7-
import { redirect, RedirectType } from 'next/navigation';
8-
import { serverIsFeatureEnabled } from '@utils/server-features';
97

108
export async function generateMetadata(): Promise<Metadata> {
119
return {
@@ -14,12 +12,6 @@ export async function generateMetadata(): Promise<Metadata> {
1412
}
1513

1614
const MessagePlansPage = async () => {
17-
const routing = await serverIsFeatureEnabled('routing');
18-
19-
if (!routing) {
20-
return redirect('/invalid-template', RedirectType.replace);
21-
}
22-
2315
const [routingConfigurations, draftCount, completedCount] = await Promise.all(
2416
[
2517
getRoutingConfigs(),

frontend/src/components/molecules/MessagePlans/MessagePlans.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const MessagePlans = (props: MessagePlansProps) => {
3737
<div className='nhsuk-grid-row'>
3838
<div className='nhsuk-grid-column-full'>
3939
<h1>{pageHeading}</h1>
40-
<Details>
40+
<Details id='message-plans-status-info'>
4141
<Details.Summary>
4242
{messagePlansPage.draftAndProductionInfo.heading}
4343
</Details.Summary>

lambdas/backend-client/src/__tests__/routing-config-api-client.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import axios from 'axios';
2-
import { RoutingConfigurationApiClient } from '../routing-config-api-client';
2+
import {
3+
RoutingConfigurationApiClient,
4+
routingConfigurationApiClient,
5+
} from '../routing-config-api-client';
36
import MockAdapter from 'axios-mock-adapter';
47

5-
describe('ClientConfiguration', () => {
8+
describe('RoutingConfigurationApiClient', () => {
69
const axiosMock = new MockAdapter(axios);
710

811
beforeEach(() => {
912
axiosMock.reset();
1013
});
1114

15+
it('should export client', () => {
16+
expect(routingConfigurationApiClient).not.toBeUndefined();
17+
});
18+
1219
describe('count', () => {
1320
it('should return error when failing to fetch from API', async () => {
1421
axiosMock
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Locator, type Page } from '@playwright/test';
2+
import { TemplateMgmtBasePageNonDynamic } from './template-mgmt-base-page-non-dynamic';
3+
4+
export class RoutingMessagePlansPage extends TemplateMgmtBasePageNonDynamic {
5+
static readonly pageUrlSegment = 'message-plans';
6+
7+
readonly messagePlanStatusInfo: Locator;
8+
9+
readonly newMessagePlanButton: Locator;
10+
11+
readonly draftMessagePlansTable: Locator;
12+
13+
readonly productionMessagePlansTable: Locator;
14+
15+
constructor(page: Page) {
16+
super(page);
17+
this.messagePlanStatusInfo = page.locator('#message-plans-status-info');
18+
this.newMessagePlanButton = page.locator('#create-message-plan-button');
19+
this.draftMessagePlansTable = page.locator('#message-plans-list-draft');
20+
this.productionMessagePlansTable = page.locator(
21+
'#message-plans-list-production'
22+
);
23+
}
24+
25+
async clickNewMessagePlanButton() {
26+
await this.newMessagePlanButton.click();
27+
}
28+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { test, expect } from '@playwright/test';
2+
import { RoutingMessagePlansPage } from '../pages/routing-message-plans-page';
3+
import {
4+
assertFooterLinks,
5+
assertGoBackLink,
6+
assertSignOutLink,
7+
assertHeaderLogoLink,
8+
assertSkipToMainContent,
9+
} from '../helpers/template-mgmt-common.steps';
10+
import { createAuthHelper, testUsers } from 'helpers/auth/cognito-auth-helper';
11+
import { RoutingConfigFactory } from 'helpers/factories/routing-config-factory';
12+
import { RoutingConfigStorageHelper } from 'helpers/db/routing-config-storage-helper';
13+
import { RoutingConfigDbEntry } from 'helpers/types';
14+
15+
type MessagePlansPageData = {
16+
draft: RoutingConfigDbEntry;
17+
production: RoutingConfigDbEntry;
18+
deleted: RoutingConfigDbEntry;
19+
};
20+
21+
async function createRoutingConfigs(): Promise<MessagePlansPageData> {
22+
const authHelper = createAuthHelper();
23+
const user = await authHelper.getTestUser(testUsers.User1.userId);
24+
25+
return {
26+
draft: {
27+
...RoutingConfigFactory.create(user, { status: 'DRAFT' }).dbEntry,
28+
},
29+
production: {
30+
...RoutingConfigFactory.create(user, { status: 'COMPLETED' }).dbEntry,
31+
},
32+
deleted: {
33+
...RoutingConfigFactory.create(user, { status: 'DELETED' }).dbEntry,
34+
},
35+
};
36+
}
37+
38+
test.describe('Message plans Page', () => {
39+
const routingStorageHelper = new RoutingConfigStorageHelper();
40+
let routingConfigs: MessagePlansPageData;
41+
42+
test.beforeAll(async () => {
43+
routingConfigs = await createRoutingConfigs();
44+
await routingStorageHelper.seed(Object.values(routingConfigs));
45+
});
46+
47+
test('should land on "Message plans" page when navigating to "/templates/message-plans" url', async ({
48+
page,
49+
baseURL,
50+
}) => {
51+
const messagePlanPage = new RoutingMessagePlansPage(page);
52+
53+
await messagePlanPage.loadPage();
54+
55+
await expect(page).toHaveURL(`${baseURL}/templates/message-plans`);
56+
await expect(messagePlanPage.pageHeading).toHaveText('Message plans');
57+
});
58+
59+
test('common page tests', async ({ page, baseURL }) => {
60+
const props = {
61+
page: new RoutingMessagePlansPage(page),
62+
id: '',
63+
baseURL,
64+
expectedUrl: 'templates/message-plans',
65+
};
66+
67+
await assertSkipToMainContent(props);
68+
await assertHeaderLogoLink(props);
69+
await assertFooterLinks(props);
70+
await assertSignOutLink(props);
71+
await assertGoBackLink(props);
72+
});
73+
});

0 commit comments

Comments
 (0)