Browse Source

CLDC-822: GDPR declined page content (#201)

* GDPR declined page content

* Add more tests

* Use real words
pull/202/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
3134ed1d10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/form/page.rb
  2. 8
      app/views/form/page.html.erb
  3. 3
      config/forms/2021_2022.json
  4. 51
      spec/views/form/page_view_spec.rb

3
app/models/form/page.rb

@ -1,6 +1,6 @@
class Form::Page class Form::Page
attr_accessor :id, :header, :description, :questions, :soft_validations, attr_accessor :id, :header, :description, :questions, :soft_validations,
:depends_on, :subsection :depends_on, :subsection, :hide_subsection_label
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
@id = id @id = id
@ -8,6 +8,7 @@ class Form::Page
@description = hsh["description"] @description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) } @questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) }
@depends_on = hsh["depends_on"] @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) } @soft_validations = hsh["soft_validations"]&.map { |sv_id, s| Form::Question.new(sv_id, s, self) }
@subsection = subsection @subsection = subsection
end end

8
app/views/form/page.html.erb

@ -16,11 +16,17 @@
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<% if @page.header.present? %> <% if @page.header.present? %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @subsection.label %></span> <% if !@page.hide_subsection_label %>
<span class="govuk-caption-l"><%= @subsection.label %></span>
<% end %>
<%= @page.header %> <%= @page.header %>
</h1> </h1>
<% end %> <% end %>
<% if @page.description.present? %>
<p class="govuk-body govuk-body-m"><%= @page.description.html_safe %></p>
<% end %>
<%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post" do |f| %> <%= form_with model: @case_log, url: form_case_log_path(@case_log), method: "post" do |f| %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<% @page.questions.map do |question| %> <% @page.questions.map do |question| %>

3
config/forms/2021_2022.json

@ -26,9 +26,10 @@
} }
}, },
"gdpr_declined": { "gdpr_declined": {
"hide_subsection_label": true,
"header": "You cannot use this service", "header": "You cannot use this service",
"hint_text": "", "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 <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">DLUHC privacy notice</a>.<br /><br /><a class=\"govuk-link\" href=\"/logs\">Go to your logs</a>",
"questions": {}, "questions": {},
"depends_on": { "gdpr_acceptance": "No" } "depends_on": { "gdpr_acceptance": "No" }
}, },

51
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(:subsection) { form.get_subsection("income_and_benefits") }
let(:page) { form.get_page("net_income") } let(:page) { form.get_page("net_income") }
let(:question) { page.questions.find { |q| q.id == "earnings" } } 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) def assign_attributes(object, attrs)
attrs.each_pair do |attr, value| attrs.each_pair do |attr, value|
@ -23,18 +26,46 @@ RSpec.describe "form/page" do
assign(:case_log, case_log) assign(:case_log, case_log)
assign(:page, page) assign(:page, page)
assign(:subsection, subsection) assign(:subsection, subsection)
assign_attributes(question, attribs) assign_attributes(page, page_attributes)
assign_attributes(question, question_attributes)
render render
end end
after do after do
# Revert any changes we've made to avoid affecting other specs as the form, # Revert any changes we've made to avoid affecting other specs as the form,
# subsection, page, question objects being acted on are in memory # 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 <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">with link</a>." }
let(:page_attributes) { { description: description } }
let(:expected_html) { '<p class="govuk-body govuk-body-m">Test description <a class="govuk-link" href="/files/privacy-notice.pdf">with link</a>.</p>' }
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 end
context "given a numeric question with prefix and suffix" do 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 it "renders prefix and suffix text" do
expect(rendered).to match(/govuk-input__prefix/) expect(rendered).to match(/govuk-input__prefix/)
@ -48,42 +79,42 @@ RSpec.describe "form/page" do
let(:expected_guidance) { /What counts as income?/ } let(:expected_guidance) { /What counts as income?/ }
context "with radio type" do 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 it "renders the guidance partial for radio questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end
end end
context "with text type" do 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 it "renders the guidance partial for text questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end
end end
context "with numeric type" do 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 it "renders the guidance partial for numeric questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end
end end
context "with select type" do 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 it "renders the guidance partial for select questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end
end end
context "with checkbox type" do 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 it "renders the guidance partial for checkbox questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end
end end
context "with date type" do 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 it "renders the guidance partial for date questions" do
expect(rendered).to match(expected_guidance) expect(rendered).to match(expected_guidance)
end end

Loading…
Cancel
Save