Browse Source

Add la_known to dynamically not required questions if postcode_known is yes or not filled in

pull/496/head
Kat 3 years ago
parent
commit
05b32b3e7a
  1. 5
      app/models/case_log.rb
  2. 4
      app/models/form.rb
  3. 6
      spec/features/form/check_answers_page_spec.rb
  4. 4
      spec/models/form_spec.rb

5
app/models/case_log.rb

@ -418,7 +418,10 @@ private
end end
def dynamically_not_required def dynamically_not_required
(form.invalidated_questions(self) + form.readonly_questions).map(&:id).uniq la_known_questions = []
la_known_questions << "la_known" if postcode_known != 0
la_known_questions << "previous_la_known" if previous_postcode_known != 0
((form.invalidated_questions(self) + form.readonly_questions).map(&:id) + la_known_questions).uniq
end end
def set_derived_fields! def set_derived_fields!

4
app/models/form.rb

@ -58,7 +58,7 @@ class Form
def next_incomplete_section_redirect_path(subsection, case_log) def next_incomplete_section_redirect_path(subsection, case_log)
subsection_ids = subsections.map(&:id) subsection_ids = subsections.map(&:id)
if case_log.status == "completed" || all_subsections_except_declaration_completed?(case_log) if case_log.status == "completed"
return first_question_in_last_subsection(subsection_ids) return first_question_in_last_subsection(subsection_ids)
end end
@ -119,7 +119,7 @@ class Form
def invalidated_page_questions(case_log) def invalidated_page_questions(case_log)
# we're already treating address fields as a special case and reset their values upon saving a case_log # we're already treating address fields as a special case and reset their values upon saving a case_log
address_questions = %w[postcode_known la previous_postcode_known prevloc postcode_full ppostcode_full] address_questions = %w[postcode_known la_known la previous_postcode_known previous_la_known prevloc postcode_full ppostcode_full]
invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || [] invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || []
end end

6
spec/features/form/check_answers_page_spec.rb

@ -228,12 +228,6 @@ RSpec.describe "Form Check Answers Page" do
click_link("Save and go to next incomplete section") click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code") expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code")
end end
it "they can click a button to move to the submission section when all sections have been completed", js: true do
visit("/logs/#{completed_case_log.id}/local-authority/check-answers")
click_link("Save and go to submit")
expect(page).to have_current_path("/logs/#{completed_case_log.id}/declaration")
end
end end
end end
end end

4
spec/models/form_spec.rb

@ -175,7 +175,7 @@ RSpec.describe Form, type: :model do
describe "invalidated_page_questions" do describe "invalidated_page_questions" do
context "when dependencies are not met" do context "when dependencies are not met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } let(:expected_invalid) { %w[cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do
expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid) expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid)
@ -183,7 +183,7 @@ RSpec.describe Form, type: :model do
end end
context "with two pages having the same question and only one has dependencies met" do context "with two pages having the same question and only one has dependencies met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } let(:expected_invalid) { %w[cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do
case_log["preg_occ"] = "No" case_log["preg_occ"] = "No"

Loading…
Cancel
Save