diff --git a/app/models/form.rb b/app/models/form.rb index 37e3627a3..274428967 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -34,8 +34,19 @@ class Form def next_page(page, case_log) page_ids = subsection_for_page(page).pages.map(&:id) - page_index = page_ids.index(page.id) - nxt_page = get_page(page_ids[page_index + 1]) + if(page.id.include?("value_check")) + question_id = page.id + if(case_log[page.id] == 1) + page_index = page_ids.index(page.id) + nxt_page = get_page(page_ids[page_index - 1]) + else + page_index = page_ids.index(page.id) + nxt_page = get_page(page_ids[page_index + 1]) + end + else + page_index = page_ids.index(page.id) + nxt_page = get_page(page_ids[page_index + 1]) + end return :check_answers if nxt_page.nil? return nxt_page.id if nxt_page.routed_to?(case_log) diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index ba66e2814..1b302cb09 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -138,18 +138,15 @@ RSpec.describe "validations" do expect(page).to have_current_path("/logs/#{case_log.id}/net-income-uc-proportion") end - # it "does not require confirming the value if the value is amended" do - # visit("/logs/#{case_log.id}/net-income") - # fill_in("case-log-earnings-field", with: income_over_soft_limit) - # choose("case-log-incfreq-0-field", allow_label_click: true) - # click_button("Save and continue") - # fill_in("case-log-earnings-field", with: income_under_soft_limit) - # click_button("Save and continue") - # expect(page).to have_current_path("/logs/#{case_log.id}/net-income-uc-proportion") - # case_log.reload - # expect(case_log.net_income_value_check).to be_nil - # end - + it "returns the user to the previous question if they do not confirm the value as correct on the interruption screen" do + visit("/logs/#{case_log.id}/net-income") + fill_in("case-log-earnings-field", with: income_over_soft_limit) + choose("case-log-incfreq-0-field", allow_label_click: true) + click_button("Save and continue") + choose("case-log-net-income-value-check-1-field", allow_label_click: true) + click_button("Save and continue") + expect(page).to have_current_path("/logs/#{case_log.id}/net-income") + end # it "clears the confirmation question if the amount was amended and the page is returned to using the back button", js: true do # visit("/logs/#{case_log.id}/net-income") # fill_in("case-log-earnings-field", with: income_over_soft_limit)