Skip to content

Commit 5295d1f

Browse files
committed
CCM-11496: playwright tests wip
1 parent 589d360 commit 5295d1f

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

frontend/src/app/message-plans/move-to-production/[routingConfigId]/__snapshots__/page.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ exports[`matches snapshot 1`] = `
4141
class="nhsuk-table__cell"
4242
>
4343
<a
44+
data-testid="preview-link"
4445
href="/message-plans/preview-message-plan/routing-config-id"
4546
>
4647
Preview
@@ -148,6 +149,7 @@ exports[`matches snapshot 1`] = `
148149
<a
149150
aria-disabled="false"
150151
class="nhsuk-button nhsuk-button--secondary nhsuk-u-margin-left-3"
152+
data-testid="cancel-link"
151153
draggable="false"
152154
href="/templates/message-plans"
153155
role="button"

frontend/src/app/message-plans/move-to-production/[routingConfigId]/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export default async function MoveMessagePlanToProductionPage({
4242
<th className='nhsuk-table__cell'>Name</th>
4343
<td className='nhsuk-table__cell'>{routingConfig.name}</td>
4444
<td className='nhsuk-table__cell'>
45-
<Link href={pageContent.previewLink.href(routingConfigId)}>
45+
<Link
46+
href={pageContent.previewLink.href(routingConfigId)}
47+
data-testid='preview-link'
48+
>
4649
{pageContent.previewLink.text}
4750
</Link>
4851
</td>
@@ -76,6 +79,7 @@ export default async function MoveMessagePlanToProductionPage({
7679
secondary
7780
href={pageContent.cancel.href}
7881
className='nhsuk-u-margin-left-3'
82+
data-testid='cancel-link'
7983
>
8084
{pageContent.cancel.text}
8185
</NHSNotifyButton>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Locator, Page } from '@playwright/test';
2+
import { TemplateMgmtBasePageDynamic } from 'pages/template-mgmt-base-page-dynamic';
3+
4+
export class RoutingMoveToProductionPage extends TemplateMgmtBasePageDynamic {
5+
static readonly pageUrlSegment = 'message-plans/move-to-production';
6+
7+
public readonly previewLink: Locator;
8+
9+
public readonly submitButton: Locator;
10+
11+
public readonly cancelLink: Locator;
12+
13+
constructor(page: Page) {
14+
super(page);
15+
16+
this.previewLink = page.getByTestId('preview-link');
17+
this.submitButton = page.getByTestId('submit-button');
18+
this.cancelLink = page.getByTestId('cancel-link');
19+
}
20+
}

tests/test-team/template-mgmt-component-tests/template-protected-routes.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { RoutingMessagePlanCampaignIdRequiredPage } from '../pages/routing/campa
3939
import { RoutingMessagePlansPage } from '../pages/routing/message-plans-page';
4040
import { RoutingChooseTemplatesPage } from 'pages/routing/choose-templates-page';
4141
import { RoutingInvalidMessagePlanPage } from 'pages/routing/invalid-message-plan-page';
42+
import { RoutingMoveToProductionPage } from 'pages/routing/move-to-production-page';
4243

4344
// Reset storage state for this file to avoid being authenticated
4445
test.use({ storageState: { cookies: [], origins: [] } });
@@ -50,6 +51,7 @@ const protectedPages = [
5051
RoutingInvalidMessagePlanPage,
5152
RoutingMessagePlanCampaignIdRequiredPage,
5253
RoutingMessagePlansPage,
54+
RoutingMoveToProductionPage,
5355
TemplateMgmtChoosePage,
5456
TemplateMgmtCopyPage,
5557
TemplateMgmtCreateEmailPage,
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { test, expect } from '@playwright/test';
2+
import {
3+
createAuthHelper,
4+
TestUser,
5+
testUsers,
6+
} from 'helpers/auth/cognito-auth-helper';
7+
import { RoutingConfigStorageHelper } from 'helpers/db/routing-config-storage-helper';
8+
import { RoutingConfigFactory } from 'helpers/factories/routing-config-factory';
9+
import {
10+
assertFooterLinks,
11+
assertHeaderLogoLink,
12+
assertSignOutLink,
13+
assertSkipToMainContent,
14+
} from 'helpers/template-mgmt-common.steps';
15+
import { RoutingMoveToProductionPage } from 'pages/routing/move-to-production-page';
16+
17+
const storageHelper = new RoutingConfigStorageHelper();
18+
19+
let user: TestUser;
20+
21+
test.beforeAll(async () => {
22+
const authHelper = createAuthHelper();
23+
user = await authHelper.getTestUser(testUsers.User1.userId);
24+
});
25+
26+
test.afterAll(async () => {
27+
await storageHelper.deleteSeeded();
28+
});
29+
30+
test.describe('Create Message Plan Page', () => {
31+
test('common page tests', async ({ page, baseURL }) => {
32+
const routingConfig =
33+
RoutingConfigFactory.create(user).withTemplates('NHSAPP');
34+
35+
await storageHelper.seed([routingConfig.dbEntry]);
36+
37+
const props = {
38+
page: new RoutingMoveToProductionPage(page),
39+
id: routingConfig.dbEntry.id,
40+
baseURL,
41+
};
42+
43+
await assertSkipToMainContent(props);
44+
await assertHeaderLogoLink(props);
45+
await assertFooterLinks(props);
46+
await assertSignOutLink(props);
47+
});
48+
49+
test('moves the message plan to production and redirects to list page', async ({
50+
baseURL,
51+
page,
52+
}) => {
53+
const routingConfig =
54+
RoutingConfigFactory.create(user).withTemplates('NHSAPP');
55+
56+
storageHelper.seed([routingConfig.dbEntry]);
57+
58+
const moveToProductionPage = new RoutingMoveToProductionPage(page);
59+
60+
await moveToProductionPage.loadPage(routingConfig.dbEntry.id);
61+
62+
await expect(page).toHaveURL(
63+
`${baseURL}/templates/message-plans/move-to-production/${routingConfig.dbEntry.id}`
64+
);
65+
66+
await moveToProductionPage.submitButton.click();
67+
68+
await expect(page).toHaveURL(`${baseURL}/templates/message-plans`);
69+
// TODO: CCM-11496 - assert status
70+
});
71+
72+
test('links to preview page for the message plan', async ({
73+
baseURL,
74+
page,
75+
}) => {
76+
const routingConfig =
77+
RoutingConfigFactory.create(user).withTemplates('NHSAPP');
78+
79+
storageHelper.seed([routingConfig.dbEntry]);
80+
81+
const moveToProductionPage = new RoutingMoveToProductionPage(page);
82+
83+
await moveToProductionPage.loadPage(routingConfig.dbEntry.id);
84+
85+
await expect(page).toHaveURL(
86+
`${baseURL}/templates/message-plans/move-to-production/${routingConfig.dbEntry.id}`
87+
);
88+
89+
await moveToProductionPage.previewLink.click();
90+
91+
await expect(page).toHaveURL(
92+
`${baseURL}/templates/message-plans/preview-message-plan/${routingConfig.dbEntry.id}`
93+
);
94+
});
95+
96+
test('cancel button links to the message plan list page', async ({
97+
baseURL,
98+
page,
99+
}) => {
100+
const routingConfig =
101+
RoutingConfigFactory.create(user).withTemplates('NHSAPP');
102+
103+
storageHelper.seed([routingConfig.dbEntry]);
104+
105+
const moveToProductionPage = new RoutingMoveToProductionPage(page);
106+
107+
await moveToProductionPage.loadPage(routingConfig.dbEntry.id);
108+
109+
await expect(page).toHaveURL(
110+
`${baseURL}/templates/message-plans/move-to-production/${routingConfig.dbEntry.id}`
111+
);
112+
113+
await moveToProductionPage.cancelLink.click();
114+
115+
await expect(page).toHaveURL(`${baseURL}/templates/message-plans`);
116+
});
117+
});

0 commit comments

Comments
 (0)