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
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@
"@hapi/hapi": "^21.4.0",
"@hapi/inert": "^7.1.0",
"@hapi/jwt": "^3.2.0",
"@hapi/scooter": "^7.0.0",
"@hapi/vision": "^7.0.3",
"@hapi/yar": "^11.0.3",
"accessible-autocomplete": "^3.0.1",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"aws-embedded-metrics": "^4.2.0",
"babel-plugin-module-resolver": "^5.0.2",
"blankie": "^5.0.0",
"convict": "^6.2.4",
"cssnano": "^7.1.0",
"cssnano-preset-default": "^7.0.8",
Expand Down
22 changes: 22 additions & 0 deletions src/server/check-responses/check-responses.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SummaryPageController } from '@defra/forms-engine-plugin/controllers/SummaryPageController.js'

export default class CheckResponsesPageController extends SummaryPageController {
Comment thread
davidatdefra marked this conversation as resolved.
/**
* @param {FormModel} model
* @param {PageSummary} pageDef
*/
constructor(model, pageDef) {
super(model, pageDef)
this.viewName = 'check-responses-page'
}

getSummaryPath() {
return this.path
}

makePostRouteHandler() {
return (request, context, h) => {
return this.proceed(request, h, this.getNextPath(context))
}
}
}
137 changes: 137 additions & 0 deletions src/server/check-responses/check-responses.controller.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { SummaryPageController } from '@defra/forms-engine-plugin/controllers/SummaryPageController.js'
import { existsSync } from 'fs'
import { join } from 'path'
import CheckResponsesPageController from '~/src/server/check-responses/check-responses.controller.js'

describe('CheckResponsesPageController', () => {
let controller
let mockModel
let mockPageDef

beforeEach(() => {
mockModel = {
basePath: '/test-form'
}
mockPageDef = {
path: '/check-answers',
title: 'Check your answers'
}
controller = new CheckResponsesPageController(mockModel, mockPageDef)
})

describe('constructor', () => {
it('should extend SummaryPageController', () => {
expect(controller).toBeInstanceOf(SummaryPageController)
})

it('should set viewName to check-responses-page', () => {
expect(controller.viewName).toBe('check-responses-page')
})
})

describe('getSummaryPath', () => {
it('returns this.path when set', () => {
controller.path = mockPageDef.path

const result = controller.getSummaryPath()

expect(result).toBe('/check-answers')
})

it('reflects updates to this.path', () => {
controller.path = '/check-answers'
expect(controller.getSummaryPath()).toBe('/check-answers')

controller.path = '/updated-check-answers'
expect(controller.getSummaryPath()).toBe('/updated-check-answers')
})

it('returns undefined if this.path is not set - plugin will then use fallback /summary', () => {
expect(controller.getSummaryPath()).toBeUndefined()
})
})

describe('makePostRouteHandler', () => {
let handler

beforeEach(() => {
handler = controller.makePostRouteHandler()
})

it('should return a function', () => {
expect(typeof handler).toBe('function')
})

it('should call getNextPath with context and proceed with correct arguments, returning its result', () => {
const request = { method: 'post', path: '/some-path' }
const context = { payload: { foo: 'bar' } }
const h = { redirect: jest.fn() }

const nextPath = '/test-form/declaration'

controller.getNextPath = jest.fn().mockReturnValue(nextPath)
const proceedResult = Symbol('proceed-result')
controller.proceed = jest.fn().mockReturnValue(proceedResult)

const result = handler(request, context, h)

expect(controller.getNextPath).toHaveBeenCalledTimes(1)
expect(controller.getNextPath).toHaveBeenCalledWith(context)

expect(controller.proceed).toHaveBeenCalledTimes(1)
expect(controller.proceed).toHaveBeenCalledWith(request, h, nextPath)

expect(result).toBe(proceedResult)
})

it('should preserve controller context inside returned handler', () => {
// If `this` is lost, spies won't be hit
const request = {}
const context = {}
const h = {}

controller.getNextPath = jest.fn().mockReturnValue('/next')
controller.proceed = jest.fn().mockReturnValue('ok')

const fn = controller.makePostRouteHandler()
const ret = fn(request, context, h)

expect(controller.proceed).toHaveBeenCalledWith(request, h, '/next')
expect(ret).toBe('ok')
})
})

describe('integration with SummaryPageController', () => {
it('should properly set up the controller instance', () => {
expect(controller).toBeDefined()
expect(controller.viewName).toBe('check-responses-page')
expect(controller).toHaveProperty('makePostRouteHandler')
})

it('should override getSummaryPath from parent', () => {
expect(controller.getSummaryPath).toBeDefined()
})

it('should override makePostRouteHandler from parent', () => {
const handler = controller.makePostRouteHandler()
expect(typeof handler).toBe('function')
expect(handler.constructor.name).toBe('Function')
})
})

describe('view file existence', () => {
it('should reference a view file that actually exists', () => {
const viewPath = controller.viewName
expect(viewPath).toBe('check-responses-page')

// Check that the view file exists at the expected location
const absoluteViewPath = join(process.cwd(), 'src/server/check-responses/views', `${viewPath}.html`)
expect(existsSync(absoluteViewPath)).toBe(true)
})

it('should have view file in the feature-based location', () => {
const featureViewPath = join(process.cwd(), 'src/server/check-responses/views/check-responses-page.html')
expect(existsSync(featureViewPath)).toBe(true)
})
})
})
42 changes: 42 additions & 0 deletions src/server/check-responses/views/check-responses-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends baseLayoutPath %}

