From 33a07392dcbfd530f21d860092c642a8caa3d64f Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Tue, 2 Jan 2024 16:36:04 +0000 Subject: [PATCH 1/2] CLDC-3076: Make example dates consistent (#2107) * CLDC-3076: Make example dates consistent * Use example date even when some hint text provided already * Temp remove some date restrictions * Update to 2 line breaks * Revert "Temp remove some date restrictions" This reverts commit cd7f18f9f10957be0cbabee7665c0abe4239acb6. --- app/helpers/collection_time_helper.rb | 3 ++- app/views/form/_date_question.html.erb | 2 +- spec/helpers/collection_time_helper_spec.rb | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 34426bab2..ea7601c70 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -13,7 +13,8 @@ module CollectionTimeHelper end def date_mid_collection_year_formatted(date) - example_date = date.nil? ? Time.zone.today : collection_start_date(date).to_date + 5.months + relevant_year = date.nil? ? current_collection_start_year : collection_start_year_for_date(date) + example_date = Date.new(relevant_year, 9, 13) example_date.to_formatted_s(:govuk_date_number_month) end diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index c84d60d0e..9de5b8f2d 100644 --- a/app/views/form/_date_question.html.erb +++ b/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, #{date_mid_collection_year_formatted(lettings_log.startdate)}" }, + hint: { text: (question.hint_text.nil? ? "" : (question.hint_text.html_safe + "

".html_safe)) + "For example, #{date_mid_collection_year_formatted(lettings_log.startdate)}" }, width: 20, **stimulus_html_attributes(question) do %> <%= govuk_inset_text(text: question.unresolved_hint_text) if question.unresolved_hint_text.present? && @log.unresolved %> diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index e9ec52292..3eef01b5e 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -85,9 +85,9 @@ RSpec.describe CollectionTimeHelper do 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}") + it "returns the 13th of September in the current collection year" do + year = current_collection_start_year + expect(result).to eq("13 9 #{year}") end end @@ -95,8 +95,8 @@ RSpec.describe CollectionTimeHelper 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}") + it "returns the 13th of September from that year" do + expect(result).to eq("13 9 #{calendar_year}") end end @@ -104,8 +104,8 @@ RSpec.describe CollectionTimeHelper 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}") + it "returns the 13th of September from the previous year" do + expect(result).to eq("13 9 #{calendar_year - 1}") end end end From a9eeddebfcf6c61a8f245a8858fb5a18bb9c289b Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:51:01 +0000 Subject: [PATCH 2/2] Fix lettings log accessor in date question (#2117) * Fix lettings log accessor in date question * Remove hardcoded date example from mrcdate question (#2118) --------- Co-authored-by: Rachael Booth --- app/models/form/lettings/questions/mrcdate.rb | 1 - app/views/form/_date_question.html.erb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/form/lettings/questions/mrcdate.rb b/app/models/form/lettings/questions/mrcdate.rb index cadcd3a7a..09176dca6 100644 --- a/app/models/form/lettings/questions/mrcdate.rb +++ b/app/models/form/lettings/questions/mrcdate.rb @@ -6,7 +6,6 @@ class Form::Lettings::Questions::Mrcdate < ::Form::Question @header = "When were the repairs completed?" @type = "date" @check_answers_card_number = 0 - @hint_text = "For example, 27 3 2021." @question_number = 24 end end diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index 9de5b8f2d..1be21d212 100644 --- a/app/views/form/_date_question.html.erb +++ b/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.nil? ? "" : (question.hint_text.html_safe + "

".html_safe)) + "For example, #{date_mid_collection_year_formatted(lettings_log.startdate)}" }, + hint: { text: (question.hint_text.nil? ? "" : (question.hint_text.html_safe + "

".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate)}" }, width: 20, **stimulus_html_attributes(question) do %> <%= govuk_inset_text(text: question.unresolved_hint_text) if question.unresolved_hint_text.present? && @log.unresolved %>