diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb new file mode 100644 index 000000000..1937394b0 --- /dev/null +++ b/app/helpers/tag_helper.rb @@ -0,0 +1,25 @@ +module TagHelper + include GovukComponentsHelper + + TEXT = { + not_started: "Not started", + cannot_start_yet: "Cannot start yet", + in_progress: "In progress", + completed: "Completed", + }.freeze + + COLOUR = { + not_started: "grey", + cannot_start_yet: "grey", + in_progress: "blue", + completed: "green", + }.freeze + + def status_tag(status, classes = []) + govuk_tag( + classes:, + colour: COLOUR[status.to_sym], + text: TEXT[status.to_sym], + ) + end +end diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 4d4a9aabb..9822958bb 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -1,20 +1,6 @@ module TasklistHelper include GovukLinkHelper - STATUSES = { - not_started: "Not started", - cannot_start_yet: "Cannot start yet", - completed: "Completed", - in_progress: "In progress", - }.freeze - - STYLES = { - not_started: "govuk-tag--grey", - cannot_start_yet: "govuk-tag--grey", - completed: "", - in_progress: "govuk-tag--blue", - }.freeze - def get_next_incomplete_section(case_log) case_log.form.subsections.find { |subsection| subsection.is_incomplete?(case_log) } end diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index 9e6a61256..bf027896c 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -41,10 +41,7 @@ <%= log.created_at.to_formatted_s(:govuk_date) %>
This log has not been started.
<% elsif @case_log.status == "completed" %>- <%= govuk_tag(text: "Completed") %> + <%= status_tag(@case_log.status) %>
You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@case_log.id}/review" %> up to 3 months after the end of the current collection year, which closes on 31 March <%= @case_log.collection_start_year.present? ? @case_log.collection_start_year + 1 : "" %>. diff --git a/spec/helpers/tag_helper_spec.rb b/spec/helpers/tag_helper_spec.rb new file mode 100644 index 000000000..bbdaeb8be --- /dev/null +++ b/spec/helpers/tag_helper_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +RSpec.describe TagHelper do + let(:empty_case_log) { FactoryBot.create(:case_log) } + let(:case_log) { FactoryBot.create(:case_log, :in_progress) } + + describe "get the status tag" do + it "returns tag with correct status text and colour" do + expect(status_tag(case_log.status)).to eq("In progress") + end + + it "returns tag with correct status text and colour and custom class" do + expect(status_tag("not_started", "app-tag--small")).to eq("Not started") + end + end +end