diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 61fb7dbe5..e804b5ac1 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -13,10 +13,7 @@ module TasklistHelper :in_progress => "govuk-tag--blue" } - def get_subsection_status(subsection_name, case_log) - @form = Form.new(2021, 2022) - questions = @form.questions_for_subsection(subsection_name).keys - + def get_subsection_status(subsection_name, case_log, questions) if subsection_name == "declaration" return all_questions_completed(case_log) ? :not_started : :cannot_start_yet end @@ -39,7 +36,7 @@ module TasklistHelper def get_next_incomplete_section(form, case_log) subsections = form.all_subsections.keys - return subsections.find { |subsection| is_incomplete?(subsection, case_log) } + return subsections.find { |subsection| is_incomplete?(subsection, case_log, form.questions_for_subsection(subsection).keys) } end private @@ -47,8 +44,8 @@ module TasklistHelper case_log.attributes.all? { |_question, answer| answer.present?} end - def is_incomplete?(subsection, case_log) - status = get_subsection_status(subsection, case_log) + def is_incomplete?(subsection, case_log, questions) + status = get_subsection_status(subsection, case_log, questions) return status == :not_started || status == :in_progress end end diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index df9c6d28b..3806758b6 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -10,8 +10,8 @@ <% section_value["subsections"].map do |subsection_key, subsection_value| %>
  • > <% 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" %> - <% subsection_status=get_subsection_status(subsection_key, @case_log) %> + <%= link_to subsection_value["label"], send("case_log_#{first_page}_path", @case_log), class: "task-name govuk-link" %> + <% subsection_status=get_subsection_status(subsection_key, @case_log, @form.questions_for_subsection(subsection_key)) %> <%= get_status_label(subsection_status) %> diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 47bbbbd20..3547782d8 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -2,29 +2,38 @@ require "rails_helper" RSpec.describe TasklistHelper do describe "get subsection status" do + @form = Form.new(2021, 2022) + income_and_benefits_questions = @form.questions_for_subsection("income_and_benefits").keys + declaration_questions = @form.questions_for_subsection("declaration").keys + local_authority_questions = @form.questions_for_subsection("local_authority").keys let!(:case_log) { FactoryBot.create(:case_log) } 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) + status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions) + expect(status).to eq(:not_started) end it "returns cannot start yet if the subsection is declaration" do - expect(get_subsection_status("declaration", case_log)).to eq(:cannot_start_yet) + status = get_subsection_status("declaration", case_log, declaration_questions) + expect(status).to eq(:cannot_start_yet) end it "returns in progress if some of the questions have been answered" do case_log["previous_postcode"] = "P0 5TT" - expect(get_subsection_status("local_authority", case_log)).to eq(:in_progress) + status = get_subsection_status("local_authority", case_log, local_authority_questions) + expect(status).to eq(:in_progress) end it "returns completed if all the questions in the subsection have been answered" do %w(net_income net_income_frequency net_income_uc_proportion housing_benefit).each {|x| case_log[x] = "value" } - expect(get_subsection_status("income_and_benefits", case_log)).to eq(:completed) + status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions) + expect(status).to eq(:completed) end it "returns not started if the subsection is declaration and all the questions are completed" do completed_case_log = CaseLog.new(case_log.attributes.map { |key, value| Hash[key, value || "value"] }.reduce(:merge)) - expect(get_subsection_status("declaration", completed_case_log)).to eq(:not_started) + status = get_subsection_status("declaration", completed_case_log, declaration_questions) + expect(status).to eq(:not_started) end end