Browse Source

fixup! CLDC-4115: Ensure form is loaded correctly before testing filters

remove 23/24 tests

make tests no longer year specific
pull/3149/head
Samuel Young 3 weeks ago
parent
commit
cc20d16b7a
  1. 8
      app/helpers/collection_time_helper.rb
  2. 147
      spec/helpers/filters_helper_spec.rb

8
app/helpers/collection_time_helper.rb

@ -54,6 +54,10 @@ module CollectionTimeHelper
current_collection_start_year - 1 current_collection_start_year - 1
end end
def previous_collection_end_year
current_collection_end_year - 1
end
def previous_collection_start_date def previous_collection_start_date
current_collection_start_date - 1.year current_collection_start_date - 1.year
end end
@ -62,6 +66,10 @@ module CollectionTimeHelper
current_collection_start_year - 2 current_collection_start_year - 2
end end
def archived_collection_end_year
current_collection_end_year - 2
end
def previous_collection_new_logs_end_date def previous_collection_new_logs_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date
end end

147
spec/helpers/filters_helper_spec.rb

@ -478,137 +478,100 @@ RSpec.describe FiltersHelper do
end end
describe "#collection_year_options" do describe "#collection_year_options" do
context "with 23/24 as the current collection year" do context "and in crossover period" do
before 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 end
context "and in crossover period" do it "has the correct options" do
before do expect(collection_year_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) {
end 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}",
it "has the correct options" do archived_collection_start_year.to_s => "#{archived_collection_start_year} to #{archived_collection_end_year}",
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
end end
end end
context "with 24/25 as the current collection year" do context "and not in crossover period" do
before 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 end
context "and in crossover period" do it "has the correct options" do
before do expect(collection_year_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) {
end 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}",
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
end end
context "and not in crossover period" do context "with future form use turned on" do
before 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 end
it "has the correct options" do it "includes next year in the options" do
expect(collection_year_options).to eq( 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 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 end
end end
describe "#collection_year_radio_options" do describe "#collection_year_radio_options" do
context "with 23/24 as the current collection year" do context "and in crossover period" do
before 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_radio_options).to eq(
{
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }, "2021" => { label: "2021 to 2022" }
},
)
end
end end
context "and not in crossover period" do it "has the correct options" do
before do expect(collection_year_radio_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) {
end 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}" },
it "has the correct options" do archived_collection_start_year.to_s => { label: "#{archived_collection_start_year} to #{archived_collection_end_year}" },
expect(collection_year_radio_options).to eq( },
{ )
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }
},
)
end
end end
end end
context "with 24/25 as the current collection year" do context "and not in crossover period" do
before 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)
Singleton.__init__(FormHandler)
end end
it "has the correct options" do it "has the correct options" do
expect(collection_year_radio_options).to eq( 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 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
end end

Loading…
Cancel
Save