diff --git a/app/components/find/courses/about_schools_component/view.html.erb b/app/components/find/courses/about_schools_component/view.html.erb index 438feac8d3..1809100f21 100644 --- a/app/components/find/courses/about_schools_component/view.html.erb +++ b/app/components/find/courses/about_schools_component/view.html.erb @@ -1,7 +1,7 @@

Training locations

- <% if course.program_type == "higher_education_programme" && course.provider.provider_code != "B31" %> + <% if show_higher_education_guidance? %> <%= render Find::Utility::AdviceComponent::View.new(title: "Where you will train") do %>

You’ll be placed in schools for most of your course. Your school placements will be within commuting distance.

@@ -10,7 +10,7 @@

Universities can work with over 100 potential placement schools. Most will be within 10 miles of the university, but sometimes they can cover a wider area, especially outside of cities.

<% end %> - <% elsif course.program_type == "scitt_programme" && course.provider.provider_code != "E65" %> + <% elsif show_scitt_guidance? %> <%= render Find::Utility::AdviceComponent::View.new(title: "Where you will train") do %>

You’ll be placed in different schools during your training. You can’t pick which schools you want to be in, but your training provider will place you in schools you can travel to.

<% end %> diff --git a/app/components/find/courses/about_schools_component/view.rb b/app/components/find/courses/about_schools_component/view.rb index 8f45d34e21..bb6c95512d 100644 --- a/app/components/find/courses/about_schools_component/view.rb +++ b/app/components/find/courses/about_schools_component/view.rb @@ -21,11 +21,28 @@ def initialize(course) def render? published_how_school_placements_work.present? || - program_type == 'higher_education_programme' || - program_type == 'scitt_programme' || + program_type.in?(%w[higher_education_programme scitt_programme]) || study_sites.any? || site_statuses.map(&:site).uniq.many? || preview?(params) end + + def show_higher_education_guidance? + return false unless course.higher_education_programme? + + course_information_config.show_placement_guidance?(:program_type) + end + + def show_scitt_guidance? + return false unless course.scitt_programme? + + course_information_config.show_placement_guidance?(:program_type) + end + + private + + def course_information_config + @course_information_config ||= Configs::CourseInformation.new(course) + end end end end diff --git a/app/components/find/courses/contact_details_component/view.html.erb b/app/components/find/courses/contact_details_component/view.html.erb index d14489b8eb..1bd0ecd30a 100644 --- a/app/components/find/courses/contact_details_component/view.html.erb +++ b/app/components/find/courses/contact_details_component/view.html.erb @@ -3,12 +3,10 @@
- - <% if course.provider.provider_code == "U80" %> - <% link = "https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries" %> + <% if show_contact_form_instead_of_email? %>
Contact form
- <%= govuk_link_to link, link %> + <%= govuk_link_to contact_form, contact_form %>
<% else %> <% if course.provider.email.present? %> @@ -33,7 +31,7 @@ <% end %> - <% if course.provider.provider_code == "28T" && course.course_code == "X104" %> + <% if show_address? %>
Address
LSJS diff --git a/app/components/find/courses/contact_details_component/view.rb b/app/components/find/courses/contact_details_component/view.rb index c1da41ac22..eeb74f3872 100644 --- a/app/components/find/courses/contact_details_component/view.rb +++ b/app/components/find/courses/contact_details_component/view.rb @@ -7,11 +7,22 @@ class View < ViewComponent::Base attr_reader :course delegate :provider, to: :course + delegate :contact_form?, :contact_form, :show_address?, to: :course_information_config def initialize(course) super @course = course end + + def show_contact_form_instead_of_email? + contact_form? + end + + private + + def course_information_config + @course_information_config ||= Configs::CourseInformation.new(course) + end end end end diff --git a/app/controllers/publish/courses/course_information_controller.rb b/app/controllers/publish/courses/course_information_controller.rb index 41ab3f2ddf..9859c9ebbf 100644 --- a/app/controllers/publish/courses/course_information_controller.rb +++ b/app/controllers/publish/courses/course_information_controller.rb @@ -59,6 +59,19 @@ def course_enrichment end def param_form_key = :publish_course_information_form + + def course_information + @course_information ||= Configs::CourseInformation.new(@course) + end + + def show_scitt_guidance? + course_information.show_placement_guidance?(:program_type) + end + + def show_universities_guidance? + course_information.show_placement_guidance?(:provider_type) + end + helper_method :show_scitt_guidance?, :show_universities_guidance? end end end diff --git a/app/services/configs/course_information.rb b/app/services/configs/course_information.rb new file mode 100644 index 0000000000..92923b1923 --- /dev/null +++ b/app/services/configs/course_information.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Configs + class CourseInformation + def initialize(course) + @db = Rails.application.config_for(:course_information) + @course = course + end + + def show_placement_guidance?(type) + case type + when :provider_type + subtype = @course.provider.provider_type + when :program_type + subtype = @course.program_type + end + + @db.dig(:placements, type, subtype.to_sym, :except_provider_codes)&.exclude?(@course.provider.provider_code) + end + + def contact_form + @db.fetch(:contact_forms).stringify_keys[@course.provider.provider_code] + end + + def contact_form? + @db.fetch(:contact_forms).stringify_keys.include?(@course.provider.provider_code) + end + + def show_address? + @db.dig(:show_address, :only_provider_codes).include?(@course.provider.provider_code) && + @db.dig(:show_address, :only_course_codes).include?(@course.course_code) + end + end +end diff --git a/app/views/publish/courses/course_information/edit.html.erb b/app/views/publish/courses/course_information/edit.html.erb index 1d26b383da..6462b195f0 100644 --- a/app/views/publish/courses/course_information/edit.html.erb +++ b/app/views/publish/courses/course_information/edit.html.erb @@ -98,14 +98,14 @@
  • how placement schools are selected
  • - <% if @provider.provider_type == 'university' && @provider.provider_code != 'B31' %> + <% if show_universities_guidance? %> <%= govuk_details(summary_text: "See the guidance we show in this section") do %>

    Where you will train

    You’ll be placed in schools for most of your course. Your school placements will be within commuting distance.

    You cannot pick which schools you want to be in, but your university will try to take your journey time into consideration.

    Universities can work with over 100 potential placement schools. Most will be within 10 miles of the university, but sometimes they can cover a wider area, especially outside of cities.

    <% end %> - <% elsif @course.program_type == 'scitt_programme' && @provider.provider_code != 'E65' %> + <% elsif show_scitt_guidance? %> <%= govuk_details(summary_text: "See the guidance we show in this section") do %>

    Where you will train

    You’ll be placed in different schools during your training. You can’t pick which schools you want to be in, but your training provider will place you in schools you can travel to.

    diff --git a/config/course_information.yml b/config/course_information.yml new file mode 100644 index 0000000000..00ecb7b09f --- /dev/null +++ b/config/course_information.yml @@ -0,0 +1,20 @@ +shared: + placements: + provider_type: + university: + except_provider_codes: + - B31 + program_type: + scitt_programme: + except_provider_codes: + - E65 + higher_education_programme: + except_provider_codes: + - B31 + show_address: + only_provider_codes: + - 28T + only_course_codes: + - X104 + contact_forms: + U80: https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries diff --git a/spec/components/find/courses/about_schools_component/view_preview.rb b/spec/components/find/courses/about_schools_component/view_preview.rb index f24b0688ac..5c5c64be0c 100644 --- a/spec/components/find/courses/about_schools_component/view_preview.rb +++ b/spec/components/find/courses/about_schools_component/view_preview.rb @@ -56,6 +56,10 @@ class FakeCourse include ActiveModel::Model attr_accessor(:provider, :published_how_school_placements_work, :placements_heading, :program_type, :study_sites, :site_statuses) + def higher_education_programme? + true + end + def preview_site_statuses site_statuses.sort_by { |status| status.site.location_name } end diff --git a/spec/components/find/courses/contact_details_component/view_spec.rb b/spec/components/find/courses/contact_details_component/view_spec.rb index 684fa22d53..5eb5d6bf25 100644 --- a/spec/components/find/courses/contact_details_component/view_spec.rb +++ b/spec/components/find/courses/contact_details_component/view_spec.rb @@ -76,4 +76,16 @@ expect(result.text).to include('LSJS', '44A Albert Road', 'London', 'NW4 2SJ') end end + + context 'when the provider has a contact form in the config' do + it 'renders the Contact Form instead of Email' do + provider = build(:provider, provider_code: 'U80') + course = build(:course, course_code: 'X104', provider:).decorate + + result = render_inline(described_class.new(course)) + + expect(result.text).to include('Contact form') + expect(result.text).not_to include('Email') + end + end end diff --git a/spec/features/publish/courses/editing_course_information_guidance_spec.rb b/spec/features/publish/courses/editing_course_information_guidance_spec.rb new file mode 100644 index 0000000000..b47098844d --- /dev/null +++ b/spec/features/publish/courses/editing_course_information_guidance_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'Guidance components on course edit page', { can_edit_current_and_next_cycles: false } do + describe 'university providers' do + context 'when provider is excluded via config' do + scenario 'Guidance is not shown' do + given_a_provider_which_does_not_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_not_see_the_guidance_text + end + + def given_a_provider_which_does_not_show_guidance + @provider = create(:provider, :university, provider_code: 'B31') + end + end + + context 'when provider is not excluded via config' do + scenario 'Guidance is shown' do + given_a_provider_which_does_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_see_the_guidance_text + end + + def given_a_provider_which_does_show_guidance + @provider = create(:provider, :university, provider_code: 'XXX') + end + end + end + + describe 'scitt courses' do + context 'when provider is excluded via config' do + scenario 'Guidance is not shown' do + given_a_provider_which_does_not_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_not_see_the_guidance_text + end + + def given_a_provider_which_does_not_show_guidance + @provider = create(:provider, :scitt, provider_code: 'E65') + end + end + + context 'when provider is not excluded via config' do + scenario 'Guidance is shown' do + given_a_provider_which_does_show_guidance + and_the_provider_has_a_course + and_i_am_authenticated_as_a_provider_user + when_i_go_to_edit_a_course + i_do_see_the_guidance_text + end + + def and_the_provider_has_a_course + @course = create(:course, :with_scitt, provider: @provider) + end + + def given_a_provider_which_does_show_guidance + @provider = create(:provider, :scitt, provider_code: 'T92') + end + end + end + + def and_the_provider_has_a_course + @course = create(:course, provider: @provider) + end + + def and_i_am_authenticated_as_a_provider_user + given_i_am_authenticated + @current_user.providers << @provider + end + + def when_i_go_to_edit_a_course + publish_course_information_edit_page.load( + provider_code: @provider.provider_code, recruitment_cycle_year: @provider.recruitment_cycle_year, course_code: @course.course_code + ) + end + + def i_do_not_see_the_guidance_text + expect(page).to have_no_content('Where you will train') + end + + def i_do_see_the_guidance_text + expect(page).to have_content('Where you will train') + end +end diff --git a/spec/services/configs/course_information_spec.rb b/spec/services/configs/course_information_spec.rb new file mode 100644 index 0000000000..55537532cf --- /dev/null +++ b/spec/services/configs/course_information_spec.rb @@ -0,0 +1,150 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Configs::CourseInformation do + let(:scitt_provider) { build(:provider, :scitt, provider_code:) } + let(:university_provider) { build(:provider, :university, provider_code:) } + + let(:he_course) { build(:course, :with_higher_education, provider:, course_code:) } + let(:scitt_course) { build(:course, :with_scitt, provider:, course_code:) } + + let(:provider_code) { 'XXX' } + let(:course_code) { 'XXX' } + + describe '#show_placement_guidance?' do + let(:course) { scitt_course } + let(:provider) { university_provider } + let(:type) { :provider_type } + + context 'when University providers provider code is present' do + let(:provider_code) { 'B31' } + + it 'returns false' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(false) + end + end + + context 'when University providers provider_code is absent' do + it 'returns true' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(true) + end + end + + context 'when SCITT course with provider_code present' do + let(:provider) { scitt_provider } + let(:type) { :program_type } + let(:provider_code) { 'E65' } + + it 'returns false' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(false) + end + end + + context 'when SCITT course with provider_code absent' do + let(:provider) { scitt_provider } + let(:type) { :program_type } + + it 'returns true' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(true) + end + end + + context 'when Higher Education course with provider_code present' do + let(:course) { he_course } + let(:provider) { scitt_provider } + let(:type) { :program_type } + let(:provider_code) { 'B31' } + + it 'returns false' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(false) + end + end + + context 'when Higher Education course with provider_code absent' do + let(:course) { he_course } + let(:provider) { scitt_provider } + let(:type) { :program_type } + + it 'returns true' do + obj = described_class.new(course) + + expect(obj.show_placement_guidance?(type)).to be(true) + end + end + end + + describe '#contact_form?' do + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when provider has a contact form' do + let(:provider_code) { 'U80' } + + it 'returns true' do + obj = described_class.new(course) + + expect(obj.contact_form?).to be(true) + end + end + + context 'when provider does not have a contact form' do + it 'returns false' do + obj = described_class.new(course) + + expect(obj.contact_form?).to be(false) + end + end + end + + describe '#contact_form' do + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when provider has a contact form' do + let(:provider_code) { 'U80' } + + it 'returns the contact form URL' do + obj = described_class.new(course) + + expect(obj.contact_form).to eq('https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries') + end + end + + context 'when provider does not have a contact form' do + it 'returns false' do + obj = described_class.new(course) + + expect(obj.contact_form).to be_nil + end + end + end + + describe '#show_address?' do + subject { described_class.new(course).show_address? } + + let(:provider) { scitt_provider } + let(:course) { scitt_course } + + context 'when course and provider codes exist' do + let(:provider_code) { '28T' } + let(:course_code) { 'X104' } + + it { is_expected.to be(true) } + end + + context 'when course and provider codes do not exist' do + it { is_expected.to be(false) } + end + end +end