Browse Source

redirect to check answers if next subsection in progress

pull/252/head
MadeTech Dushan 3 years ago
parent
commit
1f5454cfd6
  1. 5
      app/models/form.rb
  2. 23
      spec/features/form/check_answers_page_spec.rb
  3. 8
      spec/models/form_spec.rb

5
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

23
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")

8
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")

Loading…
Cancel
Save