From 1f5454cfd666b946eb28eb1722175671cab43e4d Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Mon, 31 Jan 2022 15:24:55 +0000 Subject: [PATCH] redirect to check answers if next subsection in progress --- app/models/form.rb | 5 +++- spec/features/form/check_answers_page_spec.rb | 23 ++++++++++++++++++- spec/models/form_spec.rb | 8 ++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index a2463712b..35ba54123 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -56,8 +56,11 @@ class Form next_subsection = next_subsection(subsection, case_log, subsection_ids) - if next_subsection.status(case_log) == :completed + case next_subsection.status(case_log) + when :completed next_incomplete_section_redirect_path(next_subsection, case_log) + when :in_progress + "#{next_subsection.id}/check_answers".dasherize else first_question_in_subsection = next_subsection.pages.first.id first_question_in_subsection.to_s.dasherize diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 719ab862e..3ac40786f 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -140,6 +140,21 @@ RSpec.describe "Form Check Answers Page" do ) end + let(:next_section_in_progress_case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation, + tenant_code: "123", + age1: 35, + sex1: "Male", + other_hhmemb: 0, + armedforces: "No", + illness: "No", + ) + end + let(:skip_section_case_log) do FactoryBot.create( :case_log, @@ -173,12 +188,18 @@ RSpec.describe "Form Check Answers Page" do ) end - it "they can click a button to move onto the next section" do + it "they can click a button to move onto the first page of the next (not started) incomplete section" do visit("/logs/#{section_completed_case_log.id}/household-characteristics/check-answers") click_link("Save and go to next incomplete section") expect(page).to have_current_path("/logs/#{section_completed_case_log.id}/armed-forces") end + it "they can click a button to move onto the check answers page of the next (in progress) incomplete section" do + visit("/logs/#{next_section_in_progress_case_log.id}/household-characteristics/check-answers") + click_link("Save and go to next incomplete section") + expect(page).to have_current_path("/logs/#{next_section_in_progress_case_log.id}/household-needs/check-answers") + end + it "they can click a button to skip sections until the next incomplete section" do visit("/logs/#{skip_section_case_log.id}/household-characteristics/check-answers") click_link("Save and go to next incomplete section") diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index ba1113382..67269e78e 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -92,10 +92,16 @@ RSpec.describe Form, type: :model do case_log.other_hhmemb = 0 end - it "returns the first page of the next incomplete subsection" do + it "returns the first page of the next incomplete subsection if the subsection is not in progress" do expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("armed-forces") end + it "returns the check answers page of the next incomplete subsection if the subsection is already in progress" do + case_log.armedforces = "No" + case_log.illness = "No" + expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("household-needs/check-answers") + end + it "returns the first page of the next incomplete subsection (skipping completed subsections)" do answer_household_needs(case_log) expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code")