Browse Source

CLDC-1913 Change date question hint text (#1293)

* change hardcoded date text to today's date formatted correctly

* update to show an example date in the tax year of the relevant log where that year is known

* move helper method and reuse some existing logic, adjust tests accordingly
pull/1350/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
f9d91581fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/helpers/collection_time_helper.rb
  2. 2
      app/views/form/_date_question.html.erb
  3. 1
      config/initializers/date_formats.rb
  4. 33
      spec/helpers/collection_time_helper_spec.rb

5
app/helpers/collection_time_helper.rb

@ -12,6 +12,11 @@ module CollectionTimeHelper
Time.zone.local(collection_start_year(date), 4, 1) Time.zone.local(collection_start_year(date), 4, 1)
end end
def date_mid_collection_year_formatted(date)
example_date = date.nil? ? Time.zone.today : collection_start_date(date).to_date + 5.months
example_date.to_formatted_s(:govuk_date_number_month)
end
def current_collection_start_date def current_collection_start_date
Time.zone.local(current_collection_start_year, 4, 1) Time.zone.local(current_collection_start_year, 4, 1)
end end

2
app/views/form/_date_question.html.erb

@ -3,7 +3,7 @@
<%= f.govuk_date_field question.id.to_sym, <%= f.govuk_date_field question.id.to_sym,
caption: caption(caption_text, page_header, conditional), caption: caption(caption_text, page_header, conditional),
legend: legend(question, page_header, conditional), legend: legend(question, page_header, conditional),
hint: { text: question.hint_text&.html_safe || "For example, 1 9 2022." }, hint: { text: question.hint_text&.html_safe || "For example, #{date_mid_collection_year_formatted(lettings_log.startdate)}" },
width: 20, width: 20,
**stimulus_html_attributes(question) do %> **stimulus_html_attributes(question) do %>
<%= govuk_inset_text(text: question.unresolved_hint_text) if question.unresolved_hint_text.present? && @log.unresolved %> <%= govuk_inset_text(text: question.unresolved_hint_text) if question.unresolved_hint_text.present? && @log.unresolved %>

1
config/initializers/date_formats.rb

@ -2,6 +2,7 @@ Time::DATE_FORMATS[:govuk_date] = "%-d %B %Y"
Time::DATE_FORMATS[:govuk_date_short_month] = "%-d %b %Y" Time::DATE_FORMATS[:govuk_date_short_month] = "%-d %b %Y"
Date::DATE_FORMATS[:govuk_date] = "%-d %B %Y" Date::DATE_FORMATS[:govuk_date] = "%-d %B %Y"
Date::DATE_FORMATS[:govuk_date_short_month] = "%-d %b %Y" Date::DATE_FORMATS[:govuk_date_short_month] = "%-d %b %Y"
Date::DATE_FORMATS[:govuk_date_number_month] = "%-d %-m %Y"
Time::DATE_FORMATS[:month_and_year] = "%B %Y" Time::DATE_FORMATS[:month_and_year] = "%B %Y"
Date::DATE_FORMATS[:month_and_year] = "%B %Y" Date::DATE_FORMATS[:month_and_year] = "%B %Y"

33
spec/helpers/collection_time_helper_spec.rb

@ -4,13 +4,13 @@ RSpec.describe CollectionTimeHelper do
let(:current_user) { create(:user, :data_coordinator) } let(:current_user) { create(:user, :data_coordinator) }
let(:user) { create(:user, :data_coordinator) } let(:user) { create(:user, :data_coordinator) }
describe "Current collection start year" do
around do |example| around do |example|
Timecop.freeze(now) do Timecop.freeze(now) do
example.run example.run
end end
end end
describe "Current collection start year" do
context "when the date is after 1st of April" do context "when the date is after 1st of April" do
let(:now) { Time.utc(2022, 8, 3) } let(:now) { Time.utc(2022, 8, 3) }
@ -77,4 +77,35 @@ RSpec.describe CollectionTimeHelper do
end end
end end
end end
describe "#date_mid_collection_year_formatted" do
subject(:result) { date_mid_collection_year_formatted(input) }
context "when called with nil" do
let(:input) { nil }
it "returns the current date" do
today = Time.zone.today
expect(result).to eq("#{today.day} #{today.month} #{today.year}")
end
end
context "when called with a date after the first of April" do
calendar_year = 2030
let(:input) { Date.new(calendar_year, 7, 7) }
it "returns the first of September from that year" do
expect(result).to eq("1 9 #{calendar_year}")
end
end
context "when called with a date before April" do
calendar_year = 2040
let(:input) { Date.new(calendar_year, 2, 7) }
it "returns the first of September from the previous year" do
expect(result).to eq("1 9 #{calendar_year - 1}")
end
end
end
end end

Loading…
Cancel
Save