From 400ca127c9c55ebdaa4f260f9da52af8fcf6c829 Mon Sep 17 00:00:00 2001 From: Tomas D'Stefano Date: Tue, 9 Jul 2024 10:11:56 +0100 Subject: [PATCH] Point to A level list from description tag when A level is present When there is at least one A level requirement we should be pointing to the list step and not the add more requirements page --- app/decorators/course_decorator.rb | 16 +++++++ .../courses/_description_content.html.erb | 6 +-- spec/decorators/course_decorator_spec.rb | 44 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/app/decorators/course_decorator.rb b/app/decorators/course_decorator.rb index ed2d25ea67..b31ea4a6fe 100644 --- a/app/decorators/course_decorator.rb +++ b/app/decorators/course_decorator.rb @@ -47,6 +47,22 @@ def open_or_closed_for_applications object.open_for_applications? ? 'Open' : 'Closed' end + def a_level_change_path + if object.a_level_subject_requirements.present? + h.publish_provider_recruitment_cycle_course_a_levels_add_a_level_to_a_list_path( + object.provider.provider_code, + object.provider.recruitment_cycle_year, + object.course_code + ) + else + h.publish_provider_recruitment_cycle_course_a_levels_what_a_level_is_required_path( + object.provider.provider_code, + object.provider.recruitment_cycle_year, + object.course_code + ) + end + end + def outcome I18n.t("edit_options.qualifications.#{object.qualification}.label") end diff --git a/app/views/publish/courses/_description_content.html.erb b/app/views/publish/courses/_description_content.html.erb index 3c89ac4efe..34a03aadaf 100644 --- a/app/views/publish/courses/_description_content.html.erb +++ b/app/views/publish/courses/_description_content.html.erb @@ -137,11 +137,7 @@ t("publish.providers.courses.description_content.a_levels_label"), (render ALevelRowComponent.new(course:, errors: @errors)), %w[a_level_subject_requirements accept_pending_a_level accept_a_level_equivalency], - action_path: publish_provider_recruitment_cycle_course_a_levels_what_a_level_is_required_path( - @provider.provider_code, - @provider.recruitment_cycle_year, - course.course_code - ), + action_path: course.a_level_change_path, action_visually_hidden_text: "A levels", render_errors: false ) %> diff --git a/spec/decorators/course_decorator_spec.rb b/spec/decorators/course_decorator_spec.rb index ccfb60fc63..8a71a668b1 100644 --- a/spec/decorators/course_decorator_spec.rb +++ b/spec/decorators/course_decorator_spec.rb @@ -3,6 +3,8 @@ require 'rails_helper' describe CourseDecorator do + include Rails.application.routes.url_helpers + let(:current_recruitment_cycle) { build_stubbed(:recruitment_cycle) } let(:next_recruitment_cycle) { build_stubbed(:recruitment_cycle, :next) } let(:provider) { build_stubbed(:provider, recruitment_cycle: current_recruitment_cycle) } @@ -957,6 +959,48 @@ end end + describe '#a_level_change_path' do + subject(:a_level_change_path) { course.decorate.a_level_change_path } + + context 'when course does not have an A level subject requirement' do + let(:course) do + build( + :course, + a_level_subject_requirements: [] + ) + end + + it 'returns the first page of A levels' do + expect(a_level_change_path).to eq( + publish_provider_recruitment_cycle_course_a_levels_what_a_level_is_required_path( + course.provider.provider_code, + course.provider.recruitment_cycle_year, + course.course_code + ) + ) + end + end + + context 'when course has at least one A level subject requirement' do + let(:course) do + build( + :course, + :with_a_level_requirements + ) + end + + it 'returns the A level list page' do + expect(a_level_change_path).to eq( + publish_provider_recruitment_cycle_course_a_levels_add_a_level_to_a_list_path( + course.provider.provider_code, + course.provider.recruitment_cycle_year, + course.course_code + ) + ) + end + end + end + describe '#financial_incentive_details' do subject { course.decorate.financial_incentive_details }