@@ -34,92 +34,143 @@ jest.mock('next/navigation', () => ({
3434} ) ) ;
3535
3636describe ( '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