Skip to content

Commit 81d944f

Browse files
author
Fawad Ali
committed
Merge remote-tracking branch 'origin/feature/CCM-4893_submit-email' into feature/CCM-4893_update-email
2 parents 732153b + 1ca59bf commit 81d944f

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

src/__tests__/components/forms/CreateEmailTemplate/CreateEmailTemplate.test.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render } from '@testing-library/react';
2-
import userEvent from '@testing-library/user-event';
32
import { mockDeep } from 'jest-mock-extended';
43
import { TemplateFormState } from '@utils/types';
54
import { CreateEmailTemplate } from '@forms/CreateEmailTemplate/CreateEmailTemplate';
@@ -24,8 +23,6 @@ jest.mock('react-dom', () => {
2423
});
2524

2625
test('renders page', async () => {
27-
const user = userEvent.setup();
28-
2926
const container = render(
3027
<CreateEmailTemplate
3128
initialState={mockDeep<TemplateFormState>({
@@ -37,21 +34,6 @@ test('renders page', async () => {
3734
/>
3835
);
3936
expect(container.asFragment()).toMatchSnapshot();
40-
41-
const templateNameInput = await container.findByTestId(
42-
'emailTemplateName-input'
43-
);
44-
await user.type(templateNameInput, 'template-name');
45-
46-
const templateSubjectLineInput = await container.findByTestId(
47-
'emailTemplateSubjectLine-input'
48-
);
49-
await user.type(templateSubjectLineInput, 'template-subject-line');
50-
51-
const templateMessageInput = await container.findByTestId(
52-
'emailTemplateMessage-input'
53-
);
54-
await user.type(templateMessageInput, 'template-message');
5537
});
5638

5739
test('renders page with preloaded field values', () => {

src/__tests__/components/forms/CreateEmailTemplate/server-action.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { saveSession } from '@utils/form-actions';
33
import { Session, TemplateType } from '@utils/types';
44
import { redirect } from 'next/navigation';
55
import { processFormActions } from '@forms/CreateEmailTemplate/server-action';
6+
import { MAX_EMAIL_CHARACTER_LENGTH } from '@utils/constants';
67

78
jest.mock('@utils/amplify-utils', () => ({
89
getAmplifyBackendClient: () => ({
@@ -65,6 +66,28 @@ describe('CreateEmailTemplate server actions', () => {
6566
});
6667
});
6768

69+
it('create-sms-template - should return response when when template message is too long', async () => {
70+
const response = await processFormActions(
71+
initialState,
72+
getMockFormData({
73+
'form-id': 'create-email-template',
74+
emailTemplateName: 'template-name',
75+
emailTemplateSubjectLine: 'template-subject-line',
76+
emailTemplateMessage: 'a'.repeat(MAX_EMAIL_CHARACTER_LENGTH + 1),
77+
})
78+
);
79+
80+
expect(response).toEqual({
81+
...initialState,
82+
validationError: {
83+
formErrors: [],
84+
fieldErrors: {
85+
emailTemplateMessage: ['Template message too long'],
86+
},
87+
},
88+
});
89+
});
90+
6891
it('create-email-template-back - should return response when no template name, template subject line or template message', async () => {
6992
const response = await processFormActions(
7093
initialState,

src/components/forms/CreateEmailTemplate/server-action.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { zodValidationServerAction } from '@utils/zod-validation-server-action';
33
import { z } from 'zod';
44
import { saveSession } from '@utils/form-actions';
55
import { redirect, RedirectType } from 'next/navigation';
6+
import { MAX_EMAIL_CHARACTER_LENGTH } from '@utils/constants';
67

78
const $CreateEmailTemplateSchema = z.object({
89
emailTemplateName: z
@@ -13,7 +14,10 @@ const $CreateEmailTemplateSchema = z.object({
1314
.min(1, { message: 'Enter a template subject line' }),
1415
emailTemplateMessage: z
1516
.string({ message: 'Enter a template message' })
16-
.min(1, { message: 'Enter a template message' }),
17+
.min(1, { message: 'Enter a template message' })
18+
.max(MAX_EMAIL_CHARACTER_LENGTH, {
19+
message: 'Template message too long',
20+
}),
1721
});
1822

1923
const $GoBackSchema = z.object({

src/content/content.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ export const createEmailTemplatePageContent = {
406406
templateSubjectLineLabelText: 'Subject line',
407407
templateMessageLabelText: 'Message',
408408
templateNameHintText: 'This will not be visible to recipients.',
409-
characterCountText: ' of 5000 characters',
410409
buttonText: 'Continue',
411410
};
412411

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const MAX_SMS_CHARACTER_LENGTH = 918 as const;
2+
export const MAX_EMAIL_CHARACTER_LENGTH = 100_000 as const;

src/utils/form-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function saveSession(session: Session) {
5353
operation: 'update',
5454
});
5555
}
56-
return data as Session;
56+
return data;
5757
}
5858

5959
export async function getSession(

0 commit comments

Comments
 (0)