Browse Source

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

pull/1293/head
Arthur Campbell 3 years ago
parent
commit
72db368fe6
  1. 12
      app/helpers/question_view_helper.rb
  2. 2
      app/views/form/_date_question.html.erb
  3. 48
      spec/helpers/question_view_helper_spec.rb

12
app/helpers/question_view_helper.rb

@ -13,6 +13,18 @@ module QuestionViewHelper
}
end
def example_date_in_tax_year_of(date)
return Time.zone.today if date.nil?
year = if date.month > 4 || (date.month == 4 && date.day > 5)
date.year
else
date.year - 1
end
Date.new(year, 9, 1)
end
private
def label_size(page_header, conditional)

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

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

48
spec/helpers/question_view_helper_spec.rb

@ -76,4 +76,52 @@ RSpec.describe QuestionViewHelper do
end
end
end
describe "#example_date_in_tax_year_of" do
subject(:result) { example_date_in_tax_year_of(input) }
context "when called with nil" do
let(:input) { nil }
it "returns the current date" do
expect(result).to eq(Time.zone.today)
end
end
context "when called with a date after 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(Date.new(calendar_year, 9, 1))
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(Date.new(calendar_year - 1, 9, 1))
end
end
context "when called with a date in April after the fifth" do
calendar_year = 2050
let(:input) { Date.new(calendar_year, 4, 7) }
it "returns the first of September from that year" do
expect(result).to eq(Date.new(calendar_year, 9, 1))
end
end
context "when called with a date in April before the sixth" do
calendar_year = 2060
let(:input) { Date.new(calendar_year, 4, 4) }
it "returns the first of September from the previous year" do
expect(result).to eq(Date.new(calendar_year - 1, 9, 1))
end
end
end
end

Loading…
Cancel
Save