diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index e804b5ac1..48853c54a 100644 --- a/app/helpers/tasklist_helper.rb +++ b/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?} diff --git a/app/views/case_logs/edit.html.erb b/app/views/case_logs/edit.html.erb index 60a3cb4e6..074c8ff90 100644 --- a/app/views/case_logs/edit.html.erb +++ b/app/views/case_logs/edit.html.erb @@ -6,7 +6,7 @@

This submission is <%= @case_log.status %>

-

You've completed 0 of 9 sections.

+

You've completed <%= get_sections_count(@form, @case_log, :completed) %> of <%= get_sections_count(@form, @case_log, :all) %> sections.

Skip to next incomplete section

diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 2ae23d9a3..d9863dcc4 100644 --- a/spec/features/case_log_spec.rb +++ b/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('_', ' ')}") diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 3547782d8..be08c939f 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/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