diff --git a/app/models/form.rb b/app/models/form.rb index 0617bfad6..7076d9a20 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -55,10 +55,13 @@ class Form first_question_in_subsection = next_subsection.pages.first.id return "#{first_question_in_subsection}".dasherize end - + next_subsection_id_index = subsection_ids.index(subsection.id) + 1 next_subsection = get_subsection(subsection_ids[next_subsection_id_index]) + if(next_subsection.id == "declaration" && case_log.status != "completed") + next_subsection = get_subsection(subsection_ids[0]) + end if(next_subsection.status(case_log) == :completed) next_incomplete_section_redirect_path(next_subsection, case_log) else diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index f4f889723..94dd857b3 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -152,9 +152,24 @@ RSpec.describe "Form Check Answers Page" do other_hhmemb: 0, armedforces: "No", illness: "No", - accessibility_requirements: "Don’t know", + housingneeds_h: "Yes", la: "York", - condition_effects: "Hearing - such as deafness or partial hearing" + illness_type_1: "Yes" + ) + end + + let(:cycle_sections_case_log) do + FactoryBot.create( + :case_log, + :in_progress, + owning_organisation: user.organisation, + managing_organisation: user.organisation, + layear: "1 to 2 years", + lawaitlist: "Less than 1 year", + property_postcode: "NW1 5TY", + reason: "Permanently decanted from another property owned by this landlord", + previous_postcode: "SE2 6RT", + mrcdate: Time.zone.parse("03/11/2019") ) end @@ -170,6 +185,12 @@ RSpec.describe "Form Check Answers Page" do expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/tenancy-code") end + it "they can click a button to cycle around to the next incomplete section" do + visit("/logs/#{cycle_sections_case_log.id}/local-authority/check-answers") + click_link("Save and go to next incomplete section") + expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code") + end + it "they can click a button to move to the submission section when all sections have been completed", js:true do visit("/logs/#{completed_case_log.id}/local-authority/check-answers") click_link("Save and go to submit") diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 7b7886dc0..8d094d5af 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -36,6 +36,7 @@ RSpec.describe Form, type: :model do describe "next_incomplete_section_redirect_path" do let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:subsection) { form.get_subsection("household_characteristics") } + let(:later_subsection) { form.get_subsection("local_authority") } context "when a user is on the check answers page for a subsection" do @@ -53,12 +54,22 @@ RSpec.describe Form, type: :model do it "returns the first page of the next incomplete subsection (skipping completed subsections)" do case_log.armedforces = "No" case_log.illness = "No" - case_log.accessibility_requirements = "Don’t know" + case_log.housingneeds_a = "Yes" case_log.la = "York" - case_log.condition_effects = "Hearing - such as deafness or partial hearing" + case_log.illness_type_1 = "Yes" expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code") end + it "returns the next incomplete section by cycling back around if next subsections are completed" do + case_log.layear = "1 to 2 years" + case_log.lawaitlist = "Less than 1 year" + case_log.property_postcode = "NW1 5TY" + case_log.reason = "Permanently decanted from another property owned by this landlord" + case_log.previous_postcode = "SE2 6RT" + case_log.mrcdate = Time.zone.parse("03/11/2019") + expect(form.next_incomplete_section_redirect_path(later_subsection, case_log)).to eq("armed-forces") + end + it "returns the declaration section if all sections are complete" do expect(form.next_incomplete_section_redirect_path(subsection, completed_case_log)).to eq("declaration") end