From 15f1bfb10333a8419a530e9cafa08fd2213de876 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 4 Oct 2021 12:12:38 +0100 Subject: [PATCH] Add styling change return of get status --- app/helpers/tasklist_helper.rb | 30 ++++++++++++++++++++++---- app/views/case_logs/_tasklist.html.erb | 4 ++-- spec/helpers/tasklist_helper_spec.rb | 10 ++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 788f258c0..6512be4d2 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -1,21 +1,43 @@ module TasklistHelper + STATUSES = { + :not_started => "Not started", + :cannot_start_yet => "Cannot start yet", + :completed => "Completed", + :in_progress => "In progress" + } + + STYLES = { + :not_started => "govuk-tag--grey", + :cannot_start_yet => "govuk-tag--grey", + :completed => "", + :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 if subsection_name == "declaration" - return all_questions_completed(case_log) ? "Not started" : "Cannot start yet" + return all_questions_completed(case_log) ? :not_started : :cannot_start_yet end if questions.all? {|question| case_log[question].blank?} - return "Not started" + return :not_started end if questions.all? {|question| case_log[question].present?} - return "Completed" + return :completed end - "In progress" + :in_progress end def all_questions_completed(case_log) case_log.attributes.all? { |_question, answer| answer.present?} end + + def get_status_style(status_label) + STYLES[status_label] + end + + def get_status_label(status) + STATUSES[status] + end end diff --git a/app/views/case_logs/_tasklist.html.erb b/app/views/case_logs/_tasklist.html.erb index b09864cae..dd139fe9b 100644 --- a/app/views/case_logs/_tasklist.html.erb +++ b/app/views/case_logs/_tasklist.html.erb @@ -12,8 +12,8 @@ <% 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) %> - - <%= subsection_status %> + + <%= get_status_label(subsection_status) %> <% end %> diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 98f886a29..ae74cd716 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -6,26 +6,26 @@ RSpec.describe TasklistHelper do @form = Form.new(2021, 2022) 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) end it "returns cannot start yet if the subsection is declaration" do - expect(get_subsection_status("declaration", case_log)).to eq("Cannot start yet") + expect(get_subsection_status("declaration", case_log)).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") + expect(get_subsection_status("local_authority", case_log)).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") + expect(get_subsection_status("income_and_benefits", case_log)).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") + expect(get_subsection_status("declaration", completed_case_log)).to eq(:not_started) end end end