diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 3b3afaa4e..4d4a9aabb 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -25,7 +25,7 @@ module TasklistHelper case_log.form.subsections.count { |subsection| subsection.status(case_log) == status } end - def first_page_or_check_answers(subsection, case_log) + def next_page_or_check_answers(subsection, case_log) path = if subsection.is_started?(case_log) "case_log_#{subsection.id}_check_answers_path" else @@ -37,7 +37,7 @@ module TasklistHelper def subsection_link(subsection, case_log) if subsection.status(case_log) != :cannot_start_yet - next_page_path = first_page_or_check_answers(subsection, case_log).to_s + next_page_path = next_page_or_check_answers(subsection, case_log).to_s govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize }) else subsection.label diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 3bd4edd21..6c7f5e546 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -19,8 +19,15 @@ "type": "text", "width": 10 } - } - }, + }, + "depends_on": [ + { + "housingneeds_a": "Yes" + }, + { + "housingneeds_a": null + } + ] }, "person_1_age": { "questions": { "age1": { diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index a9834a165..012e3f9b6 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -37,15 +37,20 @@ RSpec.describe TasklistHelper do end end - describe "get_first_page_or_check_answers" do + describe "get_next_page_or_check_answers" do let(:subsection) { case_log.form.get_subsection("household_characteristics") } it "returns the check answers page path if the section has been started already" do - expect(first_page_or_check_answers(subsection, case_log)).to match(/check-answers/) + expect(next_page_or_check_answers(subsection, case_log)).to match(/check-answers/) end it "returns the first question page path for the section if it has not been started yet" do - expect(first_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) + expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) + end + + it "when first question being not routed to returns the second question link" do + empty_case_log.housingneeds_a = "No" + expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-age/) end end