Skip to content

Commit c29abae

Browse files
authored
CCM-11459: Update preview template to show only edit button when Routing enabled (#691)
1 parent 0e59a23 commit c29abae

File tree

36 files changed

+2421
-777
lines changed

36 files changed

+2421
-777
lines changed

frontend/src/__tests__/app/preview-email-template/page.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ import {
1616
SMS_TEMPLATE,
1717
} from '../../helpers';
1818
import content from '@content/content';
19+
import { serverIsFeatureEnabled } from '@utils/server-features';
1920

2021
const { pageTitle } = content.components.previewEmailTemplate;
2122

2223
jest.mock('@utils/form-actions');
2324
jest.mock('next/navigation');
2425
jest.mock('@forms/PreviewEmailTemplate');
26+
jest.mock('@utils/server-features');
2527

2628
const redirectMock = jest.mocked(redirect);
2729
const getTemplateMock = jest.mocked(getTemplate);
30+
const serverIsFeatureEnabledMock = jest.mocked(serverIsFeatureEnabled);
2831

2932
describe('PreviewEmailTemplatePage', () => {
30-
beforeEach(jest.resetAllMocks);
33+
beforeEach(() => {
34+
jest.resetAllMocks();
35+
serverIsFeatureEnabledMock.mockResolvedValueOnce(true);
36+
});
3137

3238
it('should load page', async () => {
3339
const templateDTO = {
@@ -59,7 +65,12 @@ describe('PreviewEmailTemplatePage', () => {
5965
expect(await generateMetadata()).toEqual({
6066
title: pageTitle,
6167
});
62-
expect(page).toEqual(<PreviewEmailTemplate initialState={emailTemplate} />);
68+
expect(page).toEqual(
69+
<PreviewEmailTemplate
70+
initialState={emailTemplate}
71+
routingEnabled={true}
72+
/>
73+
);
6374
});
6475

6576
it('should redirect to invalid-template when no templateId is found', async () => {

frontend/src/__tests__/app/preview-nhs-app-template/page.test.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ import {
1616
SMS_TEMPLATE,
1717
} from '../../helpers';
1818
import content from '@content/content';
19+
import { serverIsFeatureEnabled } from '@utils/server-features';
1920

2021
const { pageTitle } = content.components.previewNHSAppTemplate;
2122

2223
jest.mock('@utils/form-actions');
2324
jest.mock('next/navigation');
2425
jest.mock('@forms/PreviewNHSAppTemplate/PreviewNHSAppTemplate');
26+
jest.mock('@utils/server-features');
2527

2628
const redirectMock = jest.mocked(redirect);
2729
const getTemplateMock = jest.mocked(getTemplate);
30+
const serverIsFeatureEnabledMock = jest.mocked(serverIsFeatureEnabled);
2831

2932
describe('PreviewNhsAppTemplatePage', () => {
30-
beforeEach(jest.resetAllMocks);
33+
beforeEach(() => {
34+
jest.resetAllMocks();
35+
serverIsFeatureEnabledMock.mockResolvedValueOnce(true);
36+
});
3137

3238
it('should load page', async () => {
3339
const templateDTO = {
@@ -58,7 +64,10 @@ describe('PreviewNhsAppTemplatePage', () => {
5864
title: pageTitle,
5965
});
6066
expect(page).toEqual(
61-
<PreviewNHSAppTemplate initialState={nhsAppTemplate} />
67+
<PreviewNHSAppTemplate
68+
initialState={nhsAppTemplate}
69+
routingEnabled={true}
70+
/>
6271
);
6372
});
6473

frontend/src/__tests__/app/preview-text-message-template/page.test.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ import {
1616
SMS_TEMPLATE,
1717
} from '../../helpers';
1818
import content from '@content/content';
19+
import { serverIsFeatureEnabled } from '@utils/server-features';
1920

2021
const { pageTitle } = content.components.previewSMSTemplate;
2122

2223
jest.mock('@utils/form-actions');
2324
jest.mock('next/navigation');
2425
jest.mock('@forms/PreviewSMSTemplate');
26+
jest.mock('@utils/server-features');
2527

2628
const redirectMock = jest.mocked(redirect);
2729
const getTemplateMock = jest.mocked(getTemplate);
30+
const serverIsFeatureEnabledMock = jest.mocked(serverIsFeatureEnabled);
2831

2932
describe('PreviewSMSTemplatePage', () => {
30-
beforeEach(jest.resetAllMocks);
33+
beforeEach(() => {
34+
jest.resetAllMocks();
35+
serverIsFeatureEnabledMock.mockResolvedValueOnce(true);
36+
});
3137

3238
it('should load page', async () => {
3339
const templateDTO = {
@@ -57,7 +63,9 @@ describe('PreviewSMSTemplatePage', () => {
5763
expect(await generateMetadata()).toEqual({
5864
title: pageTitle,
5965
});
60-
expect(page).toEqual(<PreviewSMSTemplate initialState={smsTemplate} />);
66+
expect(page).toEqual(
67+
<PreviewSMSTemplate initialState={smsTemplate} routingEnabled={true} />
68+
);
6169
});
6270

6371
it('should redirect to invalid-template when no template is found', async () => {

frontend/src/__tests__/components/forms/PreviewEmailTemplate/PreviewEmailTemplate.test.tsx

Lines changed: 132 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -34,92 +34,143 @@ jest.mock('next/navigation', () => ({
3434
}));
3535

3636
describe('Preview email form renders', () => {
37-
it('matches snapshot when navigating from manage templates screen', () => {
38-
const container = render(
39-
<PreviewEmailTemplate
40-
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
41-
errorState: undefined,
42-
name: 'test-template-email',
43-
templateStatus: 'NOT_YET_SUBMITTED',
44-
subject: 'template-subject-line',
45-
message: 'message',
46-
id: 'template-id',
47-
})}
48-
/>
49-
);
50-
51-
expect(container.asFragment()).toMatchSnapshot();
52-
});
53-
54-
it('matches snapshot when navigating from edit screen', () => {
55-
const mockSearchParams = new Map([['from', 'edit']]);
56-
(useSearchParams as jest.Mock).mockImplementation(() => ({
57-
get: (key: string) => mockSearchParams.get(key),
58-
}));
59-
60-
const container = render(
61-
<PreviewEmailTemplate
62-
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
63-
errorState: undefined,
64-
name: 'test-template-email',
65-
templateStatus: 'NOT_YET_SUBMITTED',
66-
subject: 'template-subject-line',
67-
message: 'message',
68-
id: 'template-id',
69-
})}
70-
/>
71-
);
72-
73-
expect(container.asFragment()).toMatchSnapshot();
74-
});
75-
76-
it('matches error snapshot', () => {
77-
const container = render(
78-
<PreviewEmailTemplate
79-
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
80-
errorState: {
81-
formErrors: [],
82-
fieldErrors: {
83-
previewEmailTemplateAction: ['Select an option'],
37+
describe('Routing feature flag - Disabled', () => {
38+
it('matches error snapshot', () => {
39+
const container = render(
40+
<PreviewEmailTemplate
41+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
42+
errorState: {
43+
formErrors: [],
44+
fieldErrors: {
45+
previewEmailTemplateAction: ['Select an option'],
46+
},
8447
},
85-
},
86-
name: 'test-template-email',
87-
templateStatus: 'NOT_YET_SUBMITTED',
88-
subject: 'template-subject-line',
89-
message: 'message',
90-
id: 'template-id',
91-
})}
92-
/>
93-
);
94-
95-
expect(container.asFragment()).toMatchSnapshot();
48+
name: 'test-template-email',
49+
templateStatus: 'NOT_YET_SUBMITTED',
50+
subject: 'template-subject-line',
51+
message: 'message',
52+
id: 'template-id',
53+
})}
54+
/>
55+
);
56+
57+
expect(container.asFragment()).toMatchSnapshot();
58+
});
59+
60+
it('renders component correctly', () => {
61+
render(
62+
<PreviewEmailTemplate
63+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
64+
errorState: undefined,
65+
name: 'test-template-email',
66+
templateStatus: 'NOT_YET_SUBMITTED',
67+
subject: 'template-subject-line',
68+
message: 'message',
69+
id: 'template-id',
70+
})}
71+
/>
72+
);
73+
74+
expect(screen.getByTestId('email-edit-radio')).toHaveAttribute(
75+
'value',
76+
'email-edit'
77+
);
78+
79+
expect(screen.getByTestId('email-submit-radio')).toHaveAttribute(
80+
'value',
81+
'email-submit'
82+
);
83+
});
84+
85+
test('Client-side validation triggers', () => {
86+
const container = render(
87+
<PreviewEmailTemplate
88+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
89+
errorState: undefined,
90+
name: 'test-template-email',
91+
templateStatus: 'NOT_YET_SUBMITTED',
92+
subject: 'template-subject-line',
93+
message: 'message',
94+
id: 'template-id',
95+
})}
96+
/>
97+
);
98+
const submitButton = screen.getByTestId('submit-button');
99+
fireEvent.click(submitButton);
100+
expect(container.asFragment()).toMatchSnapshot();
101+
});
96102
});
97103

98-
it('renders component correctly', () => {
99-
render(
100-
<PreviewEmailTemplate
101-
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
102-
errorState: undefined,
103-
name: 'test-template-email',
104-
templateStatus: 'NOT_YET_SUBMITTED',
105-
subject: 'template-subject-line',
106-
message: 'message',
107-
id: 'template-id',
108-
})}
109-
/>
110-
);
111-
112-
expect(screen.getByTestId('email-edit-radio')).toHaveAttribute(
113-
'value',
114-
'email-edit'
115-
);
116-
117-
expect(screen.getByTestId('email-submit-radio')).toHaveAttribute(
118-
'value',
119-
'email-submit'
120-
);
104+
describe('Routing feature flag - Enabled', () => {
105+
it('renders component correctly', () => {
106+
render(
107+
<PreviewEmailTemplate
108+
routingEnabled={true}
109+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
110+
errorState: undefined,
111+
name: 'test-template-email',
112+
templateStatus: 'NOT_YET_SUBMITTED',
113+
subject: 'template-subject-line',
114+
message: 'message',
115+
id: 'template-id',
116+
})}
117+
/>
118+
);
119+
120+
expect(screen.getByTestId('edit-template-button')).toHaveAttribute(
121+
'href',
122+
'/edit-email-template/template-id'
123+
);
124+
});
121125
});
122126

127+
it.each([true, false])(
128+
'matches snapshot when navigating from manage templates screen, when routing is %p',
129+
(routing) => {
130+
const container = render(
131+
<PreviewEmailTemplate
132+
routingEnabled={routing}
133+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
134+
errorState: undefined,
135+
name: 'test-template-email',
136+
templateStatus: 'NOT_YET_SUBMITTED',
137+
subject: 'template-subject-line',
138+
message: 'message',
139+
id: 'template-id',
140+
})}
141+
/>
142+
);
143+
144+
expect(container.asFragment()).toMatchSnapshot();
145+
}
146+
);
147+
148+
it.each([true, false])(
149+
'matches snapshot when navigating from edit screen when routing is %p',
150+
(routing) => {
151+
const mockSearchParams = new Map([['from', 'edit']]);
152+
(useSearchParams as jest.Mock).mockImplementationOnce(() => ({
153+
get: (key: string) => mockSearchParams.get(key),
154+
}));
155+
156+
const container = render(
157+
<PreviewEmailTemplate
158+
routingEnabled={routing}
159+
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
160+
errorState: undefined,
161+
name: 'test-template-email',
162+
templateStatus: 'NOT_YET_SUBMITTED',
163+
subject: 'template-subject-line',
164+
message: 'message',
165+
id: 'template-id',
166+
})}
167+
/>
168+
);
169+
170+
expect(container.asFragment()).toMatchSnapshot();
171+
}
172+
);
173+
123174
it('should should render subject line and message with markdown', () => {
124175
const renderMock = jest.mocked(renderEmailMarkdown);
125176

@@ -149,22 +200,4 @@ describe('Preview email form renders', () => {
149200
'Rendered via MD'
150201
);
151202
});
152-
153-
test('Client-side validation triggers', () => {
154-
const container = render(
155-
<PreviewEmailTemplate
156-
initialState={mockDeep<TemplateFormState<EmailTemplate>>({
157-
errorState: undefined,
158-
name: 'test-template-email',
159-
templateStatus: 'NOT_YET_SUBMITTED',
160-
subject: 'template-subject-line',
161-
message: 'message',
162-
id: 'template-id',
163-
})}
164-
/>
165-
);
166-
const submitButton = screen.getByTestId('submit-button');
167-
fireEvent.click(submitButton);
168-
expect(container.asFragment()).toMatchSnapshot();
169-
});
170203
});

0 commit comments

Comments
 (0)