From cc20d16b7aeb27dddbd8a46dec1e0edffbc4f502 Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Wed, 28 Jan 2026 14:48:04 +0000 Subject: [PATCH] fixup! CLDC-4115: Ensure form is loaded correctly before testing filters remove 23/24 tests make tests no longer year specific --- app/helpers/collection_time_helper.rb | 8 ++ spec/helpers/filters_helper_spec.rb | 147 ++++++++++---------------- 2 files changed, 63 insertions(+), 92 deletions(-) diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 1d35c17e9..03fe556a2 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -54,6 +54,10 @@ module CollectionTimeHelper current_collection_start_year - 1 end + def previous_collection_end_year + current_collection_end_year - 1 + end + def previous_collection_start_date current_collection_start_date - 1.year end @@ -62,6 +66,10 @@ module CollectionTimeHelper current_collection_start_year - 2 end + def archived_collection_end_year + current_collection_end_year - 2 + end + def previous_collection_new_logs_end_date FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date end diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index e3e4b0c8a..952a45ffc 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -478,137 +478,100 @@ RSpec.describe FiltersHelper do end describe "#collection_year_options" do - context "with 23/24 as the current collection year" do + context "and in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) end - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2023" => "2023 to 2024", "2022" => "2022 to 2023", "2021" => "2021 to 2022" - }, - ) - end - end - - context "and not in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2023" => "2023 to 2024", "2022" => "2022 to 2023" - }, - ) - end + it "has the correct options" do + expect(collection_year_options).to eq( + { + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", + archived_collection_start_year.to_s => "#{archived_collection_start_year} to #{archived_collection_end_year}", + }, + ) end end - context "with 24/25 as the current collection year" do + context "and not in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) end - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2024" => "2024 to 2025", "2023" => "2023 to 2024", "2022" => "2022 to 2023" - }, - ) - end + it "has the correct options" do + expect(collection_year_options).to eq( + { + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", + }, + ) end - context "and not in crossover period" do + context "with future form use turned on" do before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) end - it "has the correct options" do + it "includes next year in the options" do expect(collection_year_options).to eq( { - "2024" => "2024 to 2025", "2023" => "2023 to 2024" + next_collection_start_year.to_s => "#{next_collection_start_year} to #{next_collection_end_year}", + current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}", + previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}", }, ) end - - context "with future form use turned on" do - before do - allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) - end - - it "includes next year in the options" do - expect(collection_year_options).to eq( - { - "2025" => "2025 to 2026", "2024" => "2024 to 2025", "2023" => "2023 to 2024" - }, - ) - end - end end end end describe "#collection_year_radio_options" do - context "with 23/24 as the current collection year" do + context "and in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) - end - - context "and in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) - end - - it "has the correct options" do - expect(collection_year_radio_options).to eq( - { - "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }, "2021" => { label: "2021 to 2022" } - }, - ) - end + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) end - context "and not in crossover period" do - before do - allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) - end - - it "has the correct options" do - expect(collection_year_radio_options).to eq( - { - "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" } - }, - ) - end + it "has the correct options" do + expect(collection_year_radio_options).to eq( + { + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, + archived_collection_start_year.to_s => { label: "#{archived_collection_start_year} to #{archived_collection_end_year}" }, + }, + ) end end - context "with 24/25 as the current collection year" do + context "and not in crossover period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) - Singleton.__init__(FormHandler) + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) end it "has the correct options" do expect(collection_year_radio_options).to eq( { - "2024" => { label: "2024 to 2025" }, "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" } + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, }, ) end + + context "with future form use turned on" do + before do + allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true) + end + + it "includes next year in the options" do + expect(collection_year_radio_options).to eq( + { + next_collection_start_year.to_s => { label: "#{next_collection_start_year} to #{next_collection_end_year}" }, + current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" }, + previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" }, + }, + ) + end + end end end