Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/server/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
pathSchema,
stateSchema
} from '@defra/forms-engine-plugin/schema.js'
import { slugSchema } from '@defra/forms-model'
import { FormStatus, slugSchema } from '@defra/forms-model'
import Boom from '@hapi/boom'
import {
type Request,
Expand All @@ -34,7 +34,10 @@ import {
publicRoutes,
saveAndExitRoutes
} from '~/src/server/routes/index.js'
import { getFormMetadata } from '~/src/server/services/formsService.js'
import {
getFormDefinition,
getFormMetadata
} from '~/src/server/services/formsService.js'
import { getFeedbackFormLink } from '~/src/server/utils/utils.js'

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

return h.view('help/privacy-notice', {
form,
saveAndExitExpiryDays,
storeCompletedApplicationsFor,
storeFeedbackFor
storeFeedbackFor,
...(definition?.options?.disableUserFeedback
? {}
: getFeedbackFormLink(form.id))
})
},
options
Expand All @@ -151,9 +158,13 @@ export default {
async handler(request, h) {
const { slug } = request.params
const form = await getFormMetadata(slug)
const definition = await getFormDefinition(form.id, FormStatus.Draft)

return h.view('help/privacy-notice-specific', {
form
form,
...(definition?.options?.disableUserFeedback
? {}
: getFeedbackFormLink(form.id))
})
},
options
Expand Down
86 changes: 83 additions & 3 deletions src/server/routes/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { type FormDefinition, type FormMetadata } from '@defra/forms-model'
import { type Server } from '@hapi/hapi'
import { StatusCodes } from 'http-status-codes'

import { config } from '~/src/config/index.js'
import { createServer } from '~/src/server/index.js'
import { getFormMetadata } from '~/src/server/services/formsService.js'
import {
getFormDefinition,
getFormMetadata
} from '~/src/server/services/formsService.js'
import * as fixtures from '~/test/fixtures/index.js'
import { renderResponse } from '~/test/helpers/component-helpers.js'

Expand Down Expand Up @@ -163,7 +167,13 @@ describe('Routes', () => {
expect($banner).toHaveTextContent('Hello world')
})

test('privacy notice (general) page is served', async () => {
test('privacy notice (general) page is served with feedback form link', async () => {
jest
.mocked(getFormMetadata)
.mockResolvedValueOnce({ id: '123' } as unknown as FormMetadata)
jest
.mocked(getFormDefinition)
.mockResolvedValueOnce({} as unknown as FormDefinition)
const options = {
method: 'GET',
url: '/help/privacy/slug'
Expand All @@ -176,11 +186,76 @@ describe('Routes', () => {
level: 1
})

const $link = container.getByRole('link', {
name: 'give your feedback (opens in new tab)'
})

expect($heading).toBeInTheDocument()
expect($heading).toHaveClass('govuk-heading-l')
expect($link).toBeInTheDocument()
})

test('privacy notice (general) page is served with feedback by email link', async () => {
jest
.mocked(getFormMetadata)
.mockResolvedValueOnce({ id: '123' } as unknown as FormMetadata)
jest.mocked(getFormDefinition).mockResolvedValueOnce({
options: { disableUserFeedback: true }
} as unknown as FormDefinition)
const options = {
method: 'GET',
url: '/help/privacy/slug'
}

const { container } = await renderResponse(server, options)

const $heading = container.getByRole('heading', {
name: 'Submit a form to Defra - privacy notice',
level: 1
})

const $link = container.getByRole('link', {
name: 'give your feedback by email'
})

expect($heading).toBeInTheDocument()
expect($heading).toHaveClass('govuk-heading-l')
expect($link).toBeInTheDocument()
})

test('privacy notice (specific) page is served with feedback form link', async () => {
jest
.mocked(getFormDefinition)
.mockResolvedValueOnce({} as unknown as FormDefinition)
jest.mocked(getFormMetadata).mockResolvedValue({
...fixtures.form.metadata,
privacyNoticeType: 'text',
privacyNoticeText: '# Privacy markdown heading'
})
const options = {
method: 'GET',
url: '/help/privacy-specific/slug'
}

const { container } = await renderResponse(server, options)

const $heading = container.getByRole('heading', {
name: 'Privacy markdown heading',
level: 1
})

const $link = container.getByRole('link', {
name: 'give your feedback (opens in new tab)'
})

expect($heading).toBeInTheDocument()
expect($link).toBeInTheDocument()
})

test('privacy notice (specific) page is served', async () => {
test('privacy notice (specific) page is served with feedback by email link', async () => {
jest.mocked(getFormDefinition).mockResolvedValueOnce({
options: { disableUserFeedback: true }
} as unknown as FormDefinition)
jest.mocked(getFormMetadata).mockResolvedValue({
...fixtures.form.metadata,
privacyNoticeType: 'text',
Expand All @@ -198,6 +273,11 @@ describe('Routes', () => {
level: 1
})

const $link = container.getByRole('link', {
name: 'give your feedback by email'
})

expect($heading).toBeInTheDocument()
expect($link).toBeInTheDocument()
})
})
4 changes: 2 additions & 2 deletions src/server/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@
{% if phaseTag and not hidePhaseBanner %}
{% set feedbackLinkHtml -%}
{% if feedbackLink %}
<a href="{{ currentPath if context.isForceAccess else feedbackLink }}" class="govuk-link" {%- if not context.isForceAccess %} target="_blank" rel="noopener noreferrer" {%- endif %}>
<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 %}>
give your feedback (opens in new tab)
</a>
{% else %}
<a href="mailto:{{ config.feedbackViaEmail }}" class="govuk-link">
<a href="mailto:{{ config.feedbackViaEmail }}" class="govuk-link govuk-link--no-visited-state">
give your feedback by email
</a>
{% endif %}
Expand Down
Loading