Browse Source

Merge branch 'main' into CLDC-4202-update-question-numbers

# Conflicts:
#	app/models/form/lettings/questions/tenancy_start_date.rb
pull/3169/head
samyou-softwire 4 weeks ago
parent
commit
5cb9a76901
  1. 20
      app/components/create_log_actions_component.html.erb
  2. 17
      app/components/create_log_actions_component.rb
  3. 28
      app/controllers/test_data_controller.rb
  4. 9
      app/helpers/collection_time_helper.rb
  5. 9
      app/helpers/form_page_helper.rb
  6. 1
      app/models/form/lettings/questions/gender_same_as_sex.rb
  7. 13
      app/models/form/lettings/questions/tenancy_start_date.rb
  8. 5
      app/models/form/question.rb
  9. 2
      app/models/validations/soft_validations.rb
  10. 2
      app/services/feature_toggle.rb
  11. 2
      app/views/form/_date_question.html.erb
  12. 3
      config/locales/forms/2026/lettings/setup.en.yml
  13. 4
      config/routes.rb
  14. 16
      spec/models/form/lettings/questions/gender_same_as_sex_spec.rb

20
app/components/create_log_actions_component.html.erb

@ -14,17 +14,33 @@
<span class="govuk-body govuk-body-s">These tools can only be seen and used in testing environments.</span>
<div>
<%= govuk_button_link_to create_test_log_href, class: "govuk-button" do %>
New test log
New <%= current_collection_year_label %> test log
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
</svg>
<% end %>
<% if FeatureToggle.allow_future_form_use? %>
<%= govuk_button_link_to create_next_year_test_log_href, class: "govuk-button" do %>
New <%= next_collection_year_label %> test log
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
</svg>
<% end %>
<% end %>
<%= govuk_button_link_to create_setup_test_log_href, class: "govuk-button" do %>
New test log (setup only)
New <%= current_collection_year_label %> test log (setup only)
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
</svg>
<% end %>
<% if FeatureToggle.allow_future_form_use? %>
<%= govuk_button_link_to create_next_year_setup_test_log_href, class: "govuk-button" do %>
New <%= next_collection_year_label %> test log (setup only)
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path>
</svg>
<% end %>
<% end %>
<%= govuk_button_link_to create_test_bulk_upload_href(2025), class: "govuk-button govuk-button--secondary" do %>
25/26 BU test file
<svg class="govuk-button__start-icon bi bi-download" xmlns="http://www.w3.org/2000/svg" width="18" height="19" fill="currentColor" viewBox="0 0 16 16" stroke="currentColor" stroke-width="1.4">

17
app/components/create_log_actions_component.rb

@ -1,5 +1,6 @@
class CreateLogActionsComponent < ViewComponent::Base
include Rails.application.routes.url_helpers
include CollectionTimeHelper
attr_reader :bulk_upload, :user, :log_type
@ -38,10 +39,26 @@ class CreateLogActionsComponent < ViewComponent::Base
send("create_test_#{log_type}_log_path")
end
def create_next_year_test_log_href
send("create_next_year_test_#{log_type}_log_path")
end
def create_setup_test_log_href
send("create_setup_test_#{log_type}_log_path")
end
def create_next_year_setup_test_log_href
send("create_next_year_setup_test_#{log_type}_log_path")
end
def current_collection_year_label
"#{current_collection_start_year - 2000}/#{current_collection_end_year - 2000}"
end
def next_collection_year_label
"#{next_collection_start_year - 2000}/#{next_collection_end_year - 2000}"
end
def create_test_bulk_upload_href(year)
send("create_#{year}_test_#{log_type}_bulk_upload_path")
end

28
app/controllers/test_data_controller.rb

@ -10,6 +10,13 @@ class TestDataController < ApplicationController
redirect_to lettings_log_path(log)
end
def create_next_year_test_lettings_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA", manual_address_entry_selected: false, startdate: generate_different_date_within_collection_year(Time.zone.local(next_collection_start_year, 4, 1)))
redirect_to lettings_log_path(log)
end
def create_setup_test_lettings_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
@ -17,6 +24,13 @@ class TestDataController < ApplicationController
redirect_to lettings_log_path(log)
end
def create_next_year_setup_test_lettings_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
log = FactoryBot.create(:lettings_log, :setup_completed, assigned_to: current_user, manual_address_entry_selected: false, startdate: generate_different_date_within_collection_year(Time.zone.local(next_collection_start_year, 4, 1)))
redirect_to lettings_log_path(log)
end
%w[2025 2026].each do |year|
define_method("create_#{year}_test_lettings_bulk_upload") do
return render_not_found unless FeatureToggle.create_test_logs_enabled?
@ -47,6 +61,13 @@ class TestDataController < ApplicationController
redirect_to sales_log_path(log)
end
def create_next_year_test_sales_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, manual_address_entry_selected: false, saledate: generate_different_date_within_collection_year(Time.zone.local(next_collection_start_year, 4, 1)))
redirect_to sales_log_path(log)
end
def create_setup_test_sales_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
@ -54,6 +75,13 @@ class TestDataController < ApplicationController
redirect_to sales_log_path(log)
end
def create_next_year_setup_test_sales_log
return render_not_found unless FeatureToggle.create_test_logs_enabled?
log = FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: current_user, manual_address_entry_selected: false, saledate: generate_different_date_within_collection_year(Time.zone.local(next_collection_start_year, 4, 1)))
redirect_to sales_log_path(log)
end
%w[2025 2026].each do |year|
define_method("create_#{year}_test_sales_bulk_upload") do
return render_not_found unless FeatureToggle.create_test_logs_enabled?

