Browse Source

Fix the tests

pull/49/head
Kat 4 years ago
parent
commit
c18c9a8f06
  1. 10
      app/helpers/check_answers_helper.rb
  2. 7
      app/models/form.rb
  3. 3
      spec/fixtures/forms/test_form.json
  4. 12
      spec/helpers/check_answers_helper_spec.rb

10
app/helpers/check_answers_helper.rb

@ -41,19 +41,15 @@ module CheckAnswersHelper
end end
def get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value) def get_next_page_name(form, page_name, appliccable_questions, question_key, case_log, question_value)
new_page_name = form.next_page(page_name)
if form.all_pages[page_name].key?("default_next_page")
new_page_name = form.all_pages[page_name]["default_next_page"]
end
if appliccable_questions[question_key].key?("conditional_route_to") if appliccable_questions[question_key].key?("conditional_route_to")
appliccable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition| appliccable_questions[question_key]["conditional_route_to"].each do |conditional_page_key, condition|
unless condition_not_met(case_log, question_key, question_value, condition) unless condition_not_met(case_log, question_key, question_value, condition)
new_page_name = conditional_page_key return conditional_page_key
end end
end end
end end
new_page_name
form.next_page(page_name)
end end
def condition_not_met(case_log, question_key, question, condition) def condition_not_met(case_log, question_key, question, condition)

7
app/models/form.rb

@ -52,6 +52,13 @@ class Form
end end
def next_page(previous_page) def next_page(previous_page)
if all_pages[previous_page].key?("default_next_page")
next_page = all_pages[previous_page]["default_next_page"]
return :check_answers if next_page == "check_answers"
return next_page
end
subsection = subsection_for_page(previous_page) subsection = subsection_for_page(previous_page)
previous_page_idx = pages_for_subsection(subsection).keys.index(previous_page) previous_page_idx = pages_for_subsection(subsection).keys.index(previous_page)
pages_for_subsection(subsection).keys[previous_page_idx + 1] || :check_answers pages_for_subsection(subsection).keys[previous_page_idx + 1] || :check_answers

3
spec/fixtures/forms/test_form.json vendored

@ -496,7 +496,8 @@
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", "check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation", "header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text" "type": "text",
"conditional_for": { "faake_key": "fake_condition" }
} }
} }
} }

12
spec/helpers/check_answers_helper_spec.rb

@ -91,22 +91,16 @@ RSpec.describe CheckAnswersHelper do
context "conditional questions with type that hasn't been implemented yet" do context "conditional questions with type that hasn't been implemented yet" do
let(:unimplemented_conditional) do let(:unimplemented_conditional) do
{ "question_1" => { "previous_postcode" =>
{ "header" => "The actual question?", { "header" => "The actual question?",
"hint_text" => "", "hint_text" => "",
"type" => "date", "type" => "date",
"check_answer_label" => "Question Label", "check_answer_label" => "Question Label",
"conditional_for" => { "question_2" => %w[12-12-2021] } }, "conditional_for" => { "question_2" => %w[12-12-2021] } } }
"question_2" =>
{ "header" => "The second actual question?",
"hint_text" => "",
"type" => "radio",
"check_answer_label" => "The second question label",
"answer_options" => { "0" => "Yes", "1" => "No" } } }
end end
it "raises an error" do it "raises an error" do
allow_any_instance_of(Form).to receive(:questions_for_subsection).and_return(unimplemented_conditional) allow_any_instance_of(Form).to receive(:pages_for_subsection).and_return(unimplemented_conditional)
expect { total_number_of_questions(subsection, case_log, form) }.to raise_error(RuntimeError, "Not implemented yet") expect { total_number_of_questions(subsection, case_log, form) }.to raise_error(RuntimeError, "Not implemented yet")
end end
end end

Loading…
Cancel
Save