Browse Source

add a test for and rename first_page_or_check_answers'

pull/308/head
Kat 3 years ago
parent
commit
eb699c232f
  1. 4
      app/helpers/tasklist_helper.rb
  2. 11
      spec/fixtures/forms/2021_2022.json
  3. 11
      spec/helpers/tasklist_helper_spec.rb

4
app/helpers/tasklist_helper.rb

@ -25,7 +25,7 @@ module TasklistHelper
case_log.form.subsections.count { |subsection| subsection.status(case_log) == status } case_log.form.subsections.count { |subsection| subsection.status(case_log) == status }
end 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) path = if subsection.is_started?(case_log)
"case_log_#{subsection.id}_check_answers_path" "case_log_#{subsection.id}_check_answers_path"
else else
@ -37,7 +37,7 @@ module TasklistHelper
def subsection_link(subsection, case_log) def subsection_link(subsection, case_log)
if subsection.status(case_log) != :cannot_start_yet 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 }) govuk_link_to(subsection.label, next_page_path.dasherize, aria: { describedby: subsection.id.dasherize })
else else
subsection.label subsection.label

11
spec/fixtures/forms/2021_2022.json vendored

@ -19,8 +19,15 @@
"type": "text", "type": "text",
"width": 10 "width": 10
} }
} },
}, "depends_on": [
{
"housingneeds_a": "Yes"
},
{
"housingneeds_a": null
}
] },
"person_1_age": { "person_1_age": {
"questions": { "questions": {
"age1": { "age1": {

11
spec/helpers/tasklist_helper_spec.rb

@ -37,15 +37,20 @@ RSpec.describe TasklistHelper do
end end
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") } let(:subsection) { case_log.form.get_subsection("household_characteristics") }
it "returns the check answers page path if the section has been started already" do 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 end
it "returns the first question page path for the section if it has not been started yet" do 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
end end

Loading…
Cancel
Save