From e2e43d93ea663e508d52f391f3fb2a1fdb820a7e Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 22 Jul 2024 09:31:18 +0100 Subject: [PATCH] Make sure archived filters are removed after crossover --- app/helpers/filters_helper.rb | 9 ++++++-- spec/helpers/filters_helper_spec.rb | 32 +++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index f60946c74..38c15b82b 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -95,11 +95,16 @@ module FiltersHelper end def collection_year_options - { + years = { current_collection_start_year.to_s => year_combo(current_collection_start_year), previous_collection_start_year.to_s => year_combo(previous_collection_start_year), - archived_collection_start_year.to_s => year_combo(archived_collection_start_year), } + + if FormHandler.instance.in_crossover_period? + return years.merge({ archived_collection_start_year.to_s => year_combo(archived_collection_start_year) }) + end + + years end def collection_year_radio_options diff --git a/spec/helpers/filters_helper_spec.rb b/spec/helpers/filters_helper_spec.rb index fb7bda18e..f04157521 100644 --- a/spec/helpers/filters_helper_spec.rb +++ b/spec/helpers/filters_helper_spec.rb @@ -245,12 +245,32 @@ RSpec.describe FiltersHelper do allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) end - it "has the correct options" do - expect(collection_year_options).to eq( - { - "2023" => "2023/24", "2022" => "2022/23", "2021" => "2021/22" - }, - ) + 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/24", "2022" => "2022/23", "2021" => "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_options).to eq( + { + "2023" => "2023/24", "2022" => "2022/23" + }, + ) + end end end