Browse Source

Add conditional routing to the check answers page

pull/49/head
Kat 4 years ago
parent
commit
6cd8f69a15
  1. 5
      app/controllers/case_logs_controller.rb
  2. 11
      spec/features/case_log_spec.rb
  3. 22
      spec/fixtures/forms/test_form.json
  4. 2
      spec/helpers/check_answers_helper_spec.rb
  5. 2
      spec/models/form_handler_spec.rb

5
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

11
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

22
spec/fixtures/forms/test_form.json vendored

@ -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"
}
}
}
}
}
}

2
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

2
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

Loading…
Cancel
Save