Browse Source

Fix interruption screen success banner (#1740)

* Filter out empty values and do not downcase nils

* Update tests

* refactor
pull/1742/head v0.3.34
kosiakkatrina 2 years ago committed by GitHub
parent
commit
f7c1b05afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/form_controller.rb
  2. 6
      spec/features/form/check_answers_page_lettings_logs_spec.rb
  3. 1
      spec/fixtures/forms/2021_2022.json
  4. 25
      spec/requests/form_controller_spec.rb

2
app/controllers/form_controller.rb

@ -11,7 +11,7 @@ class FormController < ApplicationController
mandatory_questions_with_no_response = mandatory_questions_with_no_response(responses_for_page) mandatory_questions_with_no_response = mandatory_questions_with_no_response(responses_for_page)
if mandatory_questions_with_no_response.empty? && @log.update(responses_for_page.merge(updated_by: current_user)) if mandatory_questions_with_no_response.empty? && @log.update(responses_for_page.merge(updated_by: current_user))
flash[:notice] = "You have successfully updated #{@page.questions.map(&:check_answer_label).first.downcase}" if previous_interruption_screen_page_id.present? flash[:notice] = "You have successfully updated #{@page.questions.map(&:check_answer_label).reject { |label| label.to_s.empty? }.first&.downcase}" if previous_interruption_screen_page_id.present?
redirect_to(successful_redirect_path) redirect_to(successful_redirect_path)
else else
mandatory_questions_with_no_response.map do |question| mandatory_questions_with_no_response.map do |question|

6
spec/features/form/check_answers_page_lettings_logs_spec.rb

@ -72,7 +72,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
it "has question headings based on the subsection" do it "has question headings based on the subsection" do
visit("/lettings-logs/#{id}/#{subsection}/check-answers") visit("/lettings-logs/#{id}/#{subsection}/check-answers")
question_labels = ["Tenant code", "Lead tenant’s age", "Lead tenant’s gender identity", "Number of Household Members"] question_labels = ["Tenant code", "Lead tenant’s age", "Number of Household Members"]
question_labels.each do |label| question_labels.each do |label|
expect(page).to have_content(label) expect(page).to have_content(label)
end end
@ -91,7 +91,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
# This way only the links in the table will get picked up # This way only the links in the table will get picked up
it "has an answer link for questions missing an answer" do it "has an answer link for questions missing an answer" do
visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers?referrer=check_answers") visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers?referrer=check_answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 5 assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 0 assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Answer", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers") expect(page).to have_link("Answer", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers")
end end
@ -99,7 +99,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
it "has a change link for answered questions" do it "has a change link for answered questions" do
fill_in_number_question(empty_lettings_log.id, "age1", 28, "person-1-age") fill_in_number_question(empty_lettings_log.id, "age1", 28, "person-1-age")
visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers") visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
assert_selector "a", text: "Change", count: 1 assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers") expect(page).to have_link("Change", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers")
end end

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

@ -57,7 +57,6 @@
"questions": { "questions": {
"sex1": { "sex1": {
"check_answers_card_number": 1, "check_answers_card_number": 1,
"check_answer_label": "Lead tenant’s gender identity",
"header": "Which of these best describes the tenant’s gender identity?", "header": "Which of these best describes the tenant’s gender identity?",
"type": "radio", "type": "radio",
"answer_options": { "answer_options": {

25
spec/requests/form_controller_spec.rb

@ -546,7 +546,7 @@ RSpec.describe FormController, type: :request do
end end
before do before do
post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}?referrer=interruption_screen", params: post "/lettings-logs/#{lettings_log.id}/lead-tenant-age?referrer=interruption_screen", params:
end end
it "redirects back to the soft validation page" do it "redirects back to the soft validation page" do
@ -560,6 +560,29 @@ RSpec.describe FormController, type: :request do
end end
end end
context "when the question was accessed from an interruption screen and it has no check answers" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "person_1_gender",
sex1: "F",
interruption_page_id: "retirement_value_check",
},
}
end
before do
post "/lettings-logs/#{lettings_log.id}/lead-tenant-gender-identity?referrer=interruption_screen", params:
end
it "displays a success banner without crashing" do
follow_redirect!
follow_redirect!
expect(response.body).to include("You have successfully updated")
end
end
context "when requesting a soft validation page for validation that isn't triggering" do context "when requesting a soft validation page for validation that isn't triggering" do
before do before do
get "/lettings-logs/#{lettings_log.id}/retirement-value-check", headers: headers.merge({ "HTTP_REFERER" => referrer }) get "/lettings-logs/#{lettings_log.id}/retirement-value-check", headers: headers.merge({ "HTTP_REFERER" => referrer })

Loading…
Cancel
Save