Browse Source

Display completed sections count

pull/28/head
Kat 4 years ago
parent
commit
02336e9e69
  1. 8
      app/helpers/tasklist_helper.rb
  2. 2
      app/views/case_logs/edit.html.erb
  3. 34
      spec/features/case_log_spec.rb
  4. 30
      spec/helpers/tasklist_helper_spec.rb

8
app/helpers/tasklist_helper.rb

@ -39,6 +39,14 @@ module TasklistHelper
return subsections.find { |subsection| is_incomplete?(subsection, case_log, form.questions_for_subsection(subsection).keys) }
end
def get_sections_count(form, case_log, status = :all)
subsections = form.all_subsections.keys
if status == :all
return subsections.count
end
return subsections.count { |subsection| get_subsection_status(subsection, case_log, form.questions_for_subsection(subsection).keys) == status }
end
private
def all_questions_completed(case_log)
case_log.attributes.all? { |_question, answer| answer.present?}

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

@ -6,7 +6,7 @@
<h2 class="govuk-heading-s govuk-!-margin-bottom-2">This submission is
<%= @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 <%= get_sections_count(@form, @case_log, :completed) %> of <%= get_sections_count(@form, @case_log, :all) %> sections.</p>
<p class="govuk-body govuk-!-margin-bottom-7">
<a href="#<%= get_next_incomplete_section(@form, @case_log) %>">Skip to next incomplete section</a>
</p>

34
spec/features/case_log_spec.rb

@ -15,6 +15,18 @@ RSpec.describe "Test Features" do
household_number_of_other_members: { type: "numeric", answer: 2 },
}
def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("net_income", with: 18_000)
choose("net-income-frequency-yearly-field")
click_button("Save and continue")
choose("net-income-uc-proportion-all-field")
click_button("Save and continue")
choose("housing-benefit-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
end
describe "Create new log" do
it "redirects to the task list for the new log" do
visit("/case_logs")
@ -44,6 +56,17 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{empty_case_log.id}")
expect(page).to have_link("Skip to next incomplete section", :href => /#household_characteristics/)
end
it "shows the number of completed sections if no sections are completed" do
visit("/case_logs/#{empty_case_log.id}")
expect(page).to have_content("You've completed 0 of 9 sections.")
end
it "shows the number of completed sections if one section is completed" do
answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}")
expect(page).to have_content("You've completed 1 of 9 sections.")
end
end
it "displays the household questions when you click into that section" do
@ -123,17 +146,6 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("net_income", with: 18_000)
choose("net-income-frequency-yearly-field")
click_button("Save and continue")
choose("net-income-uc-proportion-all-field")
click_button("Save and continue")
choose("housing-benefit-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
end
it "can be visited by URL" do
visit("case_logs/#{id}/#{subsection}/check_answers")
expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}")

30
spec/helpers/tasklist_helper_spec.rb

@ -51,4 +51,34 @@ RSpec.describe TasklistHelper do
expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics")
end
end
describe "get sections count" do
let!(:empty_case_log) { FactoryBot.create(:case_log) }
let!(:case_log) { FactoryBot.create(:case_log, :in_progress) }
it "returns the total of sections if no status is given" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, empty_case_log)).to eq(9)
end
it "returns 0 sections for completed sections if no sections are completed" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, empty_case_log, :completed)).to eq(0)
end
it "returns the number of not started sections" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, empty_case_log, :not_started)).to eq(8)
end
it "returns the number of sections in progress" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, case_log, :in_progress)).to eq(1)
end
it "returns 0 for invalid state" do
@form = Form.new(2021, 2022)
expect(get_sections_count(@form, case_log, :fake)).to eq(0)
end
end
end

Loading…
Cancel
Save