9
app/helpers/collection_time_helper.rb

@ -16,10 +16,13 @@ module CollectionTimeHelper
Time.zone.local(collection_start_year_for_date(date), 4, 1)
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)
example_date = Date.new(relevant_year, 9, 13)
example_date.to_formatted_s(:govuk_date_number_month)
Date.new(relevant_year, 9, 13)
end
def date_mid_collection_year_formatted(date)
date_mid_collection_year(date).to_formatted_s(:govuk_date_number_month)
end
def current_collection_start_date

9
app/helpers/form_page_helper.rb

@ -1,4 +1,6 @@
module FormPageHelper
include CollectionTimeHelper
def action_href(log, page_id, referrer = "check_answers")
send("#{log.log_type}_#{page_id}_path", log, referrer:)
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)
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

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] }
@person_index = person_index
@question_number = question_number
@inferred_check_answers_value = [{ "condition" => { "gender_same_as_sex#{person_index}" => 2 }, "value" => "No" }]
end
def answer_options

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

@ -1,4 +1,6 @@
class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
include CollectionTimeHelper
def initialize(id, hsh, page)
super
@id = "startdate"
@ -7,5 +9,16 @@ class Form::Lettings::Questions::TenancyStartDate < ::Form::Question
@question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR) if form.start_date.present?
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, 2025 => 7, 2026 => 7 }.freeze
end

5
app/models/form/question.rb

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

2
app/models/validations/soft_validations.rb

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

2
app/services/feature_toggle.rb

@ -28,7 +28,7 @@ class FeatureToggle
end
def self.create_test_logs_enabled?
Rails.env.development? || Rails.env.review?
Rails.env.development? || Rails.env.review? || Rails.env.staging?
end
def self.sales_export_enabled?

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

@ -6,7 +6,7 @@
question_id: question.id,
legend: { text: legend[:text], size: legend[:size], caption: caption(caption_text, page_header, conditional) },
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:,
} %>

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

@ -63,7 +63,8 @@ en:
page_header: ""
check_answer_label: "Tenancy start date"
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?"
rent_type:

4
config/routes.rb

@ -405,11 +405,15 @@ Rails.application.routes.draw do
if FeatureToggle.create_test_logs_enabled?
get "create-test-lettings-log", to: "test_data#create_test_lettings_log"
get "create-next-year-test-lettings-log", to: "test_data#create_next_year_test_lettings_log"
get "create-setup-test-lettings-log", to: "test_data#create_setup_test_lettings_log"
get "create-next-year-setup-test-lettings-log", to: "test_data#create_next_year_setup_test_lettings_log"
get "create-2025-test-lettings-bulk-upload", to: "test_data#create_2025_test_lettings_bulk_upload"
get "create-2026-test-lettings-bulk-upload", to: "test_data#create_2026_test_lettings_bulk_upload"
get "create-test-sales-log", to: "test_data#create_test_sales_log"
get "create-next-year-test-sales-log", to: "test_data#create_next_year_test_sales_log"
get "create-setup-test-sales-log", to: "test_data#create_setup_test_sales_log"
get "create-next-year-setup-test-sales-log", to: "test_data#create_next_year_setup_test_sales_log"
get "create-2025-test-sales-bulk-upload", to: "test_data#create_2025_test_sales_bulk_upload"
get "create-2026-test-sales-bulk-upload", to: "test_data#create_2026_test_sales_bulk_upload"
end

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
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
it "has the correct question number" do
@ -72,7 +72,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -102,7 +102,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -132,7 +132,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -162,7 +162,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -192,7 +192,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -222,7 +222,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do
@ -252,7 +252,7 @@ RSpec.describe Form::Lettings::Questions::GenderSameAsSex, type: :model do
end
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
it "has the correct question number" do

Loading…
Cancel
Save