From 971229da4e59340f829001131223390ce9499a3b Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:44:15 +0100 Subject: [PATCH] Make collection_year_radio_options same as side filter options (#2668) --- app/helpers/filters_helper.rb | 10 +++--- spec/helpers/filters_helper_spec.rb | 50 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 5f8488bc9..d8a991b87 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -146,11 +146,11 @@ module FiltersHelper end def collection_year_radio_options - { - current_collection_start_year.to_s => { label: year_combo(current_collection_start_year) }, - previous_collection_start_year.to_s => { label: year_combo(previous_collection_start_year) }, - archived_collection_start_year.to_s => { label: year_combo(archived_collection_start_year) }, - } + options = {} + collection_year_options.map do |year, label| + options[year] = { label: } + end + options end def filters_applied_text(filter_type) diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index a2b658cdf..58c82f0c9 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -527,6 +527,56 @@ RSpec.describe FiltersHelper do end end + describe "#collection_year_radio_options" do + context "with 23/24 as the current collection year" 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/24" }, "2022" => { label: "2022/23" }, "2021" => { label: "2021/22" } + }, + ) + 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_radio_options).to eq( + { + "2023" => { label: "2023/24" }, "2022" => { label: "2022/23" } + }, + ) + end + end + end + + context "with 24/25 as the current collection year" do + before do + allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) + end + + it "has the correct options" do + expect(collection_year_radio_options).to eq( + { + "2024" => { label: "2024/25" }, "2023" => { label: "2023/24" }, "2022" => { label: "2022/23" } + }, + ) + end + end + end + describe "#filters_applied_text" do let(:filter_type) { "lettings_logs" } let(:result) { filters_applied_text(filter_type) }