Skip to content

Commit

Permalink
Merge pull request #69 from DEFRA/DSFAAP-580_refactor-templates
Browse files Browse the repository at this point in the history
Simplify templates
  • Loading branch information
hughfdjackson authored Dec 13, 2024
2 parents 71d9c57 + b449f70 commit ca31c9d
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 104 deletions.
2 changes: 2 additions & 0 deletions src/server/check-answers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export const checkAnswersPostController = {
const confirmation = new Confirmation(payload)

const { isValid, errors } = confirmation.validate()

if (!isValid) {
return res.view('check-answers/index', {
pageTitle: `Error: ${pageTitle}`,
heading,
confirmation,
errorMessages: Confirmation.errorMessages(errors),
errorMessage: errors.confirmation,
...tasks
})
Expand Down
16 changes: 0 additions & 16 deletions src/server/check-answers/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@
<div class="govuk-grid-column-two-thirds">
<div class="govuk-body" data-testid="app-page-body">
<div class="govuk-!-margin-top-0 govuk-!-margin-bottom-8">

{% if (errorMessage) %}
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: [
{
text: errorMessage.text,
href: "#confirmation"
}
]
}) }}
{% endif %}
<h1 class="govuk-heading-l">
{{ heading }}
</h1>

<h2 class="govuk-heading-m">Movement origin</h2>
{{ section([{
key: "Are you moving the cattle on or off your farm or premises?",
Expand Down
10 changes: 0 additions & 10 deletions src/server/common/model/answer/on-off-farm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ export class OnOffFarm extends AnswerModel {
}
}

/** @param {AnswerErrors} errors */
static errorMessages(errors) {
return [
{
href: '#on-farm-radio',
text: errors.onOffFarm?.text
}
]
}

/**
* @param {OnOffFarmData | undefined} state
* @returns {OnOffFarm}
Expand Down
11 changes: 0 additions & 11 deletions src/server/common/model/answer/on-off-farm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ describe('OnOffFarm.fromState', () => {
})
})

describe('OnOffFarm.errorMessages', () => {
it('should calculate the href to the first radio button', () => {
expect(OnOffFarm.errorMessages({ onOffFarm: { text: 'error' } })).toEqual([
{
href: '#on-farm-radio',
text: 'error'
}
])
})
})

describe('#OnOffFarm.value', () => {
it('should return a value-wrapped object to rendering in the template', () => {
expect(new OnOffFarm({ onOffFarm: 'on' }).value).toBe('on')
Expand Down
24 changes: 24 additions & 0 deletions src/server/common/templates/layouts/questions.njk
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}
{% from "govuk/components/button/macro.njk" import govukButton %}

{% extends 'layouts/page.njk' %}

{% block content %}

{% if (errorMessages) %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: errorMessages
})
}}
</div>
</div>
{% endif %}

{% if (heading) %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
{{ heading }}
</h1>
</div>
</div>
{% endif %}

{% block beforequestion %}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion src/server/licence/check-answers/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{% extends 'layouts/questions.njk' %}

{% block questions %}
<h1 class="govuk-heading-l">{{pageTitle}}</h1>

{{ govukSummaryList({
classes: "govuk-!-margin-bottom-9",
Expand All @@ -31,4 +30,5 @@
}
]
}) }}

{% endblock %}
16 changes: 1 addition & 15 deletions src/server/licence/email-address/index.njk
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}

{% extends 'layouts/questions.njk' %}

{% block questions %}
{% if (errorMessages) %}
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: errorMessages
}) }}
{% endif %}

{% call govukFieldset({
legend: {
text: heading,
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
}) %}
{% call govukFieldset() %}

{{ govukInput({
id: "emailAddress",
Expand Down
15 changes: 1 addition & 14 deletions src/server/origin/address/index.njk
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}
{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}

{% extends 'layouts/questions.njk' %}

{% block questions %}
{% if (errorMessages.length) %}
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: errorMessages
}) }}
{% endif %}

{% call govukFieldset({
legend: {
text: heading,
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
}) %}
{% call govukFieldset() %}

{{ govukInput({
label: {
Expand Down
18 changes: 2 additions & 16 deletions src/server/origin/cph-number/index.njk
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% from "govuk/components/input/macro.njk" import govukInput %}
{% from "govuk/components/fieldset/macro.njk" import govukFieldset %}

{% extends 'layouts/questions.njk' %}

{% block questions %}
{% if (errorMessages) %}
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: errorMessages
}) }}
{% endif %}

{% call govukFieldset({
legend: {
text: heading,
classes: "govuk-fieldset__legend--l",
isPageHeading: true
}
}) %}

{% call govukFieldset() %}
{{ govukInput({
id: "cphNumber",
name: "cphNumber",
Expand All @@ -34,4 +19,5 @@
}) }}

{% endcall %}

{% endblock %}
19 changes: 3 additions & 16 deletions src/server/origin/on-off-farm/index.njk
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% extends 'layouts/questions.njk' %}

{% block questions %}
{% if (errorMessages) %}
{{ govukErrorSummary({
titleText: "There is a problem",
errorList: errorMessages
}) }}
{% endif %}

{{ govukRadios({
name: "onOffFarm",
id: "onOffFarm",
fieldset: {
legend: {
text: "Are you moving the cattle on or off your farm or premises?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
id: "on-off-farm",
fieldset:{},
value: value,
items: [
{
id: "on-farm-radio",
id: "onOffFarm",
value: "on",
text: "On to the farm or premises"
},
Expand Down
5 changes: 2 additions & 3 deletions src/server/origin/summary/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
})) %}
{% endfor %}



{{ govukSummaryList({
classes: "govuk-!-margin-bottom-9",
rows: summaryRows
}) }}

{% endmacro %}

{% block questions %}
<h1 class="govuk-heading-l">{{pageTitle}}</h1>

{{ createSummary(originSummary) }}

{% endblock %}
4 changes: 2 additions & 2 deletions user-journey-tests/page-objects/origin/toFromFarmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class ToFromFarmPage extends Page {
}

get onThefarmRadio() {
return $('#on-farm-radio')
return $('#onOffFarm')
}

get offThefarmRadio() {
return $('#off-farm-radio')
}

get onFarmSummaryErrorLink() {
return $('[href="#on-farm-radio"]')
return $('[href="#onOffFarm"]')
}

get pageError() {
Expand Down

0 comments on commit ca31c9d

Please sign in to comment.