Browse Source

Add extra logic for cycling sections

pull/252/head
MadeTech Dushan 3 years ago
parent
commit
f34c534640
  1. 3
      app/models/form.rb
  2. 25
      spec/features/form/check_answers_page_spec.rb
  3. 15
      spec/models/form_spec.rb

3
app/models/form.rb

@ -59,6 +59,9 @@ class Form
next_subsection_id_index = subsection_ids.index(subsection.id) + 1 next_subsection_id_index = subsection_ids.index(subsection.id) + 1
next_subsection = get_subsection(subsection_ids[next_subsection_id_index]) 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) if(next_subsection.status(case_log) == :completed)
next_incomplete_section_redirect_path(next_subsection, case_log) next_incomplete_section_redirect_path(next_subsection, case_log)
else else

25
spec/features/form/check_answers_page_spec.rb

@ -152,9 +152,24 @@ RSpec.describe "Form Check Answers Page" do
other_hhmemb: 0, other_hhmemb: 0,
armedforces: "No", armedforces: "No",
illness: "No", illness: "No",
accessibility_requirements: "Don’t know", housingneeds_h: "Yes",
la: "York", 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 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") expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/tenancy-code")
end 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 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") visit("/logs/#{completed_case_log.id}/local-authority/check-answers")
click_link("Save and go to submit") click_link("Save and go to submit")

15
spec/models/form_spec.rb

@ -36,6 +36,7 @@ RSpec.describe Form, type: :model do
describe "next_incomplete_section_redirect_path" do describe "next_incomplete_section_redirect_path" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
let(:subsection) { form.get_subsection("household_characteristics") } 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 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 it "returns the first page of the next incomplete subsection (skipping completed subsections)" do
case_log.armedforces = "No" case_log.armedforces = "No"
case_log.illness = "No" case_log.illness = "No"
case_log.accessibility_requirements = "Don’t know" case_log.housingneeds_a = "Yes"
case_log.la = "York" 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") expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code")
end 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 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") expect(form.next_incomplete_section_redirect_path(subsection, completed_case_log)).to eq("declaration")
end end

Loading…
Cancel
Save