diff --git a/.gitignore b/.gitignore index b968ee0fa..bda797693 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,7 @@ lambdas/backend-api/src/email/email-template.json # vscode .vscode/settings.local.json +# github +.github/copilot-instructions.md + test-runs diff --git a/frontend/src/__tests__/app/choose-templates/__snapshots__/page.test.tsx.snap b/frontend/src/__tests__/app/choose-templates/__snapshots__/page.test.tsx.snap index 0a3996d36..d240745d1 100644 --- a/frontend/src/__tests__/app/choose-templates/__snapshots__/page.test.tsx.snap +++ b/frontend/src/__tests__/app/choose-templates/__snapshots__/page.test.tsx.snap @@ -102,7 +102,7 @@ exports[`ChooseTemplatesPage renders correctly for a message plan with multiple class="nhsuk-u-margin-bottom-2" data-testid="template-name-NHSAPP" > - name + app template name
- Example message + message
@@ -122,17 +128,11 @@ exports[`ViewNHSAppTemplate component matches submitted snapshot 1`] = `- This template cannot be edited because it has been submitted. -
-- If you want to change a submitted or live template, you must create a new template to replace it. -
- Example message + message
@@ -147,17 +103,11 @@ exports[`ViewEmailTemplate component matches submitted snapshot 1`] = `- This template cannot be edited because it has been submitted. -
-- If you want to change a submitted or live template, you must create a new template to replace it. -
+ template.pdf +
++ + Go back + +
+- Example message + message
@@ -122,17 +103,11 @@ exports[`ViewNHSAppTemplate component matches submitted snapshot 1`] = `- This template cannot be edited because it has been submitted. -
-- If you want to change a submitted or live template, you must create a new template to replace it. -
- Back to all templates + Go back
diff --git a/frontend/src/__tests__/app/message-plans/choose-text-message-template/preview-template/page.test.tsx b/frontend/src/__tests__/app/message-plans/choose-text-message-template/preview-template/page.test.tsx new file mode 100644 index 000000000..7cfc2a6a8 --- /dev/null +++ b/frontend/src/__tests__/app/message-plans/choose-text-message-template/preview-template/page.test.tsx @@ -0,0 +1,55 @@ +import PreviewTextMessageTemplateFromMessagePlan, { + generateMetadata, +} from '@app/message-plans/choose-text-message-template/[routingConfigId]/preview-template/[templateId]/page'; +import { ROUTING_CONFIG, SMS_TEMPLATE } from '@testhelpers/helpers'; +import { render } from '@testing-library/react'; +import { getTemplate } from '@utils/form-actions'; +import { redirect } from 'next/navigation'; + +jest.mock('@utils/form-actions'); +jest.mock('next/navigation'); + +const getTemplateMock = jest.mocked(getTemplate); +const redirectMock = jest.mocked(redirect); + +describe('PreviewTextMessageTemplateFromMessagePlan page', () => { + beforeEach(jest.resetAllMocks); + + it('should redirect to invalid page with invalid template id', async () => { + getTemplateMock.mockResolvedValueOnce(undefined); + + await PreviewTextMessageTemplateFromMessagePlan({ + params: Promise.resolve({ + routingConfigId: 'routing-config-id', + templateId: 'invalid-template-id', + }), + }); + + expect(getTemplateMock).toHaveBeenCalledWith('invalid-template-id'); + + expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace'); + }); + + it('renders SMS template preview', async () => { + getTemplateMock.mockResolvedValueOnce({ + ...SMS_TEMPLATE, + templateStatus: 'SUBMITTED', + }); + + const page = await PreviewTextMessageTemplateFromMessagePlan({ + params: Promise.resolve({ + routingConfigId: ROUTING_CONFIG.id, + templateId: SMS_TEMPLATE.id, + }), + }); + + const container = render(page); + + expect(getTemplateMock).toHaveBeenCalledWith(SMS_TEMPLATE.id); + + expect(await generateMetadata()).toEqual({ + title: 'Preview text message template - NHS Notify', + }); + expect(container.asFragment()).toMatchSnapshot(); + }); +}); diff --git a/frontend/src/__tests__/app/preview-submitted-email-template/page.test.tsx b/frontend/src/__tests__/app/preview-submitted-email-template/page.test.tsx index 66b3e39d2..0f19ae66f 100644 --- a/frontend/src/__tests__/app/preview-submitted-email-template/page.test.tsx +++ b/frontend/src/__tests__/app/preview-submitted-email-template/page.test.tsx @@ -4,7 +4,6 @@ import PreviewSubmittedEmailTemplatePage, { generateMetadata, } from '@app/preview-submitted-email-template/[templateId]/page'; -import { ViewEmailTemplate } from '@molecules/ViewEmailTemplate/ViewEmailTemplate'; import { EmailTemplate } from 'nhs-notify-web-template-management-utils'; import { getTemplate } from '@utils/form-actions'; import { redirect } from 'next/navigation'; @@ -15,6 +14,8 @@ import { SMS_TEMPLATE, } from '@testhelpers/helpers'; import content from '@content/content'; +import { PreviewSubmittedTemplate } from '@molecules/PreviewSubmittedTemplate/PreviewSubmittedTemplate'; +import PreviewTemplateDetailsEmail from '@molecules/PreviewTemplateDetails/PreviewTemplateDetailsEmail'; const { pageTitle } = content.components.previewEmailTemplate; @@ -59,7 +60,10 @@ describe('ViewSubmittedEmailTemplatePage', () => { title: pageTitle, }); expect(page).toEqual( -| + Select + | ++ Name + | ++ Type + | ++ Last edited + | ++ |
|---|---|---|---|---|
|
+
+
+
+
+
+ |
+ + + app template name + | ++ + NHS App message + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + email template name + | ++ + Email + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + sms template name + | ++ + Text message (SMS) + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + letter template name + | ++ + Standard letter + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
| + Select + | ++ Name + | ++ Type + | ++ Last edited + | ++ |
|---|---|---|---|---|
|
+
+
+
+
+
+ |
+ + + app template name + | ++ + NHS App message + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + email template name + | ++ + Email + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + sms template name + | ++ + Text message (SMS) + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + letter template name + | ++ + Standard letter + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
| + Select + | ++ Name + | ++ Type + | ++ Last edited + | ++ |
|---|---|---|---|---|
|
+
+
+
+
+
+ |
+ + + app template name + | ++ + NHS App message + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + email template name + | ++ + Email + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + sms template name + | ++ + Text message (SMS) + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
|
+
+
+
+
+
+ |
+ + + letter template name + | ++ + Standard letter + | +
+
+ 13th Jan 2025
+ + 10:19 + |
+
+
+
+
+ Preview
+
+
+ |
+
+ app content +
+ + ++ This template cannot be edited because it has been submitted. +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ app content +
+ + ++ This template cannot be edited because it has been submitted. +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ app content +
+ + ++ This template cannot be edited because it has been submitted. +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ email content +
+ + ++ This template cannot be edited because it has been submitted. +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ file.pdf +
++ file.csv +
++ a.pdf +
++ b.pdf +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ SMS content +
+ + ++ This template cannot be edited because it has been submitted. +
++ If you want to change a submitted or live template, you must create a new template to replace it. +
+ ++ email content +
+ + @@ -946,7 +950,11 @@ exports[`PreviewTemplateDetailsNhsApp matches snapshot 1`] = ` data-testid="preview__content-0" id="preview-content-message" > - app content ++ app content +
+ + @@ -1050,7 +1058,11 @@ exports[`PreviewTemplateDetailsSms matches snapshot 1`] = ` data-testid="preview__content-0" id="preview-content-message" > - SMS content ++ SMS content +
+ + diff --git a/frontend/src/__tests__/components/molecules/__snapshots__/ViewLetterTemplate.test.tsx.snap b/frontend/src/__tests__/components/molecules/__snapshots__/ViewLetterTemplate.test.tsx.snap deleted file mode 100644 index 4cde50502..000000000 --- a/frontend/src/__tests__/components/molecules/__snapshots__/ViewLetterTemplate.test.tsx.snap +++ /dev/null @@ -1,197 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ViewLetterTemplate component matches submitted snapshot 1`] = ` -- file.pdf -
-- supplier-proof.pdf -
-- If you want to change a submitted or live template, you must create a new template to replace it. -
- -{content.noTemplatesText}
+ )} ++ + {content.actions.goToTemplates.text} + +
+ )} + 0 && + 'inline-block nhsuk-u-margin-left-3 nhsuk-u-padding-top-3' + )} + > + {content.actions.backLink.text} + +
diff --git a/frontend/src/components/forms/PreviewNHSAppTemplate/PreviewNHSAppTemplate.tsx b/frontend/src/components/forms/PreviewNHSAppTemplate/PreviewNHSAppTemplate.tsx
index a27f4ea34..810af1b27 100644
--- a/frontend/src/components/forms/PreviewNHSAppTemplate/PreviewNHSAppTemplate.tsx
+++ b/frontend/src/components/forms/PreviewNHSAppTemplate/PreviewNHSAppTemplate.tsx
@@ -9,7 +9,6 @@ import {
PageComponentProps,
} from 'nhs-notify-web-template-management-utils';
import content from '@content/content';
-import { renderNHSAppMarkdown } from '@utils/markdownit';
import { useSearchParams } from 'next/navigation';
import { useActionState, useState } from 'react';
import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain';
@@ -33,8 +32,6 @@ export function PreviewNHSAppTemplate({
const formValidate = validate(schema, setErrorState);
- const { message } = state;
- const html = renderNHSAppMarkdown(message);
const isFromEditPage = searchParams.get('from') === 'edit';
const { sectionHeading, form, backLinkText } =
@@ -64,10 +61,7 @@ export function PreviewNHSAppTemplate({
formAttributes: { onSubmit: formValidate },
}}
previewDetailsComponent={
-
{content.cannotEdit}
+ )} +{content.createNewTemplate}
+ ++ {content.backLink.text} +
++ {content.backLink.text} +
+{cannotEdit}
-{createNewTemplate}
-- {backLinkText} -
-{createNewTemplate}
-- - {backLinkText} - -
-{cannotEdit}
-{createNewTemplate}
-- {backLinkText} -
-{cannotEdit}
-{createNewTemplate}
-- {backLinkText} -
-