Skip to content

Commit 7bc077e

Browse files
authored
fix/df-874: Shows correct feedback banner link (#1108)
* Shows correct feedback banner link * Prettier fix
1 parent 59861b5 commit 7bc077e

3 files changed

Lines changed: 100 additions & 9 deletions

File tree

src/server/plugins/router.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
pathSchema,
1010
stateSchema
1111
} from '@defra/forms-engine-plugin/schema.js'
12-
import { slugSchema } from '@defra/forms-model'
12+
import { FormStatus, slugSchema } from '@defra/forms-model'
1313
import Boom from '@hapi/boom'
1414
import {
1515
type Request,
@@ -34,7 +34,10 @@ import {
3434
publicRoutes,
3535
saveAndExitRoutes
3636
} from '~/src/server/routes/index.js'
37-
import { getFormMetadata } from '~/src/server/services/formsService.js'
37+
import {
38+
getFormDefinition,
39+
getFormMetadata
40+
} from '~/src/server/services/formsService.js'
3841
import { getFeedbackFormLink } from '~/src/server/utils/utils.js'
3942

4043
const routes: ServerRoute[] = [...publicRoutes, healthRoute]
@@ -134,12 +137,16 @@ export default {
134137
async handler(request, h) {
135138
const { slug } = request.params
136139
const form = await getFormMetadata(slug)
140+
const definition = await getFormDefinition(form.id, FormStatus.Draft)
137141

138142
return h.view('help/privacy-notice', {
139143
form,
140144
saveAndExitExpiryDays,
141145
storeCompletedApplicationsFor,
142-
storeFeedbackFor
146+
storeFeedbackFor,
147+
...(definition?.options?.disableUserFeedback
148+
? {}
149+
: getFeedbackFormLink(form.id))
143150
})
144151
},
145152
options
@@ -151,9 +158,13 @@ export default {
151158
async handler(request, h) {
152159
const { slug } = request.params
153160
const form = await getFormMetadata(slug)
161+
const definition = await getFormDefinition(form.id, FormStatus.Draft)
154162

155163
return h.view('help/privacy-notice-specific', {
156-
form
164+
form,
165+
...(definition?.options?.disableUserFeedback
166+
? {}
167+
: getFeedbackFormLink(form.id))
157168
})
158169
},
159170
options

src/server/routes/index.test.ts

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import { type FormDefinition, type FormMetadata } from '@defra/forms-model'
12
import { type Server } from '@hapi/hapi'
23
import { StatusCodes } from 'http-status-codes'
34

45
import { config } from '~/src/config/index.js'
56
import { 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'
711
import * as fixtures from '~/test/fixtures/index.js'
812
import { 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
})

src/server/views/layout.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
145145
{% if phaseTag and not hidePhaseBanner %}
146146
{% set feedbackLinkHtml -%}
147147
{% if feedbackLink %}
148-
<a href="{{ currentPath if context.isForceAccess else feedbackLink }}" class="govuk-link" {%- if not context.isForceAccess %} target="_blank" rel="noopener noreferrer" {%- endif %}>
148+
<a href="{{ currentPath if context.isForceAccess else feedbackLink }}" class="govuk-link govuk-link--no-visited-state" {%- if not context.isForceAccess %} target="_blank" rel="noopener noreferrer" {%- endif %}>
149149
give your feedback (opens in new tab)
150150
</a>
151151
{% else %}
152-
<a href="mailto:{{ config.feedbackViaEmail }}" class="govuk-link">
152+
<a href="mailto:{{ config.feedbackViaEmail }}" class="govuk-link govuk-link--no-visited-state">
153153
give your feedback by email
154154
</a>
155155
{% endif %}

0 commit comments

Comments
 (0)