From cb7c72993eba72f679c9d54b5dee9f9c58bc1073 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 12:46:08 +0000
Subject: [PATCH 01/12] WIP radio buttons template added to onOffPremises
---
.../question-page-controller.js | 1 +
src/server/origin/on-off-farm/index.njk | 30 +++++++++----------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/server/common/controller/question-page-controller/question-page-controller.js b/src/server/common/controller/question-page-controller/question-page-controller.js
index 17f0dc0d..8e4b10be 100644
--- a/src/server/common/controller/question-page-controller/question-page-controller.js
+++ b/src/server/common/controller/question-page-controller/question-page-controller.js
@@ -51,6 +51,7 @@ export class QuestionPageController extends GenericPageController {
pageTitle: this.page.title,
heading: this.page.heading,
value: answer.value,
+ answer,
...this.page.viewProps(req)
})
}
diff --git a/src/server/origin/on-off-farm/index.njk b/src/server/origin/on-off-farm/index.njk
index e3a21874..663dd344 100644
--- a/src/server/origin/on-off-farm/index.njk
+++ b/src/server/origin/on-off-farm/index.njk
@@ -2,26 +2,26 @@
{% extends 'layouts/questions.njk' %}
{% block questions %}
+ {# {% include "common/model/answer/radio-button/radio-button.njk" %} #}
+ {% set items = [] %}
+ {% for key,option in answer.config.options %}
+ {%
+ set items = (items.push( {
+ id: key,
+ value: key,
+ text: option.label
+ }), items)
+ %}
+ {% endfor %}
{{
govukRadios({
- name: "onOffFarm",
- id: "on-off-farm",
+ name: answer.config.payloadKey,
+ id: answer.config.payloadKey,
fieldset:{},
value: value,
- items: [
- {
- id: "onOffFarm",
- value: "on",
- text: "On to the farm or premises"
- },
- {
- id: "off-farm-radio",
- value: "off",
- text: "Off the farm or premises"
- }
- ],
- errorMessage: errors.onOffFarm
+ items: items,
+ errorMessage: errors[answer.config.payloadKey]
})
}}
{% endblock %}
From 96f70c111b695c8a52f38571ec430ef7f876f897 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 13:09:44 +0000
Subject: [PATCH 02/12] Created radio-buttons template and used it in
onOffPremises template
---
.../templates/components/radio-button.njk | 21 +++++++++++++++++
src/server/origin/on-off-farm/index.njk | 23 +------------------
2 files changed, 22 insertions(+), 22 deletions(-)
create mode 100644 src/server/common/templates/components/radio-button.njk
diff --git a/src/server/common/templates/components/radio-button.njk b/src/server/common/templates/components/radio-button.njk
new file mode 100644
index 00000000..9342d14f
--- /dev/null
+++ b/src/server/common/templates/components/radio-button.njk
@@ -0,0 +1,21 @@
+{% set items = [] %}
+{% for key,option in answer.config.options %}
+ {%
+ set items = (items.push( {
+ id: key,
+ value: key,
+ text: option.label
+ }), items)
+ %}
+{% endfor %}
+
+{{
+ govukRadios({
+ name: answer.config.payloadKey,
+ id: answer.config.payloadKey,
+ fieldset:{},
+ value: value,
+ items: items,
+ errorMessage: errors[answer.config.payloadKey]
+ })
+}}
diff --git a/src/server/origin/on-off-farm/index.njk b/src/server/origin/on-off-farm/index.njk
index 663dd344..0904dc05 100644
--- a/src/server/origin/on-off-farm/index.njk
+++ b/src/server/origin/on-off-farm/index.njk
@@ -2,26 +2,5 @@
{% extends 'layouts/questions.njk' %}
{% block questions %}
- {# {% include "common/model/answer/radio-button/radio-button.njk" %} #}
- {% set items = [] %}
- {% for key,option in answer.config.options %}
- {%
- set items = (items.push( {
- id: key,
- value: key,
- text: option.label
- }), items)
- %}
- {% endfor %}
-
- {{
- govukRadios({
- name: answer.config.payloadKey,
- id: answer.config.payloadKey,
- fieldset:{},
- value: value,
- items: items,
- errorMessage: errors[answer.config.payloadKey]
- })
- }}
+ {% include "components/radio-button.njk" %}
{% endblock %}
From ca80dba3a9b92dd76390f9d0f6c80df69711dea2 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 14:10:51 +0000
Subject: [PATCH 03/12] Moved radio-button template to the model folder
---
src/config/nunjucks/nunjucks.js | 3 ++-
.../components => model/answer/radio-button}/radio-button.njk | 0
src/server/origin/on-off-farm/index.njk | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
rename src/server/common/{templates/components => model/answer/radio-button}/radio-button.njk (100%)
diff --git a/src/config/nunjucks/nunjucks.js b/src/config/nunjucks/nunjucks.js
index 1e7fe6b4..24908b9b 100644
--- a/src/config/nunjucks/nunjucks.js
+++ b/src/config/nunjucks/nunjucks.js
@@ -13,7 +13,8 @@ const nunjucksEnvironment = nunjucks.configure(
[
'node_modules/govuk-frontend/dist/',
path.resolve(dirname, '../../server/common/templates'),
- path.resolve(dirname, '../../server/common/components')
+ path.resolve(dirname, '../../server/common/components'),
+ path.resolve(dirname, '../../server/common')
],
{
autoescape: true,
diff --git a/src/server/common/templates/components/radio-button.njk b/src/server/common/model/answer/radio-button/radio-button.njk
similarity index 100%
rename from src/server/common/templates/components/radio-button.njk
rename to src/server/common/model/answer/radio-button/radio-button.njk
diff --git a/src/server/origin/on-off-farm/index.njk b/src/server/origin/on-off-farm/index.njk
index 0904dc05..665d1ba8 100644
--- a/src/server/origin/on-off-farm/index.njk
+++ b/src/server/origin/on-off-farm/index.njk
@@ -2,5 +2,5 @@
{% extends 'layouts/questions.njk' %}
{% block questions %}
- {% include "components/radio-button.njk" %}
+ {% include "model/answer/radio-button/radio-button.njk" %}
{% endblock %}
From 471e4286f316200f253c39f22f81dbc0a4caa7dc Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 14:32:05 +0000
Subject: [PATCH 04/12] Added answer to the view returned by POST
---
.../question-page-controller/question-page-controller.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/server/common/controller/question-page-controller/question-page-controller.js b/src/server/common/controller/question-page-controller/question-page-controller.js
index 8e4b10be..442891ec 100644
--- a/src/server/common/controller/question-page-controller/question-page-controller.js
+++ b/src/server/common/controller/question-page-controller/question-page-controller.js
@@ -73,6 +73,7 @@ export class QuestionPageController extends GenericPageController {
pageTitle: `Error: ${this.page.title}`,
heading: this.page.heading,
value: answer.value,
+ answer,
errors,
errorMessages: Answer.errorMessages(errors),
...this.page.viewProps(req)
From 0294e781b52a06c7ef6727e387cd2aa86a07ae11 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 14:51:45 +0000
Subject: [PATCH 05/12] Added getter for radio buttons viewModel to build list
of items
---
.../model/answer/radio-button/radio-button.js | 10 ++++++++++
.../model/answer/radio-button/radio-button.njk | 13 +------------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/server/common/model/answer/radio-button/radio-button.js b/src/server/common/model/answer/radio-button/radio-button.js
index 298c8c36..ad0172a2 100644
--- a/src/server/common/model/answer/radio-button/radio-button.js
+++ b/src/server/common/model/answer/radio-button/radio-button.js
@@ -90,4 +90,14 @@ export class RadioButtonAnswer extends AnswerModel {
[this.config.payloadKey]: fields[this.config.payloadKey]
})
}
+
+ get viewModelItems() {
+ const result = Object.entries(this.config.options).map(([key, value]) => ({
+ id: key,
+ value: key,
+ text: value.label
+ }))
+ result[0].id = this.config.payloadKey
+ return result
+ }
}
diff --git a/src/server/common/model/answer/radio-button/radio-button.njk b/src/server/common/model/answer/radio-button/radio-button.njk
index 9342d14f..6cc17f3b 100644
--- a/src/server/common/model/answer/radio-button/radio-button.njk
+++ b/src/server/common/model/answer/radio-button/radio-button.njk
@@ -1,21 +1,10 @@
-{% set items = [] %}
-{% for key,option in answer.config.options %}
- {%
- set items = (items.push( {
- id: key,
- value: key,
- text: option.label
- }), items)
- %}
-{% endfor %}
-
{{
govukRadios({
name: answer.config.payloadKey,
id: answer.config.payloadKey,
fieldset:{},
value: value,
- items: items,
+ items: answer.viewModelItems,
errorMessage: errors[answer.config.payloadKey]
})
}}
From 659bf545296aff542ef384a49a86ae450d9637ef Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 16:14:05 +0000
Subject: [PATCH 06/12] Unit tests
---
.../question-page-controller.test.js | 64 +++++++++++++++++++
.../answer/radio-button/radio-button.test.js | 19 ++++++
2 files changed, 83 insertions(+)
diff --git a/src/server/common/controller/question-page-controller/question-page-controller.test.js b/src/server/common/controller/question-page-controller/question-page-controller.test.js
index f22aea23..99816f7f 100644
--- a/src/server/common/controller/question-page-controller/question-page-controller.test.js
+++ b/src/server/common/controller/question-page-controller/question-page-controller.test.js
@@ -404,4 +404,68 @@ describe('QuestionPageController', () => {
expect(headers.location).toBe(`${overriddenQuestionUrl}?redirect=true`)
})
})
+
+ describe('View render', () => {
+ const h = {
+ view: jest.fn().mockReturnValue('view')
+ }
+ const request = {
+ yar: {
+ get: jest.fn(),
+ set: jest.fn()
+ },
+ query: {
+ redirect_uri: 'redirect_uri'
+ }
+ }
+
+ it('GET should render view with expected arguments', () => {
+ const result = controller.getHandler(request, h)
+
+ expect(h.view).toHaveBeenCalledTimes(1)
+ expect(h.view).toHaveBeenCalledWith(
+ questionView,
+ expect.objectContaining({
+ heading: question,
+ nextPage: 'redirect_uri',
+ pageTitle: question,
+ value: undefined
+ })
+ )
+
+ const viewArgs = h.view.mock.calls[0][1]
+ expect(viewArgs.answer).toBeInstanceOf(TestAnswer)
+
+ expect(result).toBe('view')
+ })
+
+ it('POST should render view with expected arguments', () => {
+ const postRequest = {
+ ...request,
+ payload: { nextPage: 'test_next_page' }
+ }
+
+ const result = controller.postHandler(postRequest, h)
+
+ expect(h.view).toHaveBeenCalledTimes(1)
+ expect(h.view).toHaveBeenCalledWith(
+ questionView,
+ expect.objectContaining({
+ errorMessages: [
+ { href: `#${questionKey}`, text: 'There is a problem' }
+ ],
+ errors: { questionKey: { text: 'There is a problem' } },
+ heading: question,
+ nextPage: 'test_next_page',
+ pageTitle: `Error: ${question}`,
+ value: undefined
+ })
+ )
+
+ const viewArgs = h.view.mock.calls[0][1]
+ expect(viewArgs.answer).toBeInstanceOf(TestAnswer)
+
+ expect(result).toBe('view')
+ })
+ })
})
diff --git a/src/server/common/model/answer/radio-button/radio-button.test.js b/src/server/common/model/answer/radio-button/radio-button.test.js
index e52feb27..033a0ba6 100644
--- a/src/server/common/model/answer/radio-button/radio-button.test.js
+++ b/src/server/common/model/answer/radio-button/radio-button.test.js
@@ -139,4 +139,23 @@ describe('RadioButton', () => {
expect(new RadioButtonTest(undefined).html).toBe('')
})
})
+
+ describe('#RadioButton.viewModelItems', () => {
+ it('should return the list of items from the config options and first item with the payloadKey', () => {
+ const viewModelItems = new RadioButtonTest().viewModelItems
+
+ expect(viewModelItems).toEqual([
+ {
+ id: 'test_radio',
+ value: 'value_1',
+ text: 'test_label_1'
+ },
+ {
+ id: 'value_2',
+ value: 'value_2',
+ text: 'test_label_2'
+ }
+ ])
+ })
+ })
})
From 3d39768eaa4ee3de1ad1d97ce0ad374e6110df69 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 16:53:20 +0000
Subject: [PATCH 07/12] Using radio button template and model in destination
type, receive method, etc
---
.../__snapshots__/index.test.js.snap | 2 +-
src/server/check-answers/index.test.js | 9 +--
.../destination-type/destination-type.js | 10 ++-
.../model/answer/origin-type/origin-type.js | 5 +-
.../model/answer/radio-button/radio-button.js | 5 +-
.../answer/radio-button/radio-button.test.js | 12 +++-
.../answer/receiveMethod/receiveMethod.js | 4 +-
.../receiveMethod/receiveMethod.test.js | 4 +-
.../__snapshots__/index.test.js.snap | 63 +++++++++++++++++++
.../destination/destination-type/index.njk | 39 +-----------
.../destination-type/index.test.js | 36 ++++++++++-
.../__snapshots__/index.test.js.snap | 45 +++++++++++++
src/server/licence/receiveMethod/index.njk | 24 +------
.../licence/receiveMethod/index.test.js | 36 ++++++++++-
src/server/origin/on-off-farm/index.njk | 2 +-
.../__snapshots__/index.test.js.snap | 54 ++++++++++++++++
src/server/origin/origin-type/index.njk | 31 +--------
src/server/origin/origin-type/index.test.js | 36 ++++++++++-
18 files changed, 306 insertions(+), 111 deletions(-)
create mode 100644 src/server/destination/destination-type/__snapshots__/index.test.js.snap
create mode 100644 src/server/licence/receiveMethod/__snapshots__/index.test.js.snap
create mode 100644 src/server/origin/origin-type/__snapshots__/index.test.js.snap
diff --git a/src/server/check-answers/__snapshots__/index.test.js.snap b/src/server/check-answers/__snapshots__/index.test.js.snap
index 7a129612..769044df 100644
--- a/src/server/check-answers/__snapshots__/index.test.js.snap
+++ b/src/server/check-answers/__snapshots__/index.test.js.snap
@@ -95,7 +95,7 @@ exports[`#CheckAnswers Should provide expected response 1`] = `
How would you like this licence sent to you?
- email
+ Email
Change How would you like this licence sent to you?
diff --git a/src/server/check-answers/index.test.js b/src/server/check-answers/index.test.js
index d8574e89..4e964b9f 100644
--- a/src/server/check-answers/index.test.js
+++ b/src/server/check-answers/index.test.js
@@ -19,7 +19,8 @@ const testAddress = {
addressPostcode: 'RG24 8RR'
}
const testEmailAddress = 'name@example.com'
-const testReceiveMethod = 'email'
+const testReceiveMethodValue = 'email'
+const testReceiveMethodLabel = 'Email'
const originDefaultState = {
onOffFarm: 'off',
@@ -30,7 +31,7 @@ const originDefaultState = {
const licenceDefaultState = {
emailAddress: testEmailAddress,
- receiveMethod: testReceiveMethod,
+ receiveMethod: testReceiveMethodValue,
fullName: {
firstName: 'William T.',
lastName: 'Riker'
@@ -67,7 +68,7 @@ const emailContent = [
' ' +
licenceDefaultState.fullName.lastName,
'## How would you like this licence sent to you?',
- testReceiveMethod,
+ testReceiveMethodLabel,
'## What email address would you like the licence sent to?',
testEmailAddress
].join('\n')
@@ -125,7 +126,7 @@ describe('#CheckAnswers', () => {
expect(taskListValues[5].innerHTML).toContain(
`${licenceDefaultState.fullName.firstName} ${licenceDefaultState.fullName.lastName}`
)
- expect(taskListValues[6].innerHTML).toContain(testReceiveMethod)
+ expect(taskListValues[6].innerHTML).toContain(testReceiveMethodLabel)
expect(taskListValues[7].innerHTML).toContain(testEmailAddress)
expect(statusCode).toBe(statusCodes.ok)
diff --git a/src/server/common/model/answer/destination-type/destination-type.js b/src/server/common/model/answer/destination-type/destination-type.js
index 8e8f9183..6b57843c 100644
--- a/src/server/common/model/answer/destination-type/destination-type.js
+++ b/src/server/common/model/answer/destination-type/destination-type.js
@@ -7,8 +7,14 @@ const onOffFarmConfig = {
options: {
slaughter: { label: 'Slaughter' },
'dedicated-sale': { label: 'Dedicated sale for TB (orange market)' },
- afu: { label: 'Approved finishing unit (AFU)' },
- other: { label: 'Another destination' }
+ afu: {
+ label: 'Approved finishing unit (AFU)',
+ hint: 'Including enhanced with grazing (AFUE)'
+ },
+ other: {
+ label: 'Another destination',
+ hint: 'For example, a veterinary practice, zoo, or a laboratory'
+ }
},
errors: {
emptyOptionText: 'Select where the animals are going'
diff --git a/src/server/common/model/answer/origin-type/origin-type.js b/src/server/common/model/answer/origin-type/origin-type.js
index f11791fb..983bd048 100644
--- a/src/server/common/model/answer/origin-type/origin-type.js
+++ b/src/server/common/model/answer/origin-type/origin-type.js
@@ -6,7 +6,10 @@ const config = {
payloadKey: 'originType',
options: {
'tb-restricted-farm': { label: 'TB restricted farm' },
- afu: { label: 'Approved finishing unit (AFU)' },
+ afu: {
+ label: 'Approved finishing unit (AFU)',
+ hint: 'Including enhanced with grazing (AFUE)'
+ },
other: { label: 'Another type of premises' }
},
errors: {
diff --git a/src/server/common/model/answer/radio-button/radio-button.js b/src/server/common/model/answer/radio-button/radio-button.js
index ad0172a2..c074af25 100644
--- a/src/server/common/model/answer/radio-button/radio-button.js
+++ b/src/server/common/model/answer/radio-button/radio-button.js
@@ -95,7 +95,10 @@ export class RadioButtonAnswer extends AnswerModel {
const result = Object.entries(this.config.options).map(([key, value]) => ({
id: key,
value: key,
- text: value.label
+ text: value.label,
+ hint: {
+ text: value.hint
+ }
}))
result[0].id = this.config.payloadKey
return result
diff --git a/src/server/common/model/answer/radio-button/radio-button.test.js b/src/server/common/model/answer/radio-button/radio-button.test.js
index 033a0ba6..31361124 100644
--- a/src/server/common/model/answer/radio-button/radio-button.test.js
+++ b/src/server/common/model/answer/radio-button/radio-button.test.js
@@ -17,7 +17,7 @@ const testRadioConfig = {
payloadKey: 'test_radio',
options: {
value_1: { label: 'test_label_1' },
- value_2: { label: 'test_label_2' }
+ value_2: { label: 'test_label_2', hint: 'test_hint_2' }
},
errors: {
emptyOptionText: 'Select an option'
@@ -148,12 +148,18 @@ describe('RadioButton', () => {
{
id: 'test_radio',
value: 'value_1',
- text: 'test_label_1'
+ text: 'test_label_1',
+ hint: {
+ text: undefined
+ }
},
{
id: 'value_2',
value: 'value_2',
- text: 'test_label_2'
+ text: 'test_label_2',
+ hint: {
+ text: 'test_hint_2'
+ }
}
])
})
diff --git a/src/server/common/model/answer/receiveMethod/receiveMethod.js b/src/server/common/model/answer/receiveMethod/receiveMethod.js
index 11d65e44..18835ef0 100644
--- a/src/server/common/model/answer/receiveMethod/receiveMethod.js
+++ b/src/server/common/model/answer/receiveMethod/receiveMethod.js
@@ -5,8 +5,8 @@ import { RadioButtonAnswer } from '../radio-button/radio-button.js'
const config = {
payloadKey: 'receiveMethod',
options: {
- email: { label: 'email' },
- post: { label: 'post' }
+ email: { label: 'Email' },
+ post: { label: 'Post' }
},
errors: {
emptyOptionText: 'Select how you would like this licence sent to you'
diff --git a/src/server/common/model/answer/receiveMethod/receiveMethod.test.js b/src/server/common/model/answer/receiveMethod/receiveMethod.test.js
index ad9be431..e3ace423 100644
--- a/src/server/common/model/answer/receiveMethod/receiveMethod.test.js
+++ b/src/server/common/model/answer/receiveMethod/receiveMethod.test.js
@@ -25,7 +25,7 @@ describe('ReceiveMethod', () => {
it('should have the expected options to select from', () => {
expect(Object.keys(ReceiveMethodAnswer.config.options)).toHaveLength(2)
- expect(ReceiveMethodAnswer.config.options.email.label).toBe('email')
- expect(ReceiveMethodAnswer.config.options.post.label).toBe('post')
+ expect(ReceiveMethodAnswer.config.options.email.label).toBe('Email')
+ expect(ReceiveMethodAnswer.config.options.post.label).toBe('Post')
})
})
diff --git a/src/server/destination/destination-type/__snapshots__/index.test.js.snap b/src/server/destination/destination-type/__snapshots__/index.test.js.snap
new file mode 100644
index 00000000..0082bbff
--- /dev/null
+++ b/src/server/destination/destination-type/__snapshots__/index.test.js.snap
@@ -0,0 +1,63 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`DestinationTypePage DestinationTypePage.content should render expected response and content 1`] = `
+"
+
+
+
Where are the animals going to?
+
+
+
+ "
+`;
diff --git a/src/server/destination/destination-type/index.njk b/src/server/destination/destination-type/index.njk
index 9c5f56f1..665d1ba8 100644
--- a/src/server/destination/destination-type/index.njk
+++ b/src/server/destination/destination-type/index.njk
@@ -2,42 +2,5 @@
{% extends 'layouts/questions.njk' %}
{% block questions %}
-
- {{
- govukRadios({
- name: "destinationType",
- id: "destination-type",
- fieldset:{},
- value: value,
- items: [
- {
- id: "destinationType",
- value: "slaughter",
- text: "Slaughter"
- },
- {
- id: "dedicatedSale",
- value: "dedicated-sale",
- text: "Dedicated sale for TB (orange market)"
- },
- {
- id: "afu",
- value: "afu",
- text: "Approved finishing unit (AFU)",
- hint: {
- text: "Including enhanced with grazing (AFUE)"
- }
- },
- {
- id: "other",
- value: "other",
- text: "Another destination",
- hint:{
- text: "For example, a veterinary practice, zoo, or a laboratory"
- }
- }
- ],
- errorMessage: errors.destinationType
- })
- }}
+ {% include "model/answer/radio-button/radio-button.njk" %}
{% endblock %}
diff --git a/src/server/destination/destination-type/index.test.js b/src/server/destination/destination-type/index.test.js
index c33dbf25..624e55a7 100644
--- a/src/server/destination/destination-type/index.test.js
+++ b/src/server/destination/destination-type/index.test.js
@@ -7,6 +7,10 @@ import { DestinationTypeAnswer } from '../../common/model/answer/destination-typ
import { destinationGeneralLicencePage } from '../general-licence/index.js'
import { destinationSummaryPage } from '../summary/index.js'
import { anotherDestinationPage } from '../another-destination/index.js'
+import { createServer } from '~/src/server/index.js'
+import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
+import { statusCodes } from '~/src/server/common/constants/status-codes.js'
+import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
const sectionKey = 'destination'
const question = 'Where are the animals going to?'
@@ -84,6 +88,36 @@ describe('DestinationTypePage', () => {
expect(plugin.name).toBe(`${sectionKey}-${questionKey}`)
expect(plugin).toHaveProperty('register')
})
+
+ describe('DestinationTypePage.content', () => {
+ /** @type {Server} */
+ let server
+
+ beforeAll(async () => {
+ server = await createServer()
+ await server.initialize()
+ })
+
+ afterAll(async () => {
+ await server.stop({ timeout: 0 })
+ })
+
+ it('should render expected response and content', async () => {
+ const { payload, statusCode } = await server.inject(
+ withCsrfProtection({
+ method: 'GET',
+ url: pageUrl
+ })
+ )
+
+ const document = parseDocument(payload)
+ expect(document.title).toBe(question)
+ expect(statusCode).toBe(statusCodes.ok)
+
+ const content = document.querySelector('#main-content')?.innerHTML
+ expect(content).toMatchSnapshot()
+ })
+ })
})
-/** @import { PluginBase, PluginNameVersion } from '@hapi/hapi' */
+/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
diff --git a/src/server/licence/receiveMethod/__snapshots__/index.test.js.snap b/src/server/licence/receiveMethod/__snapshots__/index.test.js.snap
new file mode 100644
index 00000000..055de87e
--- /dev/null
+++ b/src/server/licence/receiveMethod/__snapshots__/index.test.js.snap
@@ -0,0 +1,45 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`ReceiveMethodPage DestinationTypePage.content should render expected response and content 1`] = `
+"
+
+
+
How would you like this licence sent to you?
+
+
+
+ "
+`;
diff --git a/src/server/licence/receiveMethod/index.njk b/src/server/licence/receiveMethod/index.njk
index 7d32ca5b..a1a10ffa 100644
--- a/src/server/licence/receiveMethod/index.njk
+++ b/src/server/licence/receiveMethod/index.njk
@@ -2,27 +2,5 @@
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% extends 'layouts/questions.njk' %}
{% block questions %}
- {% call govukFieldset() %}
- {{
- govukRadios({
- name: "receiveMethod",
- id: "receive-method",
- fieldset:{},
- value: value,
- items: [
- {
- id: "receiveMethod",
- value: "email",
- text: "Email"
- },
- {
- id: "post",
- value: "post",
- text: "Post"
- }
- ],
- errorMessage: errors.receiveMethod
- })
- }}
- {% endcall %}
+ {% include "model/answer/radio-button/radio-button.njk" %}
{% endblock %}
diff --git a/src/server/licence/receiveMethod/index.test.js b/src/server/licence/receiveMethod/index.test.js
index 456eac32..b843a076 100644
--- a/src/server/licence/receiveMethod/index.test.js
+++ b/src/server/licence/receiveMethod/index.test.js
@@ -2,6 +2,10 @@ import { receiveMethod, receiveMethodPage, ReceiveMethodPage } from './index.js'
import { ReceiveMethodAnswer } from '../../common/model/answer/receiveMethod/receiveMethod.js'
import { emailAddressPage } from '../email-address/index.js'
import { postExitPage } from '../postExitPage/index.js'
+import { createServer } from '~/src/server/index.js'
+import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
+import { statusCodes } from '~/src/server/common/constants/status-codes.js'
+import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
// TODO: import next page object
@@ -71,6 +75,36 @@ describe('ReceiveMethodPage', () => {
expect(plugin.name).toBe(`${sectionKey}-${questionKey}`)
expect(plugin).toHaveProperty('register')
})
+
+ describe('DestinationTypePage.content', () => {
+ /** @type {Server} */
+ let server
+
+ beforeAll(async () => {
+ server = await createServer()
+ await server.initialize()
+ })
+
+ afterAll(async () => {
+ await server.stop({ timeout: 0 })
+ })
+
+ it('should render expected response and content', async () => {
+ const { payload, statusCode } = await server.inject(
+ withCsrfProtection({
+ method: 'GET',
+ url: pageUrl
+ })
+ )
+
+ const document = parseDocument(payload)
+ expect(document.title).toBe(question)
+ expect(statusCode).toBe(statusCodes.ok)
+
+ const content = document.querySelector('#main-content')?.innerHTML
+ expect(content).toMatchSnapshot()
+ })
+ })
})
-/** @import { PluginBase, PluginNameVersion } from '@hapi/hapi' */
+/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
diff --git a/src/server/origin/on-off-farm/index.njk b/src/server/origin/on-off-farm/index.njk
index 665d1ba8..5295d068 100644
--- a/src/server/origin/on-off-farm/index.njk
+++ b/src/server/origin/on-off-farm/index.njk
@@ -1,5 +1,5 @@
{% from "govuk/components/radios/macro.njk" import govukRadios %}
-{% extends 'layouts/questions.njk' %}
+{% extends 'templates/layouts/questions.njk' %}
{% block questions %}
{% include "model/answer/radio-button/radio-button.njk" %}
diff --git a/src/server/origin/origin-type/__snapshots__/index.test.js.snap b/src/server/origin/origin-type/__snapshots__/index.test.js.snap
new file mode 100644
index 00000000..000ef9ad
--- /dev/null
+++ b/src/server/origin/origin-type/__snapshots__/index.test.js.snap
@@ -0,0 +1,54 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`OriginTypePage OriginTypePage.content should render expected response and content 1`] = `
+"
+
+
+
What type of premises are the animals moving off?
+
+
+
+ "
+`;
diff --git a/src/server/origin/origin-type/index.njk b/src/server/origin/origin-type/index.njk
index b54d545a..665d1ba8 100644
--- a/src/server/origin/origin-type/index.njk
+++ b/src/server/origin/origin-type/index.njk
@@ -2,34 +2,5 @@
{% extends 'layouts/questions.njk' %}
{% block questions %}
-
- {{
- govukRadios({
- name: "originType",
- id: "origin-type",
- fieldset:{},
- value: value,
- items: [
- {
- id: "originType",
- value: "tb-restricted-farm",
- text: "TB restricted farm"
- },
- {
- id: "afu-radio",
- value: "afu",
- text: "Approved finishing unit (AFU)",
- hint: {
- text: "Including enhanced with grazing (AFUE)"
- }
- },
- {
- id: "other-radio",
- value: "other",
- text: "Another type of premises"
- }
- ],
- errorMessage: errors.originType
- })
- }}
+ {% include "model/answer/radio-button/radio-button.njk" %}
{% endblock %}
diff --git a/src/server/origin/origin-type/index.test.js b/src/server/origin/origin-type/index.test.js
index ef37dd9e..95c9ce12 100644
--- a/src/server/origin/origin-type/index.test.js
+++ b/src/server/origin/origin-type/index.test.js
@@ -2,8 +2,12 @@ import { originType, originTypePage, OriginTypePage } from './index.js'
import { OriginTypeAnswer } from '../../common/model/answer/origin-type/origin-type.js'
import { cphNumberPage } from '../cph-number/index.js'
import { exitPagePremisesType } from '../premises-type-exit-page/index.js'
+import { createServer } from '~/src/server/index.js'
+import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
+import { statusCodes } from '~/src/server/common/constants/status-codes.js'
+import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
-/** @import { PluginBase, PluginNameVersion } from '@hapi/hapi' */
+/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
const sectionKey = 'origin'
const question = 'What type of premises are the animals moving off?'
@@ -73,4 +77,34 @@ describe('OriginTypePage', () => {
expect(plugin.name).toBe(`${sectionKey}-${questionKey}`)
expect(plugin).toHaveProperty('register')
})
+
+ describe('OriginTypePage.content', () => {
+ /** @type {Server} */
+ let server
+
+ beforeAll(async () => {
+ server = await createServer()
+ await server.initialize()
+ })
+
+ afterAll(async () => {
+ await server.stop({ timeout: 0 })
+ })
+
+ it('should render expected response and content', async () => {
+ const { payload, statusCode } = await server.inject(
+ withCsrfProtection({
+ method: 'GET',
+ url: pageUrl
+ })
+ )
+
+ const document = parseDocument(payload)
+ expect(document.title).toBe(question)
+ expect(statusCode).toBe(statusCodes.ok)
+
+ const content = document.querySelector('#main-content')?.innerHTML
+ expect(content).toMatchSnapshot()
+ })
+ })
})
From a90817b98d123bbec21a8b6866dfd7fe952483f9 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Thu, 23 Jan 2025 17:00:15 +0000
Subject: [PATCH 08/12] Updates to user journey tests
---
.../page-objects/destination/destinationSelectionPage.js | 2 +-
user-journey-tests/page-objects/origin/originTypePage.js | 4 ++--
user-journey-tests/page-objects/origin/toFromFarmPage.js | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/user-journey-tests/page-objects/destination/destinationSelectionPage.js b/user-journey-tests/page-objects/destination/destinationSelectionPage.js
index 709eb13e..dbcced63 100644
--- a/user-journey-tests/page-objects/destination/destinationSelectionPage.js
+++ b/user-journey-tests/page-objects/destination/destinationSelectionPage.js
@@ -15,7 +15,7 @@ class DestinationSelectionPage extends Page {
}
get dedicatedSaleRadio() {
- return $('#dedicatedSale')
+ return $('#dedicated-sale')
}
get approvedFinishingRadio() {
diff --git a/user-journey-tests/page-objects/origin/originTypePage.js b/user-journey-tests/page-objects/origin/originTypePage.js
index b2380004..303cad33 100644
--- a/user-journey-tests/page-objects/origin/originTypePage.js
+++ b/user-journey-tests/page-objects/origin/originTypePage.js
@@ -15,11 +15,11 @@ class OriginTypePage extends Page {
}
get approvedFinishingUnitRadio() {
- return $('#afu-radio')
+ return $('#afu')
}
get anotherTypeOfPremisesRadio() {
- return $('#other-radio')
+ return $('#other')
}
get errorLink() {
diff --git a/user-journey-tests/page-objects/origin/toFromFarmPage.js b/user-journey-tests/page-objects/origin/toFromFarmPage.js
index 2d4784ea..7bb531da 100644
--- a/user-journey-tests/page-objects/origin/toFromFarmPage.js
+++ b/user-journey-tests/page-objects/origin/toFromFarmPage.js
@@ -16,7 +16,7 @@ class ToFromFarmPage extends Page {
}
get offThefarmRadio() {
- return $('#off-farm-radio')
+ return $('#off')
}
get onFarmSummaryErrorLink() {
From aa4e16af0ee4d6cf921841c7a139cceb84e8892c Mon Sep 17 00:00:00 2001
From: Hugh FD Jackson
Date: Thu, 23 Jan 2025 20:23:32 +0000
Subject: [PATCH 09/12] DSFAAP-639: scope snapshot helper within describe for
cleaner lifecylce management
---
src/server/common/model/page/page-model.js | 2 +-
.../common/test-helpers/snapshot-page.js | 45 +++++++++++++++++++
src/server/cookies-policy/index.test.js | 36 +++------------
.../destination-type/index.test.js | 39 +++-------------
.../destination/general-licence/index.test.js | 29 +++---------
.../licence/receiveMethod/index.test.js | 39 +++-------------
src/server/origin/origin-type/index.test.js | 41 +++--------------
7 files changed, 77 insertions(+), 154 deletions(-)
create mode 100644 src/server/common/test-helpers/snapshot-page.js
diff --git a/src/server/common/model/page/page-model.js b/src/server/common/model/page/page-model.js
index 5d18a1f0..eb3a2dfe 100644
--- a/src/server/common/model/page/page-model.js
+++ b/src/server/common/model/page/page-model.js
@@ -52,7 +52,7 @@ export class Page {
/**
* @param {import('@hapi/hapi').Request} _req
* @returns {Record}
- * */
+ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
viewProps(_req) {
return {}
diff --git a/src/server/common/test-helpers/snapshot-page.js b/src/server/common/test-helpers/snapshot-page.js
new file mode 100644
index 00000000..fe6aa064
--- /dev/null
+++ b/src/server/common/test-helpers/snapshot-page.js
@@ -0,0 +1,45 @@
+import { parseDocument } from '../../common/test-helpers/dom.js'
+import { createServer } from '~/src/server/index.js'
+import { withCsrfProtection } from './csrf.js'
+/** @import { Server } from '@hapi/hapi' */
+
+/* global expect, it, beforeAll, afterAll, describe */
+
+/**
+ * @param {string} describeMessage
+ * @param {string} shouldMessage
+ * @param {string} urlPath
+ */
+export const describePageSnapshot = (
+ describeMessage,
+ shouldMessage,
+ urlPath
+) => {
+ describe(describeMessage, () => {
+ /** @type {Server} */
+ let server
+
+ beforeAll(async () => {
+ server = await createServer()
+ await server.initialize()
+ })
+
+ afterAll(async () => {
+ await server.stop({ timeout: 0 })
+ })
+
+ it(shouldMessage, async () => {
+ const { payload } = await server.inject(
+ withCsrfProtection({
+ method: 'GET',
+ url: urlPath
+ })
+ )
+
+ const content =
+ parseDocument(payload).querySelector('#main-content')?.innerHTML
+
+ expect(content).toMatchSnapshot()
+ })
+ })
+}
diff --git a/src/server/cookies-policy/index.test.js b/src/server/cookies-policy/index.test.js
index 1bb84864..1a7d387e 100644
--- a/src/server/cookies-policy/index.test.js
+++ b/src/server/cookies-policy/index.test.js
@@ -1,34 +1,10 @@
-import { createServer } from '~/src/server/index.js'
-import { statusCodes } from '~/src/server/common/constants/status-codes.js'
-import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
+import { describePageSnapshot } from '../common/test-helpers/snapshot-page.js'
-describe('#destinationSummaryController', () => {
- /** @type {Server} */
- let server
-
- beforeAll(async () => {
- server = await createServer()
- await server.initialize()
- })
-
- afterAll(async () => {
- await server.stop({ timeout: 0 })
- })
-
- it('should render expected response and content', async () => {
- const { payload, statusCode } = await server.inject({
- method: 'GET',
- url: '/cookies'
- })
-
- const document = parseDocument(payload)
- expect(document.title).toBe('Cookies')
- expect(statusCode).toBe(statusCodes.ok)
-
- const content = document.querySelector('#main-content')?.innerHTML
- expect(content).toMatchSnapshot()
- })
-})
+describePageSnapshot(
+ '#destinationSummaryController',
+ 'should render expected response and content',
+ '/cookies'
+)
/**
* @import { Server } from '@hapi/hapi'
diff --git a/src/server/destination/destination-type/index.test.js b/src/server/destination/destination-type/index.test.js
index 624e55a7..2ebbcfd9 100644
--- a/src/server/destination/destination-type/index.test.js
+++ b/src/server/destination/destination-type/index.test.js
@@ -7,10 +7,7 @@ import { DestinationTypeAnswer } from '../../common/model/answer/destination-typ
import { destinationGeneralLicencePage } from '../general-licence/index.js'
import { destinationSummaryPage } from '../summary/index.js'
import { anotherDestinationPage } from '../another-destination/index.js'
-import { createServer } from '~/src/server/index.js'
-import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
-import { statusCodes } from '~/src/server/common/constants/status-codes.js'
-import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
+import { describePageSnapshot } from '../../common/test-helpers/snapshot-page.js'
const sectionKey = 'destination'
const question = 'Where are the animals going to?'
@@ -89,35 +86,11 @@ describe('DestinationTypePage', () => {
expect(plugin).toHaveProperty('register')
})
- describe('DestinationTypePage.content', () => {
- /** @type {Server} */
- let server
-
- beforeAll(async () => {
- server = await createServer()
- await server.initialize()
- })
-
- afterAll(async () => {
- await server.stop({ timeout: 0 })
- })
-
- it('should render expected response and content', async () => {
- const { payload, statusCode } = await server.inject(
- withCsrfProtection({
- method: 'GET',
- url: pageUrl
- })
- )
-
- const document = parseDocument(payload)
- expect(document.title).toBe(question)
- expect(statusCode).toBe(statusCodes.ok)
-
- const content = document.querySelector('#main-content')?.innerHTML
- expect(content).toMatchSnapshot()
- })
- })
+ describePageSnapshot(
+ 'DestinationTypePage.content',
+ 'should render expected response and content',
+ pageUrl
+ )
})
/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
diff --git a/src/server/destination/general-licence/index.test.js b/src/server/destination/general-licence/index.test.js
index d28a0417..02733b5b 100644
--- a/src/server/destination/general-licence/index.test.js
+++ b/src/server/destination/general-licence/index.test.js
@@ -1,7 +1,6 @@
-import { parseDocument } from '../../common/test-helpers/dom.js'
+import { describePageSnapshot } from '../../common/test-helpers/snapshot-page.js'
import { DestinationSummaryPage } from '../summary/index.js'
import { DestinationGeneralLicencePage } from './index.js'
-import { createServer } from '~/src/server/index.js'
/** @import { Server } from '@hapi/hapi' */
@@ -44,24 +43,8 @@ describe('DestinationGeneralLicencePage', () => {
})
})
-describe('DestinationGeneralLicenceController', () => {
- /** @type {Server} */
- let server
-
- beforeAll(async () => {
- server = await createServer()
- await server.initialize()
- })
-
- it('should render the expected content', async () => {
- const { payload } = await server.inject({
- method: 'GET',
- url: page.urlPath
- })
-
- const content =
- parseDocument(payload).querySelector('#main-content')?.innerHTML
-
- expect(content).toMatchSnapshot()
- })
-})
+describePageSnapshot(
+ 'DestinationGeneralLicenceController',
+ 'should render the expected content',
+ page.urlPath
+)
diff --git a/src/server/licence/receiveMethod/index.test.js b/src/server/licence/receiveMethod/index.test.js
index b843a076..b60e070c 100644
--- a/src/server/licence/receiveMethod/index.test.js
+++ b/src/server/licence/receiveMethod/index.test.js
@@ -2,10 +2,7 @@ import { receiveMethod, receiveMethodPage, ReceiveMethodPage } from './index.js'
import { ReceiveMethodAnswer } from '../../common/model/answer/receiveMethod/receiveMethod.js'
import { emailAddressPage } from '../email-address/index.js'
import { postExitPage } from '../postExitPage/index.js'
-import { createServer } from '~/src/server/index.js'
-import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
-import { statusCodes } from '~/src/server/common/constants/status-codes.js'
-import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
+import { describePageSnapshot } from '../../common/test-helpers/snapshot-page.js'
// TODO: import next page object
@@ -76,35 +73,11 @@ describe('ReceiveMethodPage', () => {
expect(plugin).toHaveProperty('register')
})
- describe('DestinationTypePage.content', () => {
- /** @type {Server} */
- let server
-
- beforeAll(async () => {
- server = await createServer()
- await server.initialize()
- })
-
- afterAll(async () => {
- await server.stop({ timeout: 0 })
- })
-
- it('should render expected response and content', async () => {
- const { payload, statusCode } = await server.inject(
- withCsrfProtection({
- method: 'GET',
- url: pageUrl
- })
- )
-
- const document = parseDocument(payload)
- expect(document.title).toBe(question)
- expect(statusCode).toBe(statusCodes.ok)
-
- const content = document.querySelector('#main-content')?.innerHTML
- expect(content).toMatchSnapshot()
- })
- })
+ describePageSnapshot(
+ 'DestinationTypePage.content',
+ 'should render expected response and content',
+ pageUrl
+ )
})
/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
diff --git a/src/server/origin/origin-type/index.test.js b/src/server/origin/origin-type/index.test.js
index 95c9ce12..1e4cfc42 100644
--- a/src/server/origin/origin-type/index.test.js
+++ b/src/server/origin/origin-type/index.test.js
@@ -2,12 +2,9 @@ import { originType, originTypePage, OriginTypePage } from './index.js'
import { OriginTypeAnswer } from '../../common/model/answer/origin-type/origin-type.js'
import { cphNumberPage } from '../cph-number/index.js'
import { exitPagePremisesType } from '../premises-type-exit-page/index.js'
-import { createServer } from '~/src/server/index.js'
-import { parseDocument } from '~/src/server/common/test-helpers/dom.js'
-import { statusCodes } from '~/src/server/common/constants/status-codes.js'
-import { withCsrfProtection } from '../../common/test-helpers/csrf.js'
+import { describePageSnapshot } from '../../common/test-helpers/snapshot-page.js'
-/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
+/** @import { PluginBase, PluginNameVersion } from '@hapi/hapi' */
const sectionKey = 'origin'
const question = 'What type of premises are the animals moving off?'
@@ -78,33 +75,9 @@ describe('OriginTypePage', () => {
expect(plugin).toHaveProperty('register')
})
- describe('OriginTypePage.content', () => {
- /** @type {Server} */
- let server
-
- beforeAll(async () => {
- server = await createServer()
- await server.initialize()
- })
-
- afterAll(async () => {
- await server.stop({ timeout: 0 })
- })
-
- it('should render expected response and content', async () => {
- const { payload, statusCode } = await server.inject(
- withCsrfProtection({
- method: 'GET',
- url: pageUrl
- })
- )
-
- const document = parseDocument(payload)
- expect(document.title).toBe(question)
- expect(statusCode).toBe(statusCodes.ok)
-
- const content = document.querySelector('#main-content')?.innerHTML
- expect(content).toMatchSnapshot()
- })
- })
+ describePageSnapshot(
+ 'OriginTypePage.content',
+ 'should render expected response and content',
+ pageUrl
+ )
})
From 7e3abff86feaabd5e6621981f46275d0b88575c2 Mon Sep 17 00:00:00 2001
From: Hugh FD Jackson
Date: Thu, 23 Jan 2025 20:45:52 +0000
Subject: [PATCH 10/12] DSFAAP-639: use more generic viewModel
---
.../model/answer/radio-button/radio-button.js | 32 ++++++++-----
.../answer/radio-button/radio-button.njk | 11 +----
.../answer/radio-button/radio-button.test.js | 45 ++++++++++---------
3 files changed, 48 insertions(+), 40 deletions(-)
diff --git a/src/server/common/model/answer/radio-button/radio-button.js b/src/server/common/model/answer/radio-button/radio-button.js
index c074af25..645145aa 100644
--- a/src/server/common/model/answer/radio-button/radio-button.js
+++ b/src/server/common/model/answer/radio-button/radio-button.js
@@ -91,16 +91,28 @@ export class RadioButtonAnswer extends AnswerModel {
})
}
+ get viewModel() {
+ return {
+ name: this.config.payloadKey,
+ id: this.config.payloadKey,
+ fieldset: {},
+ value: this.value,
+ items: this.viewModelItems
+ }
+ }
+
get viewModelItems() {
- const result = Object.entries(this.config.options).map(([key, value]) => ({
- id: key,
- value: key,
- text: value.label,
- hint: {
- text: value.hint
- }
- }))
- result[0].id = this.config.payloadKey
- return result
+ const viewModelItems = Object.entries(this.config.options).map(
+ ([key, value]) => ({
+ id: key,
+ value: key,
+ text: value.label,
+ hint: {
+ text: value.hint
+ }
+ })
+ )
+ viewModelItems[0].id = this.config.payloadKey
+ return viewModelItems
}
}
diff --git a/src/server/common/model/answer/radio-button/radio-button.njk b/src/server/common/model/answer/radio-button/radio-button.njk
index 6cc17f3b..51289af0 100644
--- a/src/server/common/model/answer/radio-button/radio-button.njk
+++ b/src/server/common/model/answer/radio-button/radio-button.njk
@@ -1,10 +1 @@
-{{
- govukRadios({
- name: answer.config.payloadKey,
- id: answer.config.payloadKey,
- fieldset:{},
- value: value,
- items: answer.viewModelItems,
- errorMessage: errors[answer.config.payloadKey]
- })
-}}
+{{ govukRadios(assign({}, answer.viewModel, { errorMessage: errors[answer.config.payloadKey]})) }}
diff --git a/src/server/common/model/answer/radio-button/radio-button.test.js b/src/server/common/model/answer/radio-button/radio-button.test.js
index 31361124..72717224 100644
--- a/src/server/common/model/answer/radio-button/radio-button.test.js
+++ b/src/server/common/model/answer/radio-button/radio-button.test.js
@@ -141,27 +141,32 @@ describe('RadioButton', () => {
})
describe('#RadioButton.viewModelItems', () => {
- it('should return the list of items from the config options and first item with the payloadKey', () => {
- const viewModelItems = new RadioButtonTest().viewModelItems
-
- expect(viewModelItems).toEqual([
- {
- id: 'test_radio',
- value: 'value_1',
- text: 'test_label_1',
- hint: {
- text: undefined
+ it('should return everything (except errors) to render in the template', () => {
+ const answer = new RadioButtonTest({ test_radio: 'value_1' })
+ expect(answer.viewModel).toEqual({
+ name: 'test_radio',
+ id: 'test_radio',
+ fieldset: {},
+ value: answer.value,
+ items: [
+ {
+ id: 'test_radio',
+ value: 'value_1',
+ text: 'test_label_1',
+ hint: {
+ text: undefined
+ }
+ },
+ {
+ id: 'value_2',
+ value: 'value_2',
+ text: 'test_label_2',
+ hint: {
+ text: 'test_hint_2'
+ }
}
- },
- {
- id: 'value_2',
- value: 'value_2',
- text: 'test_label_2',
- hint: {
- text: 'test_hint_2'
- }
- }
- ])
+ ]
+ })
})
})
})
From 979217e60b4993ca8272ac8a8ba853766171a8ab Mon Sep 17 00:00:00 2001
From: Hugh FD Jackson
Date: Thu, 23 Jan 2025 22:18:31 +0000
Subject: [PATCH 11/12] DSFAAP-639: inline viewModel items
---
.../model/answer/radio-button/radio-button.js | 26 +++++++------------
.../answer/radio-button/radio-button.test.js | 2 +-
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/server/common/model/answer/radio-button/radio-button.js b/src/server/common/model/answer/radio-button/radio-button.js
index 645145aa..2ee4f09a 100644
--- a/src/server/common/model/answer/radio-button/radio-button.js
+++ b/src/server/common/model/answer/radio-button/radio-button.js
@@ -92,27 +92,21 @@ export class RadioButtonAnswer extends AnswerModel {
}
get viewModel() {
+ const items = Object.entries(this.config.options).map(([key, value]) => ({
+ id: key,
+ value: key,
+ text: value.label,
+ hint: {
+ text: value.hint
+ }
+ }))
+ items[0].id = this.config.payloadKey
return {
name: this.config.payloadKey,
id: this.config.payloadKey,
fieldset: {},
value: this.value,
- items: this.viewModelItems
+ items
}
}
-
- get viewModelItems() {
- const viewModelItems = Object.entries(this.config.options).map(
- ([key, value]) => ({
- id: key,
- value: key,
- text: value.label,
- hint: {
- text: value.hint
- }
- })
- )
- viewModelItems[0].id = this.config.payloadKey
- return viewModelItems
- }
}
diff --git a/src/server/common/model/answer/radio-button/radio-button.test.js b/src/server/common/model/answer/radio-button/radio-button.test.js
index 72717224..8c29df80 100644
--- a/src/server/common/model/answer/radio-button/radio-button.test.js
+++ b/src/server/common/model/answer/radio-button/radio-button.test.js
@@ -140,7 +140,7 @@ describe('RadioButton', () => {
})
})
- describe('#RadioButton.viewModelItems', () => {
+ describe('#RadioButton.viewModel', () => {
it('should return everything (except errors) to render in the template', () => {
const answer = new RadioButtonTest({ test_radio: 'value_1' })
expect(answer.viewModel).toEqual({
From ab42e317eca4276a73f679325f1ebb0f250418b3 Mon Sep 17 00:00:00 2001
From: Jose Luis Garcia Ramos <11478086+joseluisgraa@users.noreply.github.com>
Date: Fri, 24 Jan 2025 10:30:30 +0000
Subject: [PATCH 12/12] Removed import govukradios where not needed
---
src/server/common/model/answer/radio-button/radio-button.njk | 1 +
src/server/destination/another-destination/index.njk | 1 -
src/server/destination/destination-type/index.njk | 1 -
src/server/destination/general-licence/index.njk | 1 -
src/server/licence/receiveMethod/index.njk | 2 --
src/server/origin/on-off-farm/index.njk | 1 -
src/server/origin/origin-type/index.njk | 1 -
src/server/origin/premises-type-exit-page/index.njk | 1 -
8 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/src/server/common/model/answer/radio-button/radio-button.njk b/src/server/common/model/answer/radio-button/radio-button.njk
index 51289af0..2a3560b6 100644
--- a/src/server/common/model/answer/radio-button/radio-button.njk
+++ b/src/server/common/model/answer/radio-button/radio-button.njk
@@ -1 +1,2 @@
+{% from "govuk/components/radios/macro.njk" import govukRadios %}
{{ govukRadios(assign({}, answer.viewModel, { errorMessage: errors[answer.config.payloadKey]})) }}
diff --git a/src/server/destination/another-destination/index.njk b/src/server/destination/another-destination/index.njk
index 0a0fc6e6..2e86b59a 100644
--- a/src/server/destination/another-destination/index.njk
+++ b/src/server/destination/another-destination/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'layouts/page.njk' %}
{% block content %}
diff --git a/src/server/destination/destination-type/index.njk b/src/server/destination/destination-type/index.njk
index 665d1ba8..b673b847 100644
--- a/src/server/destination/destination-type/index.njk
+++ b/src/server/destination/destination-type/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'layouts/questions.njk' %}
{% block questions %}
diff --git a/src/server/destination/general-licence/index.njk b/src/server/destination/general-licence/index.njk
index 2690910e..238a2869 100644
--- a/src/server/destination/general-licence/index.njk
+++ b/src/server/destination/general-licence/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'layouts/page.njk' %}
{% block content %}
diff --git a/src/server/licence/receiveMethod/index.njk b/src/server/licence/receiveMethod/index.njk
index a1a10ffa..8fad9b28 100644
--- a/src/server/licence/receiveMethod/index.njk
+++ b/src/server/licence/receiveMethod/index.njk
@@ -1,5 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
-{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}
{% extends 'layouts/questions.njk' %}
{% block questions %}
{% include "model/answer/radio-button/radio-button.njk" %}
diff --git a/src/server/origin/on-off-farm/index.njk b/src/server/origin/on-off-farm/index.njk
index 5295d068..08e8753b 100644
--- a/src/server/origin/on-off-farm/index.njk
+++ b/src/server/origin/on-off-farm/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'templates/layouts/questions.njk' %}
{% block questions %}
diff --git a/src/server/origin/origin-type/index.njk b/src/server/origin/origin-type/index.njk
index 665d1ba8..b673b847 100644
--- a/src/server/origin/origin-type/index.njk
+++ b/src/server/origin/origin-type/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'layouts/questions.njk' %}
{% block questions %}
diff --git a/src/server/origin/premises-type-exit-page/index.njk b/src/server/origin/premises-type-exit-page/index.njk
index 3194137a..088aec89 100644
--- a/src/server/origin/premises-type-exit-page/index.njk
+++ b/src/server/origin/premises-type-exit-page/index.njk
@@ -1,4 +1,3 @@
-{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% extends 'layouts/page.njk' %}
{% block content %}