diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index d4c61cc6a..fc67e91f2 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -104,10 +104,15 @@ private content["conditional_route_to"].each do |route, answer| if responses_for_page[question] == answer + if route == "check_answers" + subsection = subsection_for_page(previous_page) + return "case_log_#{subsection}_check_answers_path" + end return "case_log_#{route}_path" end end end + form.next_page_redirect_path(previous_page) end end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 419c1e09b..a3d10a43d 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -344,5 +344,16 @@ RSpec.describe "Test Features" do click_button("Save and continue") expect(page).to have_current_path("/case_logs/#{id}/conditional_question_no_page") end + + + it "can route based on page inclusion rules" do + visit("case_logs/#{id}/conditional_question") + choose("case-log-pregnancy-yes-field", allow_label_click: true) + click_button("Save and continue") + expect(page).to have_current_path("/case_logs/#{id}/conditional_question_yes_page") + choose("case-log-cbl-letting-yes-field", allow_label_click: true) + click_button("Save and continue") + expect(page).to have_current_path("/case_logs/conditional_question/check_answers") + end end end diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index dad82a79d..485784890 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -258,13 +258,17 @@ }, "conditional_question_yes_page": { "questions": { - "conditional_question_yes_question": { + "cbl_letting": { "check_answer_label": "Has the next condition been met?", "header": "Has the next condition been met?", "type": "radio", "answer_options": { "0": "Yes", "1": "No" + }, + "conditional_route_to": { + "check_answers": "Yes", + "check_answers": "No" } } } @@ -281,6 +285,22 @@ } } } + }, + "conditional_question_no_second_page": { + "questions": { + "conditional_question_no_second_question": { + "check_answer_label": "Has the condition not been met again?", + "header": "Has the next condition not been met again?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + }, + "include_page_condition": { + "pregnancy": "No" + } + } + } } } } diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 4481c2735..87532a578 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -122,7 +122,7 @@ RSpec.describe CheckAnswersHelper do it "counts correct questions when the conditional question is answered" do case_log["pregnancy"] = "No" - expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(2) + expect(total_number_of_questions(conditional_routing_subsection, case_log, form)).to eq(3) end end end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 27c80d5ea..ff6d4dc0f 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -15,7 +15,7 @@ RSpec.describe FormHandler do form_handler = FormHandler.instance form = form_handler.get_form("test_form") expect(form).to be_a(Form) - expect(form.all_pages.count).to eq(21) + expect(form.all_pages.count).to eq(22) end end