Browse Source

Merge branch 'main' into CLDC-4203-update-bulk-upload-field-numbers

pull/3189/head
samyou-softwire 4 weeks ago
parent
commit
21e6c6e458
  1. 9
      app/helpers/collection_time_helper.rb
  2. 9
      app/helpers/form_page_helper.rb
  3. 1
      app/models/form/lettings/questions/gender_same_as_sex.rb
  4. 13
      app/models/form/lettings/questions/tenancy_start_date.rb
  5. 5
      app/models/form/question.rb
  6. 2
      app/models/validations/soft_validations.rb
  7. 2
      app/views/form/_date_question.html.erb
  8. 3
      config/locales/forms/2026/lettings/setup.en.yml
  9. 16
      spec/models/form/lettings/questions/gender_same_as_sex_spec.rb

9
app/helpers/collection_time_helper.rb

@ -16,10 +16,13 @@ module CollectionTimeHelper
Time.zone.local(collection_start_year_for_date(date), 4, 1) Time.zone.local(collection_start_year_for_date(date), 4, 1)
end end
def date_mid_collection_year_formatted(date) def date_mid_collection_year(date)
relevant_year = date.nil? ? current_collection_start_year : collection_start_year_for_date(date) relevant_year = date.nil? ? current_collection_start_year : collection_start_year_for_date(date)
example_date = Date.new(relevant_year, 9, 13) Date.new(relevant_year, 9, 13)
example_date.to_formatted_s(:govuk_date_number_month) end
def date_mid_collection_year_formatted(date)
date_mid_collection_year(date).to_formatted_s(:govuk_date_number_month)
end end
def current_collection_start_date def current_collection_start_date

9
app/helpers/form_page_helper.rb

@ -1,4 +1,6 @@
module FormPageHelper module FormPageHelper
include CollectionTimeHelper
def action_href(log, page_id, referrer = "check_answers") def action_href(log, page_id, referrer = "check_answers")
send("#{log.log_type}_#{page_id}_path", log, referrer:) send("#{log.log_type}_#{page_id}_path", log, referrer:)
end end
@ -46,4 +48,11 @@ module FormPageHelper
page.skip_href(log) || send(log.form.next_page_redirect_path(page, log, current_user, ignore_answered: true), log) page.skip_href(log) || send(log.form.next_page_redirect_path(page, log, current_user, ignore_answered: true), log)
end end
end end
def date_hint(question, log)
[
question.hint_text.presence,
question.date_example_override(log) || "For example, #{date_mid_collection_year_formatted(log.startdate).tr(' ', '/')}",
].compact.join("<br><br>").html_safe
end
end end

1
app/models/form/lettings/questions/gender_same_as_sex.rb

@ -7,6 +7,7 @@ class Form::Lettings::Questions::GenderSameAsSex < ::Form::Question
@conditional_for = { "gender_description#{person_index}" => [2] } @conditional_for = { "gender_description#{person_index}" => [2] }
@person_index = person_index @person_index = person_index
@question_number = question_number @question_number = question_number
@inferred_check_answers_value = [{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }]
end end
def answer_options def answer_options

13
app/models/form/lettings/questions/tenancy_start_date.rb

@ -1,4 +1,6 @@
class Form::Lettings::Questions::TenancyStartDate < ::Form::Question class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
include CollectionTimeHelper
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "startdate" @id = "startdate"
@ -7,5 +9,16 @@ class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] if form.start_date.present? @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] if form.start_date.present?
end end
def date_example_override(log)
return unless form.start_year_2026_or_later?
example_date =
[date_mid_collection_year(log.startdate), Time.zone.today + 7]
.min
.to_formatted_s(:govuk_date_number_month)
.tr(" ", "/")
I18n.t("forms.#{form.start_date.year}.#{copy_key}.example", default: "", example_date:)
end
QUESTION_NUMBER_FROM_YEAR = { 2023 => 5, 2024 => 7 }.freeze QUESTION_NUMBER_FROM_YEAR = { 2023 => 5, 2024 => 7 }.freeze
end end

5
app/models/form/question.rb

@ -299,6 +299,11 @@ class Form::Question
answer_options.keys.reject { |x| x.match(/divider/) } answer_options.keys.reject { |x| x.match(/divider/) }
end end
# used by date questions that need bespoke formatting for the example date
def date_example_override(_log)
nil
end
private private
def selected_answer_option_is_derived?(log) def selected_answer_option_is_derived?(log)

2
app/models/validations/soft_validations.rb

@ -329,6 +329,8 @@ private
end end
def at_least_one_person_working_situation_is_illness? def at_least_one_person_working_situation_is_illness?
return if hhmemb.present? && hhmemb > 8
person_count = hhmemb || 8 person_count = hhmemb || 8
(1..person_count).any? { |n| public_send("ecstat#{n}") == 8 } (1..person_count).any? { |n| public_send("ecstat#{n}") == 8 }

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

@ -6,7 +6,7 @@
question_id: question.id, question_id: question.id,
legend: { text: legend[:text], size: legend[:size], caption: caption(caption_text, page_header, conditional) }, legend: { text: legend[:text], size: legend[:size], caption: caption(caption_text, page_header, conditional) },
resource_type: @log.log_type, resource_type: @log.log_type,
hint: (question.hint_text.blank? ? "" : (question.hint_text.html_safe + "</br></br>".html_safe)) + "For example, #{date_mid_collection_year_formatted(@log.startdate).tr(' ', '/')}", hint: date_hint(question, @log),
f:, f:,
} %> } %>

3
config/locales/forms/2026/lettings/setup.en.yml

@ -63,7 +63,8 @@ en:
page_header: "" page_header: ""
check_answer_label: "Tenancy start date" check_answer_label: "Tenancy start date"
check_answer_prompt: "" check_answer_prompt: ""
hint_text: "" hint_text: "The tenancy start date can be up to 14 days from today. If your tenancy starts more than 14 days into the future, please wait until you are within 14 days of the start date before submitting your log. <br><br>For example, if you’re answering this question on 1 April, you can enter a tenancy start date up to and including 15 April."
example: "Enter the date in the format DD/MM/YYYY, for example %{example_date}."
question_text: "What is the tenancy start date?" question_text: "What is the tenancy start date?"
rent_type: rent_type:

16
spec/models/form/lettings/questions/gender_same_as_sex_spec.rb

@ -42,7 +42,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -72,7 +72,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -102,7 +102,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -132,7 +132,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -162,7 +162,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -192,7 +192,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -222,7 +222,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do
@ -252,7 +252,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to be_nil expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }])
end end
it "has the correct question number" do it "has the correct question number" do

Loading…
Cancel
Save