1+ import { type FormDefinition , type FormMetadata } from '@defra/forms-model'
12import { type Server } from '@hapi/hapi'
23import { StatusCodes } from 'http-status-codes'
34
45import { config } from '~/src/config/index.js'
56import { createServer } from '~/src/server/index.js'
6- import { getFormMetadata } from '~/src/server/services/formsService.js'
7+ import {
8+ getFormDefinition ,
9+ getFormMetadata
10+ } from '~/src/server/services/formsService.js'
711import * as fixtures from '~/test/fixtures/index.js'
812import { renderResponse } from '~/test/helpers/component-helpers.js'
913
@@ -163,7 +167,13 @@ describe('Routes', () => {
163167 expect ( $banner ) . toHaveTextContent ( 'Hello world' )
164168 } )
165169
166- test ( 'privacy notice (general) page is served' , async ( ) => {
170+ test ( 'privacy notice (general) page is served with feedback form link' , async ( ) => {
171+ jest
172+ . mocked ( getFormMetadata )
173+ . mockResolvedValueOnce ( { id : '123' } as unknown as FormMetadata )
174+ jest
175+ . mocked ( getFormDefinition )
176+ . mockResolvedValueOnce ( { } as unknown as FormDefinition )
167177 const options = {
168178 method : 'GET' ,
169179 url : '/help/privacy/slug'
@@ -176,11 +186,76 @@ describe('Routes', () => {
176186 level : 1
177187 } )
178188
189+ const $link = container . getByRole ( 'link' , {
190+ name : 'give your feedback (opens in new tab)'
191+ } )
192+
193+ expect ( $heading ) . toBeInTheDocument ( )
194+ expect ( $heading ) . toHaveClass ( 'govuk-heading-l' )
195+ expect ( $link ) . toBeInTheDocument ( )
196+ } )
197+
198+ test ( 'privacy notice (general) page is served with feedback by email link' , async ( ) => {
199+ jest
200+ . mocked ( getFormMetadata )
201+ . mockResolvedValueOnce ( { id : '123' } as unknown as FormMetadata )
202+ jest . mocked ( getFormDefinition ) . mockResolvedValueOnce ( {
203+ options : { disableUserFeedback : true }
204+ } as unknown as FormDefinition )
205+ const options = {
206+ method : 'GET' ,
207+ url : '/help/privacy/slug'
208+ }
209+
210+ const { container } = await renderResponse ( server , options )
211+
212+ const $heading = container . getByRole ( 'heading' , {
213+ name : 'Submit a form to Defra - privacy notice' ,
214+ level : 1
215+ } )
216+
217+ const $link = container . getByRole ( 'link' , {
218+ name : 'give your feedback by email'
219+ } )
220+
179221 expect ( $heading ) . toBeInTheDocument ( )
180222 expect ( $heading ) . toHaveClass ( 'govuk-heading-l' )
223+ expect ( $link ) . toBeInTheDocument ( )
224+ } )
225+
226+ test ( 'privacy notice (specific) page is served with feedback form link' , async ( ) => {
227+ jest
228+ . mocked ( getFormDefinition )
229+ . mockResolvedValueOnce ( { } as unknown as FormDefinition )
230+ jest . mocked ( getFormMetadata ) . mockResolvedValue ( {
231+ ...fixtures . form . metadata ,
232+ privacyNoticeType : 'text' ,
233+ privacyNoticeText : '# Privacy markdown heading'
234+ } )
235+ const options = {
236+ method : 'GET' ,
237+ url : '/help/privacy-specific/slug'
238+ }
239+
240+ const { container } = await renderResponse ( server , options )
241+
242+ const $heading = container . getByRole ( 'heading' , {
243+ name : 'Privacy markdown heading' ,
244+ level : 1
245+ } )
246+
247+ const $link = container . getByRole ( 'link' , {
248+ name : 'give your feedback (opens in new tab)'
249+ } )
250+
251+ expect ( $heading ) . toBeInTheDocument ( )
252+ expect ( $link ) . toBeInTheDocument ( )
181253 } )
182254
183- test ( 'privacy notice (specific) page is served' , async ( ) => {
255+ test ( 'privacy notice (specific) page is served with feedback by email link' , async ( ) => {
256+ jest . mocked ( getFormDefinition ) . mockResolvedValueOnce ( {
257+ options : { disableUserFeedback : true }
258+ } as unknown as FormDefinition )
184259 jest . mocked ( getFormMetadata ) . mockResolvedValue ( {
185260 ...fixtures . form . metadata ,
186261 privacyNoticeType : 'text' ,
@@ -198,6 +273,11 @@ describe('Routes', () => {
198273 level : 1
199274 } )
200275
276+ const $link = container . getByRole ( 'link' , {
277+ name : 'give your feedback by email'
278+ } )
279+
201280 expect ( $heading ) . toBeInTheDocument ( )
281+ expect ( $link ) . toBeInTheDocument ( )
202282 } )
203283} )
0 commit comments