diff --git a/app/models/recruitment_cycle.rb b/app/models/recruitment_cycle.rb index 6dece42a915..6777a33db9b 100644 --- a/app/models/recruitment_cycle.rb +++ b/app/models/recruitment_cycle.rb @@ -1,17 +1,15 @@ module RecruitmentCycle - CYCLES = { - '2024' => '2023 to 2024', - '2023' => '2022 to 2023', - '2022' => '2021 to 2022', - '2021' => '2020 to 2021', - '2020' => '2019 to 2020', - }.freeze - def self.cycle_string(year) - cycle = CYCLES.fetch(year.to_s) + cycle = cycle_strings.fetch(year.to_s) current_year.to_s == year.to_s ? "#{cycle} - current" : cycle end + def self.cycle_strings(upto = current_year) + 2020.upto(upto.to_i).index_with do |year| + "#{year - 1} to #{year}" + end.stringify_keys + end + def self.real_current_year CycleTimetable.real_current_year end diff --git a/app/models/support_interface/applications_filter.rb b/app/models/support_interface/applications_filter.rb index bd399e1fad4..f2ccb28491c 100644 --- a/app/models/support_interface/applications_filter.rb +++ b/app/models/support_interface/applications_filter.rb @@ -76,9 +76,7 @@ def filters private def year_filter - cycle_options = RecruitmentCycle::CYCLES.filter_map do |year, _| - next if year.to_i > RecruitmentCycle.current_year - + cycle_options = RecruitmentCycle.cycle_strings(RecruitmentCycle.current_year).map do |year, _| { value: year, label: RecruitmentCycle.cycle_string(year), diff --git a/app/views/support_interface/performance/service_performance_dashboard.html.erb b/app/views/support_interface/performance/service_performance_dashboard.html.erb index 18d1c4debbe..f9455327bcf 100644 --- a/app/views/support_interface/performance/service_performance_dashboard.html.erb +++ b/app/views/support_interface/performance/service_performance_dashboard.html.erb @@ -7,7 +7,7 @@ <%= govuk_link_to 'View in large screen mode', '?screen=1' %>

- <% year_choices = RecruitmentCycle::CYCLES.map do |year, label| %> + <% year_choices = RecruitmentCycle.cycle_strings(RecruitmentCycle.current_year).map do |year, label| %> <% { name: label, url: "?year=#{year}&screen=#{params[:screen] || 0}", current: params[:year] == year } %> <% end %> diff --git a/spec/models/recruitment_cycle_spec.rb b/spec/models/recruitment_cycle_spec.rb index 3d6ccbed0ee..c84f1c3a5c9 100644 --- a/spec/models/recruitment_cycle_spec.rb +++ b/spec/models/recruitment_cycle_spec.rb @@ -1,6 +1,47 @@ require 'rails_helper' RSpec.describe RecruitmentCycle, time: CycleTimetableHelper.mid_cycle(2023) do + describe '.cycle_strings' do + it 'returns an empty hash when start year is before 2020' do + expect(described_class.cycle_strings(2000)).to eq({}) + end + + it 'returns the cycle strings up to one year from current_year' do + expect(described_class.cycle_strings).to eq( + { '2020' => '2019 to 2020', + '2021' => '2020 to 2021', + '2022' => '2021 to 2022', + '2023' => '2022 to 2023' }, + ) + end + + it 'returns the cycle strings up to the arg year' do + expect(described_class.cycle_strings(2024)).to eq( + { '2020' => '2019 to 2020', + '2021' => '2020 to 2021', + '2022' => '2021 to 2022', + '2023' => '2022 to 2023', + '2024' => '2023 to 2024' }, + ) + end + + context 'when cycle switcher is after apply opens' do + before do + SiteSetting.set(name: 'cycle_schedule', value: 'today_is_after_apply_opens') + end + + it 'returns the cycle strings up to the arg year' do + expect(described_class.cycle_strings).to eq( + { '2020' => '2019 to 2020', + '2021' => '2020 to 2021', + '2022' => '2021 to 2022', + '2023' => '2022 to 2023', + '2024' => '2023 to 2024' }, + ) + end + end + end + describe '.cycle_string' do it 'throws an error when a cycle does not exist for the specified year' do expect { described_class.cycle_string(2000) } diff --git a/spec/system/provider_interface/provider_user_exports_applications_to_csv_spec.rb b/spec/system/provider_interface/provider_user_exports_applications_to_csv_spec.rb index b19922db4d1..43f62de82ee 100644 --- a/spec/system/provider_interface/provider_user_exports_applications_to_csv_spec.rb +++ b/spec/system/provider_interface/provider_user_exports_applications_to_csv_spec.rb @@ -79,7 +79,7 @@ def then_i_get_validation_errors end def and_i_fill_out_the_form_for_applications_this_year_of_any_status_for_the_first_provider - check RecruitmentCycle::CYCLES[RecruitmentCycle.current_year.to_s] + check RecruitmentCycle.cycle_strings(RecruitmentCycle.current_year) choose 'All statuses' check @current_provider_user.providers.first.name @@ -98,7 +98,7 @@ def then_the_downloaded_file_includes_applications_this_year_of_any_status_for_t def and_i_fill_out_the_form_for_applications_all_years_of_deferred_and_accepted_offers_for_the_first_provider RecruitmentCycle.years_visible_to_providers.each do |year| - check RecruitmentCycle::CYCLES[year.to_s] + check RecruitmentCycle.cycle_strings(year) end choose 'Specific statuses' check 'Deferred'