Browse Source

Update interruption screen page

pull/1584/head
Kat 3 years ago
parent
commit
c1f8a7c135
  1. 4
      app/helpers/interruption_screen_helper.rb
  2. 8
      app/models/form/question.rb
  3. 56
      app/views/form/_interruption_screen_question.html.erb
  4. 2
      app/views/form/page.html.erb
  5. 21
      spec/features/form/validations_spec.rb
  6. 3
      spec/fixtures/forms/2021_2022.json

4
app/helpers/interruption_screen_helper.rb

@ -29,6 +29,10 @@ module InterruptionScreenHelper
I18n.t(title_text["translation"], **translation_params).to_s I18n.t(title_text["translation"], **translation_params).to_s
end end
def soft_validation_affected_questions(question, log)
question.affected_question_ids.map { |question_id| log.form.get_question(question_id, log) }
end
private private
def get_value_from_argument(log, argument) def get_value_from_argument(log, argument)

8
app/models/form/question.rb

@ -4,7 +4,8 @@ class Form::Question
:conditional_for, :readonly, :answer_options, :page, :check_answer_label, :conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
:guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived,
:check_answers_card_number, :unresolved_hint_text, :question_number, :plain_label :check_answers_card_number, :unresolved_hint_text, :question_number, :plain_label,
:affected_question_ids
module GuidancePosition module GuidancePosition
TOP = 1 TOP = 1
@ -43,6 +44,7 @@ class Form::Question
@question_number = hsh["question_number"] @question_number = hsh["question_number"]
@plain_label = hsh["plain_label"] @plain_label = hsh["plain_label"]
@disable_clearing_if_not_routed_or_dynamic_answer_options = hsh["disable_clearing_if_not_routed_or_dynamic_answer_options"] @disable_clearing_if_not_routed_or_dynamic_answer_options = hsh["disable_clearing_if_not_routed_or_dynamic_answer_options"]
@affected_question_ids = hsh["affected_question_ids"] || []
end end
end end
@ -124,6 +126,10 @@ class Form::Question
"/#{log.model_name.param_key.dasherize}s/#{log.id}/#{page_id.to_s.dasherize}?referrer=check_answers" "/#{log.model_name.param_key.dasherize}s/#{log.id}/#{page_id.to_s.dasherize}?referrer=check_answers"
end end
def interruption_action_href(log, page_id)
"/#{log.model_name.param_key.dasherize}s/#{log.id}/#{page_id.to_s.dasherize}"
end
def unanswered?(log) def unanswered?(log)
return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox" return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox"

56
app/views/form/_interruption_screen_question.html.erb

