Skip to content

Commit

Permalink
Merge pull request #4003 from DFE-Digital/1141-find-remove-reference-…
Browse files Browse the repository at this point in the history
…to-provider-codes

Refactor references to provider codes in view templates
  • Loading branch information
inulty-dfe authored Jan 18, 2024
2 parents 1ac9d7e + e381d24 commit e1a3327
Show file tree
Hide file tree
Showing 12 changed files with 362 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="govuk-!-margin-bottom-8">
<h2 class="govuk-heading-l" id="training-locations">Training locations</h2>
<div data-qa="course__about_schools">
<% 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 %>
<p class="govuk-body">You’ll be placed in schools for most of your course. Your school placements will be within
commuting distance.</p>
Expand All @@ -10,7 +10,7 @@
<p class="govuk-body">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.</p>
<% 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 %>
<p class="govuk-body">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.</p>
<% end %>
Expand Down
21 changes: 19 additions & 2 deletions app/components/find/courses/about_schools_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

<div class="course-basicinfo">
<dl class="app-description-list">
<!-- Temporary stop gap for https://trello.com/c/vJRKI35V/614-stop-gap-ucl-is-moving-away-from-using-email. BIN it as soon as we have a better solution. -->
<% if course.provider.provider_code == "U80" %>
<% link = "https://www.ucl.ac.uk/prospective-students/graduate/admissions-enquiries" %>
<% if show_contact_form_instead_of_email? %>
<dt class="app-description-list__label">Contact form</dt>
<dd data-qa="provider__email">
<%= govuk_link_to link, link %>
<%= govuk_link_to contact_form, contact_form %>
</dd>
<% else %>
<% if course.provider.email.present? %>
Expand All @@ -33,7 +31,7 @@
</dd>
<% end %>

<% if course.provider.provider_code == "28T" && course.course_code == "X104" %>
<% if show_address? %>
<dt class="app-description-list__label">Address</dt>
<dd data-qa="provider__address">
LSJS
Expand Down
11 changes: 11 additions & 0 deletions app/components/find/courses/contact_details_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/publish/courses/course_information_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions app/services/configs/course_information.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/views/publish/courses/course_information/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@
<li>how placement schools are selected</li>
</ul>

<% 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 %>
<h3 class="govuk-heading-m">Where you will train</h3>
<p class="govuk-body">You’ll be placed in schools for most of your course. Your school placements will be within commuting distance.</p>
<p class="govuk-body">You cannot pick which schools you want to be in, but your university will try to take your journey time into consideration.</p>
<p class="govuk-body">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.</p>
<% 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 %>
<h3 class="govuk-heading-m">Where you will train</h3>
<p class="govuk-body">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.</p>
Expand Down
20 changes: 20 additions & 0 deletions config/course_information.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit e1a3327

Please sign in to comment.