diff --git a/app/models/form/page.rb b/app/models/form/page.rb index 2cdebff39..12b1065d6 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -1,6 +1,6 @@ class Form::Page attr_accessor :id, :header, :description, :questions, :soft_validations, - :depends_on, :subsection + :depends_on, :subsection, :hide_subsection_label def initialize(id, hsh, subsection) @id = id @@ -8,6 +8,7 @@ class Form::Page @description = hsh["description"] @questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) } @depends_on = hsh["depends_on"] + @hide_subsection_label = hsh["hide_subsection_label"] @soft_validations = hsh["soft_validations"]&.map { |sv_id, s| Form::Question.new(sv_id, s, self) } @subsection = subsection end diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb index 8385eaac7..360d56520 100644 --- a/app/views/form/page.html.erb +++ b/app/views/form/page.html.erb @@ -16,11 +16,17 @@
<% if @page.header.present? %>

- <%= @subsection.label %> + <% if !@page.hide_subsection_label %> + <%= @subsection.label %> + <% end %> <%= @page.header %>

<% end %> + <% if @page.description.present? %> +

<%= @page.description.html_safe %>

+ <% end %> + <%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post" do |f| %> <%= f.govuk_error_summary %> <% @page.questions.map do |question| %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index da5a0bb0e..f50480d15 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -26,9 +26,10 @@ } }, "gdpr_declined": { + "hide_subsection_label": true, "header": "You cannot use this service", "hint_text": "", - "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.", + "description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.

Go to your logs", "questions": {}, "depends_on": { "gdpr_acceptance": "No" } }, diff --git a/spec/views/form/page_view_spec.rb b/spec/views/form/page_view_spec.rb index ac7c8c9b6..bcf23c28b 100644 --- a/spec/views/form/page_view_spec.rb +++ b/spec/views/form/page_view_spec.rb @@ -11,7 +11,10 @@ RSpec.describe "form/page" do let(:subsection) { form.get_subsection("income_and_benefits") } let(:page) { form.get_page("net_income") } let(:question) { page.questions.find { |q| q.id == "earnings" } } - let(:initial_attribs) { { type: "numeric", answer_options: nil, prefix: nil, suffix: nil } } + let(:initial_page_attributes) { { description: nil, hide_subsection_label: nil } } + let(:initial_question_attributes) { { type: "numeric", answer_options: nil, prefix: nil, suffix: nil } } + let(:page_attributes) { {} } + let(:question_attributes) { {} } def assign_attributes(object, attrs) attrs.each_pair do |attr, value| @@ -23,18 +26,46 @@ RSpec.describe "form/page" do assign(:case_log, case_log) assign(:page, page) assign(:subsection, subsection) - assign_attributes(question, attribs) + assign_attributes(page, page_attributes) + assign_attributes(question, question_attributes) render end after do # Revert any changes we've made to avoid affecting other specs as the form, # subsection, page, question objects being acted on are in memory - assign_attributes(question, initial_attribs) + assign_attributes(page, initial_page_attributes) + assign_attributes(question, initial_question_attributes) + end + + context "given a page with a description" do + let(:description) { "Test description with link." } + let(:page_attributes) { { description: description } } + let(:expected_html) { '

Test description with link.

' } + + it "renders the description" do + expect(rendered).to match(expected_html) + end + end + + context "given a page with a header" do + it "renders the header and the subsection label" do + expect(rendered).to match(page.header) + expect(rendered).to match(subsection.label) + end + end + + context "given a page with a header and hide_subsection_label true" do + let(:page_attributes) { { hide_subsection_label: true } } + + it "renders the header but not the subsection label" do + expect(rendered).to match(page.header) + expect(rendered).not_to match(subsection.label) + end end context "given a numeric question with prefix and suffix" do - let(:attribs) { { type: "numeric", prefix: "£", suffix: "every week" } } + let(:question_attributes) { { type: "numeric", prefix: "£", suffix: "every week" } } it "renders prefix and suffix text" do expect(rendered).to match(/govuk-input__prefix/) @@ -48,42 +79,42 @@ RSpec.describe "form/page" do let(:expected_guidance) { /What counts as income?/ } context "with radio type" do - let(:attribs) { { type: "radio", answer_options: { "1": "A", "2": "B" } } } + let(:question_attributes) { { type: "radio", answer_options: { "1": "A", "2": "B" } } } it "renders the guidance partial for radio questions" do expect(rendered).to match(expected_guidance) end end context "with text type" do - let(:attribs) { { type: "text", answer_options: nil } } + let(:question_attributes) { { type: "text", answer_options: nil } } it "renders the guidance partial for text questions" do expect(rendered).to match(expected_guidance) end end context "with numeric type" do - let(:attribs) { { type: "numeric", answer_options: nil } } + let(:question_attributes) { { type: "numeric", answer_options: nil } } it "renders the guidance partial for numeric questions" do expect(rendered).to match(expected_guidance) end end context "with select type" do - let(:attribs) { { type: "select", answer_options: { "1": "A", "2": "B" } } } + let(:question_attributes) { { type: "select", answer_options: { "1": "A", "2": "B" } } } it "renders the guidance partial for select questions" do expect(rendered).to match(expected_guidance) end end context "with checkbox type" do - let(:attribs) { { type: "checkbox", answer_options: { "1": "A", "2": "B" } } } + let(:question_attributes) { { type: "checkbox", answer_options: { "1": "A", "2": "B" } } } it "renders the guidance partial for checkbox questions" do expect(rendered).to match(expected_guidance) end end context "with date type" do - let(:attribs) { { type: "date", answer_options: nil } } + let(:question_attributes) { { type: "date", answer_options: nil } } it "renders the guidance partial for date questions" do expect(rendered).to match(expected_guidance) end