@ -1,22 +1,48 @@
<%= govuk_panel( <%= govuk_panel(
title_text: display_title_text(title_text, lettings_log),
classes: "app-panel--interruption", classes: "app-panel--interruption",
) do %> ) do %>
<p class="govuk-panel__body"><%= display_informative_text(informative_text, lettings_log) %></p> <p class="govuk-heading-l"><%= display_title_text(title_text, lettings_log) %></p>
<%= f.govuk_radio_buttons_fieldset question.id.to_sym, <p class="govuk-body-l"><%= display_informative_text(informative_text, lettings_log) %></p>
legend: { text: question.header }, <p class="govuk-body-l"><%= question.header %></p>
hint: { text: question.hint_text&.html_safe } do %> <p class="govuk-body-l"><%= question.hint_text&.html_safe %></p>
<% question.answer_options.map do |key, options| %>
<% if key.starts_with?("divider") %> <% end %>
<%= f.govuk_radio_divider %>
<% else %> <h1 class="govuk-heading-l">
<%= f.govuk_radio_button question.id, Make sure these answers are all correct
key, </h1>
label: { text: options["value"] }, <%= govuk_summary_list do |summary_list| %>
hint: { text: options["hint"] }, <% soft_validation_affected_questions(question, @log).each do |affected_question| %>
**stimulus_html_attributes(question) %> <% summary_list.row do |row| %>
<% row.key { get_question_label(affected_question) } %>
<% row.value do %>
<%= simple_format(
get_answer_label(affected_question, @log),
wrapper_tag: "span",
class: "govuk-!-margin-right-4",
) %>
<% extra_value = affected_question.get_extra_check_answer_value(@log) %>
<% if extra_value && affected_question.answer_label(@log, current_user).present? %>
<%= simple_format(
extra_value,
wrapper_tag: "span",
class: "govuk-!-font-weight-regular app-!-colour-muted",
) %>
<% end %>
<% affected_question.get_inferred_answers(@log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% if @log.collection_period_open? %>
<% row.action(
text: affected_question.action_text(@log),
href: affected_question.interruption_action_href(@log, affected_question.page.id),
visually_hidden_text: affected_question.check_answer_label.to_s.downcase,
) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<%= f.govuk_submit "Save and continue", accesskey: "s", class: "app-button--inverse govuk-!-margin-bottom-0" %>
<% end %> <% end %>
<%= f.hidden_field question.id, value: "0" %>
<%= f.govuk_submit "Save and continue" %>

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

@ -7,7 +7,7 @@
<div data-controller="govukfrontend"></div> <div data-controller="govukfrontend"></div>
<%= form_with model: @log, url: request.original_url, method: "post", local: true do |f| %> <%= form_with model: @log, url: request.original_url, method: "post", local: true do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-<%= @page.questions[0].type == "interruption_screen" ? "full-from-desktop" : "two-thirds-from-desktop" %>"> <div class="govuk-grid-column-two-thirds-from-desktop" %>
<% remove_other_page_errors(@log, @page) %> <% remove_other_page_errors(@log, @page) %>
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>

21
spec/features/form/validations_spec.rb

@ -138,28 +138,33 @@ RSpec.describe "validations" do
let(:income_over_soft_limit) { 750 } let(:income_over_soft_limit) { 750 }
let(:income_under_soft_limit) { 700 } let(:income_under_soft_limit) { 700 }
it "prompts the user to confirm the value is correct with an interruption screen" do before do
visit("/lettings-logs/#{lettings_log.id}/net-income") visit("/lettings-logs/#{lettings_log.id}/net-income")
fill_in("lettings-log-earnings-field", with: income_over_soft_limit) fill_in("lettings-log-earnings-field", with: income_over_soft_limit)
choose("lettings-log-incfreq-1-field", allow_label_click: true) choose("lettings-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
end
it "prompts the user to confirm the value is correct with an interruption screen" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check")
expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation")
expect(page).to have_content("You told us the lead tenant’s working situation is: full-time – 30 hours or more") expect(page).to have_content("You told us the lead tenant’s working situation is: full-time – 30 hours or more")
expect(page).to have_content("The household income you have entered is £750.00 every week") expect(page).to have_content("The household income you have entered is £750.00 every week")
choose("lettings-log-net-income-value-check-0-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-uc-proportion") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-uc-proportion")
end end
it "returns the user to the previous question if they do not confirm the value as correct on the interruption screen" do it "allows to fix the questions that trigger the soft validation" do
visit("/lettings-logs/#{lettings_log.id}/net-income") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check")
fill_in("lettings-log-earnings-field", with: income_over_soft_limit) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/net-income").twice
expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/person-1-working-situation")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-value-check")
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/net-income", match: :first)
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income")
fill_in("lettings-log-earnings-field", with: income_under_soft_limit)
choose("lettings-log-incfreq-1-field", allow_label_click: true) choose("lettings-log-incfreq-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
choose("lettings-log-net-income-value-check-1-field", allow_label_click: true) expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income-uc-proportion") # will need change to the interruption screen
click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/net-income")
end end
end end
end end

3
spec/fixtures/forms/2021_2022.json vendored

@ -770,7 +770,8 @@
"1": { "1": {
"value": "No" "value": "No"
} }
} },
"affected_question_ids": ["ecstat1", "incfreq", "earnings"]
} }
} }
}, },

Loading…
Cancel
Save