Browse Source

add button for moving to next incomplete section

pull/252/head
MadeTech Dushan 3 years ago
parent
commit
8cda8cbc84
  1. 20
      app/models/form.rb
  2. 8
      app/views/form/check_answers.html.erb
  3. 59
      spec/features/form/check_answers_page_spec.rb
  4. 32
      spec/models/form_spec.rb

20
app/models/form.rb

@ -46,6 +46,26 @@ class Form
"case_log_#{nxt_page}_path"
end
end
def next_incomplete_section_redirect_path(subsection, case_log)
subsection_ids = subsections.map(&:id)
if(case_log.status == "completed")
next_subsection = get_subsection(subsection_ids[subsection_ids.length - 1])
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.status(case_log) == :completed)
next_incomplete_section_redirect_path(next_subsection, case_log)
else
first_question_in_subsection = next_subsection.pages.first.id
return "#{first_question_in_subsection}".dasherize
end
end
def conditional_question_conditions
conditions = questions.map { |q| Hash(q.id => q.conditional_for) if q.conditional_for.present? }.compact

8
app/views/form/check_answers.html.erb

@ -22,7 +22,13 @@
</dl>
<%= form_with model: @case_log, method: "get" do |f| %>
<%= f.govuk_submit "Save and continue" %>
<%= f.govuk_submit 'Save and continue' do %>
<% if @case_log.status == "in_progress" %>
<a class="govuk-button govuk-button--secondary" href=<%= "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}" %>>Save and go to next incomplete section</a>
<% elsif @case_log.status == "completed" %>
<a class="govuk-button govuk-button--secondary" href=<%= "/logs/#{@case_log.id}/#{@case_log.form.next_incomplete_section_redirect_path(subsection, @case_log)}" %>>Save and go to submit</a>
<% end%>
<% end %>
<% end %>
</div>
</div>

59
spec/features/form/check_answers_page_spec.rb

@ -22,6 +22,14 @@ RSpec.describe "Form Check Answers Page" do
managing_organisation: user.organisation,
)
end
let(:completed_case_log) do
FactoryBot.create(
:case_log,
:completed,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
let(:id) { case_log.id }
before do
@ -117,5 +125,56 @@ RSpec.describe "Form Check Answers Page" do
expect(page).not_to have_content(label)
end
end
context "when the user wants to bypass the tasklist page from check answers" do
let(:section_completed_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
)
end
let(:skip_section_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",
accessibility_requirements: "Don’t know",
la: "York",
condition_effects: "Hearing - such as deafness or partial hearing"
)
end
it "they can click a button to move onto the next 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 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")
expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/tenancy-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")
expect(page).to have_current_path("/logs/#{completed_case_log.id}/declaration")
end
end
end
end

32
spec/models/form_spec.rb

@ -33,6 +33,38 @@ RSpec.describe Form, type: :model do
end
end
describe "next_incomplete_section_redirect_path" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
let(:subsection) { form.get_subsection("household_characteristics") }
context "when a user is on the check answers page for a subsection" do
before do
case_log.tenant_code = "123"
case_log.age1 = 35
case_log.sex1 = "Male"
case_log.other_hhmemb = 0
end
it "returns the first page of the next incomplete subsection" do
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("armed-forces")
end
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.la = "York"
case_log.condition_effects = "Hearing - such as deafness or partial hearing"
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code")
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
end
end
describe "invalidated_page_questions" do
context "when dependencies are not met" do
let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question declaration] }

Loading…
Cancel
Save