{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% from "govuk/components/button/macro.njk" import govukButton %}

{% block pageTitle %}
{{ pageTitle | evaluate }} | {{ serviceName }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{% block table %}
<h1 class="govuk-heading-l">{{ pageTitle }}</h1>

{% for section in checkAnswers %}
{% if section.title.text %}
<h2 class="govuk-heading-m">
{{ section.title.text }}
</h2>
{% endif %}

{{ govukSummaryList(section.summaryList) }}
{% endfor %}

{% endblock %}

{% block form %}
<form method="post" novalidate>
<input type="hidden" name="crumb" value="{{ crumb }}">

<div class="govuk-button-group">
{{ govukButton({
text: "Continue",
preventDoubleClick: true
}) }}
</div>
</form>
{% endblock %}
</div>
</div>
{% endblock %}
5 changes: 3 additions & 2 deletions src/server/common/forms/definitions/adding-value.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,9 @@ pages:
shortDescription: Project postcode
id: abcddf63-8379-40f7-aa5e-941c663b273a
id: 0e08708a-f393-40fa-86a6-d30bc736a354
- title: Check your details
path: /check-details
- title: Check your answers
path: /summary
Comment thread
davidatdefra marked this conversation as resolved.
controller: CheckResponsesPageController
id: 8de1f74b-f328-4363-a3de-a5fae6b891b0
- title: Confirm and send
path: /declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ pages:
options: {}
schema: {}
id: 089374a5-13e7-494d-994e-9b38c4b7392c
- title: Check your details
- title: Check your answers
path: /summary
controller: SummaryPageController
components: []
controller: CheckResponsesPageController
id: aa34c1e0-e119-4e69-ab91-06d6b092055e
- title: Confirm and send
path: /declaration
Expand Down
6 changes: 3 additions & 3 deletions src/server/common/templates/layouts/page.njk
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
{% if auth.isAuthenticated %}
<div class="gov-grid-row">
<div style="float:right;clear:both;text-align:right;">
<p class="govuk-body govuk-!-margin-bottom-0">Signed in as <a href="/home" class="govuk-link">{{ auth.name }}</a></p>
<!-- <p class="govuk-body govuk-!-margin-bottom-0"><a href="/auth/organisation" class="govuk-link">Switch organisation</a></p> -->
<p class="govuk-body govuk-!-margin-bottom-0"><a href="/auth/sign-out" class="govuk-link">Sign out</a></p>
<p class="govuk-body govuk-!-margin-bottom-0">Signed in as <a href="/home" class="govuk-link govuk-link--no-visited-state">{{ auth.name }}</a></p>
<!-- <p class="govuk-body govuk-!-margin-bottom-0"><a href="/auth/organisation" class="govuk-link govuk-link--no-visited-state">Switch organisation</a></p> -->
<p class="govuk-body govuk-!-margin-bottom-0"><a href="/auth/sign-out" class="govuk-link govuk-link--no-visited-state">Sign out</a></p>
</div>
</div>
{% endif %}
Expand Down
68 changes: 34 additions & 34 deletions src/server/confirmation/views/confirmation-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
{% set mainClasses = "govuk-main-wrapper--l" %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
titleText: "Details submitted",
html: ("Your reference number<br><strong>" + referenceNumber + "</strong>") | safe
}) }}
<p class="govuk-body">We have sent you a confirmation email with a record of your answers.</p>
<p class="govuk-body">If you do not get an email within 72 hours, call the RPA helpline and follow the options for the Farming Investment Fund scheme.</p>
<p class="govuk-body">You can <a href="https://www.gov.uk/government/publications/adding-value-grant-for-farmers-to-improve-crops-or-livestock/how-to-apply-for-an-adding-value-grant">check if you can apply for another Adding Value project</a> in addition to top fruit storage.</p>
<h2 class="govuk-heading-m">RPA helpline</h2>
<h3 class="govuk-heading-s">Telephone</h3>
<p class="govuk-body govuk-!-margin-bottom-0">Telephone: 03000 200 301</p>
<p class="govuk-body">Monday to Friday, 9am to 5pm (except public holidays)</p>
<p class="govuk-body"><a href="https://www.gov.uk/call-charges">Find out about call charges</a></p>
<h3 class="govuk-heading-s">Email</h3>
<p class="govuk-body"><a href="mailto:FTF@rpa.gov.uk">FTF@rpa.gov.uk</a></p>
<h3 class="govuk-heading-s">What happens next</h3>
<ol class="govuk-list govuk-list--number">
<li class="govuk-body govuk-!-margin-left-3">The RPA will contact you when the full application period opens. They will tell you if your project scored well enough to get the full application form.</li>
<li class="govuk-body govuk-!-margin-left-3">If you submit an application, the RPA will assess it against other projects and value for money. You will not automatically get a grant. The grant is expected to be highly competitive and you are competing against other projects.</li>
<li class="govuk-body govuk-!-margin-left-3">If your application is successful, you'll be sent a funding agreement and can begin work on the project.</li>
</ol>
<div class="govuk-warning-text"><span class="govuk-warning-text__icon" aria-hidden="true">!</span><strong class="govuk-warning-text__text">You must not start the project</strong></div>
<p class="govuk-body">Starting the project or committing to any costs (such as placing orders) before you receive a funding agreement will invalidate your application.</p>
<p class="govuk-body">Before you start the project, you can:</p>
<ul class="govuk-list govuk-list--bullet">
<li>get quotes from suppliers</li>
<li>apply for planning permission</li>
</ul>
<div class="govuk-body govuk-!-margin-top-9">
<p class="govuk-body"><a href="https://example.com/feedback">What do you think of this service?</a></p>
</div>
</div>
</div>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukPanel({
titleText: "Details submitted",
html: ("Your reference number<br><strong>" + referenceNumber + "</strong>") | safe
}) }}
<p class="govuk-body">We have sent you a confirmation email with a record of your answers.</p>
<p class="govuk-body">If you do not get an email within 72 hours, call the RPA helpline and follow the options for the Farming Investment Fund scheme.</p>
<p class="govuk-body">You can <a class="govuk-link" href="https://www.gov.uk/government/publications/adding-value-grant-for-farmers-to-improve-crops-or-livestock/how-to-apply-for-an-adding-value-grant">check if you can apply for another Adding Value project</a> in addition to top fruit storage.</p>
<h2 class="govuk-heading-m">RPA helpline</h2>
<h3 class="govuk-heading-s">Telephone</h3>
<p class="govuk-body govuk-!-margin-bottom-0">Telephone: 03000 200 301</p>
<p class="govuk-body">Monday to Friday, 9am to 5pm (except public holidays)</p>
<p class="govuk-body"><a class="govuk-link" href="https://www.gov.uk/call-charges">Find out about call charges</a></p>
<h3 class="govuk-heading-s">Email</h3>
<p class="govuk-body"><a class="govuk-link" href="mailto:FTF@rpa.gov.uk">FTF@rpa.gov.uk</a></p>
<h3 class="govuk-heading-s">What happens next</h3>
<ol class="govuk-list govuk-list--number">
<li class="govuk-body govuk-!-margin-left-3">The RPA will contact you when the full application period opens. They will tell you if your project scored well enough to get the full application form.</li>
<li class="govuk-body govuk-!-margin-left-3">If you submit an application, the RPA will assess it against other projects and value for money. You will not automatically get a grant. The grant is expected to be highly competitive and you are competing against other projects.</li>
<li class="govuk-body govuk-!-margin-left-3">If your application is successful, you'll be sent a funding agreement and can begin work on the project.</li>
</ol>
<div class="govuk-warning-text"><span class="govuk-warning-text__icon" aria-hidden="true">!</span><strong class="govuk-warning-text__text">You must not start the project</strong></div>
<p class="govuk-body">Starting the project or committing to any costs (such as placing orders) before you receive a funding agreement will invalidate your application.</p>
<p class="govuk-body">Before you start the project, you can:</p>
<ul class="govuk-list govuk-list--bullet">
<li>get quotes from suppliers</li>
<li>apply for planning permission</li>
</ul>
<div class="govuk-body govuk-!-margin-top-9">
<p class="govuk-body"><a class="govuk-link" href="https://example.com/feedback">What do you think of this service?</a></p>
</div>
</div>
</div>
{% endblock %}
Loading
Loading