Browse Source

Make skip to next incomplete section functional

pull/28/head
Kat 4 years ago
parent
commit
a0653e2c3b
  1. 19
      app/helpers/tasklist_helper.rb
  2. 2
      app/views/case_logs/_tasklist.html.erb
  3. 2
      app/views/case_logs/edit.html.erb
  4. 5
      spec/features/case_log_spec.rb
  5. 16
      spec/helpers/tasklist_helper_spec.rb

19
app/helpers/tasklist_helper.rb

@ -29,10 +29,6 @@ module TasklistHelper
:in_progress :in_progress
end end
def all_questions_completed(case_log)
case_log.attributes.all? { |_question, answer| answer.present?}
end
def get_status_style(status_label) def get_status_style(status_label)
STYLES[status_label] STYLES[status_label]
end end
@ -40,4 +36,19 @@ module TasklistHelper
def get_status_label(status) def get_status_label(status)
STATUSES[status] STATUSES[status]
end end
def get_next_incomplete_section(form, case_log)
subsections = form.all_subsections.keys
return subsections.find { |subsection| is_incomplete?(subsection, case_log) }
end
private
def all_questions_completed(case_log)
case_log.attributes.all? { |_question, answer| answer.present?}
end
def is_incomplete?(subsection, case_log)
status = get_subsection_status(subsection, case_log)
return status == :not_started || status == :in_progress
end
end end

2
app/views/case_logs/_tasklist.html.erb

@ -8,7 +8,7 @@
</h2> </h2>
<ul class="app-task-list__items"> <ul class="app-task-list__items">
<% section_value["subsections"].map do |subsection_key, subsection_value| %> <% section_value["subsections"].map do |subsection_key, subsection_value| %>
<li class="app-task-list__item"> <li class="app-task-list__item" id=<%= subsection_key %>>
<% first_page = @form.first_page_for_subsection(subsection_key) %> <% first_page = @form.first_page_for_subsection(subsection_key) %>
<%= link_to subsection_value["label"], send("case_log_#{first_page}_path", @case_log), class: "task-name" %> <%= link_to subsection_value["label"], send("case_log_#{first_page}_path", @case_log), class: "task-name" %>
<% subsection_status=get_subsection_status(subsection_key, @case_log) %> <% subsection_status=get_subsection_status(subsection_key, @case_log) %>

2
app/views/case_logs/edit.html.erb

@ -8,7 +8,7 @@
<%= @case_log.status %></h2> <%= @case_log.status %></h2>
<p class="govuk-body govuk-!-margin-bottom-7">You've completed 0 of 9 sections.</p> <p class="govuk-body govuk-!-margin-bottom-7">You've completed 0 of 9 sections.</p>
<p class="govuk-body govuk-!-margin-bottom-7"> <p class="govuk-body govuk-!-margin-bottom-7">
<a href="#">Skip to next incomplete section</a> <a href="#<%= get_next_incomplete_section(@form, @case_log) %>">Skip to next incomplete section</a>
</p> </p>
<%= render "tasklist", locals: { form: @form } %> <%= render "tasklist", locals: { form: @form } %>

5
spec/features/case_log_spec.rb

@ -39,6 +39,11 @@ RSpec.describe "Test Features" do
assert_selector ".govuk-tag", text: /Completed/, count: 0 assert_selector ".govuk-tag", text: /Completed/, count: 0
assert_selector ".govuk-tag", text: /Cannot start yet/, count: 1 assert_selector ".govuk-tag", text: /Cannot start yet/, count: 1
end end
it "skips to the first section if no answers are completed" do
visit("/case_logs/#{empty_case_log.id}")
expect(page).to have_link("Skip to next incomplete section", :href => /#household_characteristics/)
end
end end
it "displays the household questions when you click into that section" do it "displays the household questions when you click into that section" do

16
spec/helpers/tasklist_helper_spec.rb

@ -3,7 +3,6 @@ require "rails_helper"
RSpec.describe TasklistHelper do RSpec.describe TasklistHelper do
describe "get subsection status" do describe "get subsection status" do
let!(:case_log) { FactoryBot.create(:case_log) } let!(:case_log) { FactoryBot.create(:case_log) }
@form = Form.new(2021, 2022)
it "returns not started if none of the questions in the subsection are answered" do it "returns not started if none of the questions in the subsection are answered" do
expect(get_subsection_status("income_and_benefits", case_log)).to eq(:not_started) expect(get_subsection_status("income_and_benefits", case_log)).to eq(:not_started)
@ -28,4 +27,19 @@ RSpec.describe TasklistHelper do
expect(get_subsection_status("declaration", completed_case_log)).to eq(:not_started) expect(get_subsection_status("declaration", completed_case_log)).to eq(:not_started)
end end
end end
describe "get next incomplete section" do
let!(:case_log) { FactoryBot.create(:case_log) }
it "returns the first subsection name if it is not completed" do
@form = Form.new(2021, 2022)
expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics")
end
it "returns the first subsection name if it is partially completed" do
@form = Form.new(2021, 2022)
case_log["tenant_code"] = 123
expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics")
end
end
end end

Loading…
Cancel
Save