diff --git a/app/components/add_course_button.html.erb b/app/components/add_course_button.html.erb
index beaa855073..154c6b3f7b 100644
--- a/app/components/add_course_button.html.erb
+++ b/app/components/add_course_button.html.erb
@@ -1,6 +1,6 @@
<% if required_organisation_details_present? %>
<%= govuk_button_link_to(
- "Add course",
+ t("components.add_course_button.add_course"),
new_publish_provider_recruitment_cycle_course_path(
provider_code: provider.provider_code,
recruitment_cycle_year: provider.recruitment_cycle_year
@@ -11,11 +11,11 @@
<% else %>
-
Before adding a course, you need to:
+
<%= t("components.add_course_button.before_adding") %>
<% incomplete_sections.each do |section| %>
-
- <%= govuk_link_to(section.name, section.path) %>
+ <%= govuk_link_to(section.text, section.path) %>
<% end %>
diff --git a/app/components/add_course_button.rb b/app/components/add_course_button.rb
index 401b1ac875..98996f7691 100644
--- a/app/components/add_course_button.rb
+++ b/app/components/add_course_button.rb
@@ -4,66 +4,42 @@ class AddCourseButton < ViewComponent::Base
include RecruitmentCycleHelper
attr_reader :provider
- Section = Struct.new(:name, :path, keyword_init: true)
+ Section = Struct.new(:text, :path, keyword_init: true)
def initialize(provider:)
- @provider = provider
super
+ @provider = provider
end
- private
-
- def incomplete_sections
- incomplete_sections_hash.keys.select { |section| send(section) }.map do |section|
- Section.new(name: "add #{incomplete_section_article(section)} #{incomplete_section_label_suffix(section)}", path: incomplete_sections_hash[section])
- end
- end
-
- def incomplete_sections_hash
- {
- site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year),
- accredited_provider_not_present?: publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, provider.recruitment_cycle_year)
- }
- end
-
- def incomplete_section_label_suffix(section)
- labels = {
- accredited_provider_not_present?: 'accredited provider',
- site_not_present?: 'school'
- }
-
- labels[section]
+ def required_organisation_details_present?
+ incomplete_sections.empty?
end
- def required_organisation_details_present?
- accredited_provider_present? && site_present?
+ def incomplete_sections
+ @incomplete_sections ||= [school, accredited_provider].compact
end
- def accredited_provider_present?
- return true if accredited_provider?
+ private
- provider.accredited_providers.any?
- end
+ def accredited_provider
+ return if accredited_partner_present?
- def site_present?
- provider.sites.any?
+ Section.new(text: t('components.add_course_button.add_accredited_provider'), path: publish_provider_recruitment_cycle_accredited_partnerships_path(provider.provider_code, provider.recruitment_cycle_year))
end
- def accredited_provider_not_present?
- return false if provider.accredited?
+ def school
+ return if school_present?
- !accredited_provider_present?
+ Section.new(text: t('components.add_course_button.add_school'), path: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year))
end
- def site_not_present?
- !site_present?
- end
+ def accredited_partner_present?
+ return true if provider.accredited?
- def accredited_provider?
- provider.accredited?
+ provider.accredited_partners.any?
end
- def incomplete_section_article(section)
- incomplete_section_label_suffix(section) == 'accredited provider' ? 'an' : 'a'
+ def school_present?
+ provider.sites.any?
end
end
diff --git a/app/components/add_course_button_enrichments.html.erb b/app/components/add_course_button_enrichments.html.erb
new file mode 100644
index 0000000000..beaa855073
--- /dev/null
+++ b/app/components/add_course_button_enrichments.html.erb
@@ -0,0 +1,23 @@
+<% if required_organisation_details_present? %>
+ <%= govuk_button_link_to(
+ "Add course",
+ new_publish_provider_recruitment_cycle_course_path(
+ provider_code: provider.provider_code,
+ recruitment_cycle_year: provider.recruitment_cycle_year
+ ),
+ class: "govuk-!-margin-bottom-6"
+ ) %>
+
+<% else %>
+
+
+
Before adding a course, you need to:
+
+ <% incomplete_sections.each do |section| %>
+ -
+ <%= govuk_link_to(section.name, section.path) %>
+
+ <% end %>
+
+
+<% end %>
diff --git a/app/components/add_course_button_enrichments.rb b/app/components/add_course_button_enrichments.rb
new file mode 100644
index 0000000000..6f6d59883d
--- /dev/null
+++ b/app/components/add_course_button_enrichments.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+class AddCourseButtonEnrichments < ViewComponent::Base
+ include RecruitmentCycleHelper
+ attr_reader :provider
+
+ Section = Struct.new(:name, :path, keyword_init: true)
+
+ def initialize(provider:)
+ @provider = provider
+ super
+ end
+
+ private
+
+ def incomplete_sections
+ incomplete_sections_hash.keys.select { |section| send(section) }.map do |section|
+ Section.new(name: "add #{incomplete_section_article(section)} #{incomplete_section_label_suffix(section)}", path: incomplete_sections_hash[section])
+ end
+ end
+
+ def incomplete_sections_hash
+ {
+ site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year),
+ accredited_provider_not_present?: publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, provider.recruitment_cycle_year)
+ }
+ end
+
+ def incomplete_section_label_suffix(section)
+ labels = {
+ accredited_provider_not_present?: 'accredited provider',
+ site_not_present?: 'school'
+ }
+
+ labels[section]
+ end
+
+ def required_organisation_details_present?
+ accredited_provider_present? && site_present?
+ end
+
+ def accredited_provider_present?
+ return true if accredited_provider?
+
+ provider.accredited_providers.any?
+ end
+
+ def site_present?
+ provider.sites.any?
+ end
+
+ def accredited_provider_not_present?
+ return false if provider.accredited?
+
+ !accredited_provider_present?
+ end
+
+ def site_not_present?
+ !site_present?
+ end
+
+ def accredited_provider?
+ provider.accredited?
+ end
+
+ def incomplete_section_article(section)
+ incomplete_section_label_suffix(section) == 'accredited provider' ? 'an' : 'a'
+ end
+end
diff --git a/app/controllers/publish/providers/training_partners/course_exports_controller.rb b/app/controllers/publish/providers/training_partners/course_exports_controller.rb
new file mode 100644
index 0000000000..ca50496c61
--- /dev/null
+++ b/app/controllers/publish/providers/training_partners/course_exports_controller.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Publish
+ module Providers
+ module TrainingPartners
+ class CourseExportsController < ApplicationController
+ def index
+ authorize(provider, :can_list_training_providers?)
+
+ respond_to do |format|
+ format.csv do
+ send_data(data_export.data, filename: data_export.filename, disposition: :attachment)
+ end
+ end
+ end
+
+ private
+
+ def courses
+ @courses ||= provider.current_accredited_courses
+ end
+
+ def data_export
+ @data_export ||= Exports::AccreditedCourseList.new(courses:)
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/publish/providers/training_partners/courses_controller.rb b/app/controllers/publish/providers/training_partners/courses_controller.rb
new file mode 100644
index 0000000000..c3b27c240e
--- /dev/null
+++ b/app/controllers/publish/providers/training_partners/courses_controller.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Publish
+ module Providers
+ module TrainingPartners
+ class CoursesController < ApplicationController
+ def index
+ authorize(provider, :index?)
+
+ @courses = fetch_courses
+ end
+
+ private
+
+ def training_partner
+ @training_partner ||= provider.training_partners.find_by(provider_code: params[:training_partner_code])
+ end
+
+ def fetch_courses
+ training_partner
+ .courses
+ .includes(:enrichments, :site_statuses, provider: [:recruitment_cycle])
+ .where(accredited_provider_code: provider.provider_code)
+ .order(:name)
+ .map(&:decorate)
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/publish/providers/training_partners_controller.rb b/app/controllers/publish/providers/training_partners_controller.rb
new file mode 100644
index 0000000000..94af7c6e70
--- /dev/null
+++ b/app/controllers/publish/providers/training_partners_controller.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Publish
+ module Providers
+ class TrainingPartnersController < ApplicationController
+ def index
+ authorize(provider, :can_list_training_providers?)
+
+ @training_partners = provider.training_partners.include_accredited_courses_counts(provider.provider_code).order(:provider_name)
+ @course_counts = @training_partners.to_h { |p| [p.provider_code, p.accredited_courses_count] }
+ end
+ end
+ end
+end
diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb
index af4dcdb3b5..717eae1816 100644
--- a/app/helpers/breadcrumb_helper.rb
+++ b/app/helpers/breadcrumb_helper.rb
@@ -73,9 +73,13 @@ def training_providers_breadcrumb
end
def training_provider_courses_breadcrumb
- path = publish_provider_recruitment_cycle_training_provider_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_provider.provider_code)
- training_providers_breadcrumb.merge({ "#{@training_provider.provider_name}’s courses" => path })
+ if Settings.features.provider_partnerships
+ path = publish_provider_recruitment_cycle_training_partner_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_partner.provider_code)
+ training_providers_breadcrumb.merge({ "#{@training_partner.provider_name}’s courses" => path })
+ else
+ path = publish_provider_recruitment_cycle_training_provider_courses_path(@provider.provider_code, @provider.recruitment_cycle_year, @training_provider.provider_code)
+ training_providers_breadcrumb.merge({ "#{@training_provider.provider_name}’s courses" => path })
+ end
end
-
# rubocop:enable Rails/HelperInstanceVariable
end
diff --git a/app/helpers/navigation_bar_helper.rb b/app/helpers/navigation_bar_helper.rb
index ee552a80b1..c635b046d6 100644
--- a/app/helpers/navigation_bar_helper.rb
+++ b/app/helpers/navigation_bar_helper.rb
@@ -21,6 +21,8 @@ def navigation_items(provider)
def partnership_link(provider)
if Settings.features.provider_partnerships && !provider.accredited?
{ name: t('navigation_bar.accredited_partnerships'), url: publish_provider_recruitment_cycle_accredited_partnerships_path(provider.provider_code, provider.recruitment_cycle_year) }
+ elsif Settings.features.provider_partnerships && provider.accredited?
+ { name: t('navigation_bar.training_partners'), url: publish_provider_recruitment_cycle_training_partners_path(provider.provider_code, provider.recruitment_cycle_year) }
elsif provider.accredited?
{ name: t('navigation_bar.training_partners'), url: publish_provider_recruitment_cycle_training_providers_path(provider.provider_code, provider.recruitment_cycle_year) }
else
diff --git a/app/views/publish/courses/index.html.erb b/app/views/publish/courses/index.html.erb
index 978e2db780..8bee0e38a8 100644
--- a/app/views/publish/courses/index.html.erb
+++ b/app/views/publish/courses/index.html.erb
@@ -2,8 +2,11 @@
<%= content_for :before_content, render_breadcrumbs(:courses) %>
Courses
-
+<% if Settings.features.provider_partnerships %>
<%= render AddCourseButton.new(provider: @provider) %>
+<% else %>
+<%= render AddCourseButtonEnrichments.new(provider: @provider) %>
+<% end %>
<% if @self_accredited_courses %>
diff --git a/app/views/publish/providers/training_partners/courses/index.html.erb b/app/views/publish/providers/training_partners/courses/index.html.erb
new file mode 100644
index 0000000000..37661ccd26
--- /dev/null
+++ b/app/views/publish/providers/training_partners/courses/index.html.erb
@@ -0,0 +1,11 @@
+<% content_for :page_title, @provider.provider_name %>
+<%= content_for :before_content, render_breadcrumbs(:training_provider_courses) %>
+
+
+ <%= t(".title") %>
+ <%= @training_partner.provider_name %>
+
+
+
+ <%= render partial: "publish/courses/course_table", locals: { courses: @courses } %>
+
diff --git a/app/views/publish/providers/training_partners/index.html.erb b/app/views/publish/providers/training_partners/index.html.erb
new file mode 100644
index 0000000000..dd60df6745
--- /dev/null
+++ b/app/views/publish/providers/training_partners/index.html.erb
@@ -0,0 +1,65 @@
+<% content_for :page_title, "Training partners" %>
+<%= content_for :before_content, render_breadcrumbs(:training_providers) %>
+
+
+ <%= t(".title") %>
+
+
+
+
+
+
+ <% @training_partners.each do |training_partner| %>
+ -
+
+ <% if Settings.features.provider_partnerships %>
+ <%= govuk_link_to(
+ training_partner.provider_name,
+ publish_provider_recruitment_cycle_training_partner_courses_path(
+ @provider.provider_code,
+ @provider.recruitment_cycle_year,
+ training_partner.provider_code
+ ),
+ class: "govuk-!-font-weight-bold",
+ data: { qa: "training_partner_name" }
+ ) %>
+ <% else %>
+ <%= govuk_link_to(
+ training_partner.provider_name,
+ publish_provider_recruitment_cycle_training_provider_courses_path(
+ @provider.provider_code,
+ @provider.recruitment_cycle_year,
+ training_partner.provider_code
+ ),
+ class: "govuk-!-font-weight-bold",
+ data: { qa: "training_partner_name" }
+ ) %>
+ <% end %>
+
+ <%= pluralize(@course_counts[training_partner.provider_code], "course") %>
+
+
+
+ <% end %>
+
+
+
+ <% unless @training_partners.empty? %>
+
+ <% end %>
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8653f9a7ec..32a37e5dbb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -220,6 +220,11 @@ en:
school_direct_salaried_training_programme:
label: "Salaried"
components:
+ add_course_button:
+ before_adding: "Before adding a course, you need to:"
+ add_course: Add course
+ add_accredited_provider: add an accredited provider
+ add_school: add a school
providers:
copy_course_content_warning_component:
copied_fields_from:
@@ -707,6 +712,15 @@ en:
title: *add_accredited_provider
caption: *add_accredited_provider
add: *add_accredited_provider
+ training_partners:
+ index:
+ title: Training partners
+ download: Download
+ download_file: Download as a CSV file
+ export: Export all the courses you’re the accredited provider for.
+ courses:
+ index:
+ title: Training partner
accredited_provider_search:
new:
title: &accredited_provider_title Enter a provider name, UKPRN or postcode
diff --git a/config/routes/publish.rb b/config/routes/publish.rb
index bd48e9574e..6b76bb3571 100644
--- a/config/routes/publish.rb
+++ b/config/routes/publish.rb
@@ -252,11 +252,19 @@
scope module: :providers do
get '/training-providers-courses', on: :member, to: 'training_providers/course_exports#index', as: 'download_training_providers_courses'
- resources :training_providers, path: '/training-providers', only: [:index], param: :code do
- resources :courses, module: :training_providers, only: [:index]
+ # rubocop:disable Style/RedundantConstantBase
+ constraints(::Constraints::PartnershipFeature.new(:off)) do
+ resources :training_providers, path: '/training-providers', only: [:index], param: :code do
+ resources :courses, only: [:index], controller: 'training_providers/courses'
+ end
+ end
+
+ constraints(::Constraints::PartnershipFeature.new(:on)) do
+ resources :training_partners, path: '/training-partners', controller: 'training_partners', only: [:index], param: :code do
+ resources :courses, only: [:index], controller: 'training_partners/courses'
+ end
end
- # rubocop:disable Style/RedundantConstantBase
constraints(::Constraints::PartnershipFeature.new(:on)) do
get '/accredited-providers', to: redirect('/publish/organisations/%{provider_code}/%{recruitment_cycle_year}/accredited-partnerships')
resources :accredited_partnerships, param: :accredited_provider_code, except: %i[show], path: 'accredited-partnerships', controller: 'accredited_partnerships' do
diff --git a/spec/components/add_course_button_enrichments_spec.rb b/spec/components/add_course_button_enrichments_spec.rb
new file mode 100644
index 0000000000..8cf7a97dea
--- /dev/null
+++ b/spec/components/add_course_button_enrichments_spec.rb
@@ -0,0 +1,186 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe AddCourseButtonEnrichments do
+ include Rails.application.routes.url_helpers
+
+ let(:recruitment_cycle) { build(:recruitment_cycle, :next) }
+ let(:provider) { build(:provider, recruitment_cycle:) }
+
+ before do
+ render_inline(described_class.new(provider:))
+ end
+
+ context 'when the provider has not filled out any required sections' do
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+
+ context 'when the provider has only added a study site' do
+ let(:provider) { build(:provider, study_sites: [build(:site, :study_site)], recruitment_cycle:) }
+
+ it 'renders a study sites link' do
+ expect(rendered_content).to have_no_link(
+ 'add a study site',
+ href: publish_provider_recruitment_cycle_study_sites_path(
+ provider.provider_code,
+ provider.recruitment_cycle_year
+ )
+ )
+ end
+
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+
+ context 'when the provider is an accredited provider' do
+ let(:provider) { build(:provider, :accredited_provider, recruitment_cycle:) }
+
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_no_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+
+ context 'when the provider has only added a site' do
+ let(:provider) { build(:provider, sites: [create(:site)], recruitment_cycle:) }
+
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_no_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+
+ context 'when the provider has added a site and a study site' do
+ let(:provider) { build(:provider, study_sites: [build(:site, :study_site)], sites: [build(:site)], recruitment_cycle:) }
+
+ it 'renders a study sites link' do
+ expect(rendered_content).to have_no_link(
+ 'add a study site',
+ href: publish_provider_recruitment_cycle_study_sites_path(
+ provider.provider_code,
+ provider.recruitment_cycle_year
+ )
+ )
+ end
+
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_no_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+
+ context 'when the provider has added all required organisation details' do
+ let(:provider) { build(:provider, :accredited_provider, study_sites: [build(:site, :study_site)], sites: [build(:site)], recruitment_cycle:) }
+
+ it 'renders a study sites link' do
+ expect(rendered_content).to have_no_link(
+ 'add a study site',
+ href: publish_provider_recruitment_cycle_study_sites_path(
+ provider.provider_code,
+ provider.recruitment_cycle_year
+ )
+ )
+ end
+
+ it 'renders an accredited provider link' do
+ expect(rendered_content).to have_no_link(
+ 'add an accredited provider',
+ href: publish_provider_recruitment_cycle_accredited_providers_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+
+ it 'renders a schools link' do
+ expect(rendered_content).to have_no_link(
+ 'add a school',
+ href: publish_provider_recruitment_cycle_schools_path(
+ provider.provider_code,
+ provider.recruitment_cycle.year
+ )
+ )
+ end
+ end
+end
diff --git a/spec/components/add_course_button_spec.rb b/spec/components/add_course_button_spec.rb
index 504977b9f8..d8db0279e0 100644
--- a/spec/components/add_course_button_spec.rb
+++ b/spec/components/add_course_button_spec.rb
@@ -16,7 +16,7 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
@@ -50,7 +50,7 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
@@ -74,7 +74,7 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_no_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
@@ -98,7 +98,7 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
@@ -132,14 +132,14 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
)
end
- it 'renders a schools link' do
+ it 'does not render a schools link' do
expect(rendered_content).to have_no_link(
'add a school',
href: publish_provider_recruitment_cycle_schools_path(
@@ -166,7 +166,7 @@
it 'renders an accredited provider link' do
expect(rendered_content).to have_no_link(
'add an accredited provider',
- href: publish_provider_recruitment_cycle_accredited_providers_path(
+ href: publish_provider_recruitment_cycle_accredited_partnerships_path(
provider.provider_code,
provider.recruitment_cycle.year
)
diff --git a/spec/features/publish/add_course_button_enrichments_spec.rb b/spec/features/publish/add_course_button_enrichments_spec.rb
new file mode 100644
index 0000000000..40e23b53ca
--- /dev/null
+++ b/spec/features/publish/add_course_button_enrichments_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+feature 'Add course button', :can_edit_current_and_next_cycles do
+ scenario 'with no study sites on the provider in the next cycle' do
+ given_i_am_authenticated_as_a_provider_user
+ when_i_visit_the_courses_page
+ then_i_should_see_the_add_course_button
+ end
+
+ scenario 'with study sites on the provider in the next cycle' do
+ given_i_am_authenticated_as_a_provider_user_with_study_sites
+ when_i_visit_the_courses_page
+ then_i_should_see_the_add_course_button
+ end
+
+ def then_i_should_see_the_add_study_site_link
+ expect(page).to have_link('add a study site', href: "/publish/organisations/#{provider.provider_code}/#{provider.recruitment_cycle_year}/study-sites")
+ end
+
+ def and_i_should_not_see_the_add_course_button
+ expect(page).to have_no_link('Add course')
+ end
+
+ def then_i_should_see_the_add_course_button
+ expect(page).to have_link('Add course')
+ end
+
+ def given_i_am_authenticated_as_a_provider_user
+ given_i_am_authenticated(
+ user: create(
+ :user,
+ providers: [
+ create(:provider, :accredited_provider, sites: [build(:site)], courses: [build(:course)])
+ ]
+ )
+ )
+ end
+
+ def given_i_am_authenticated_as_a_provider_user_with_study_sites
+ given_i_am_authenticated(
+ user: create(
+ :user,
+ providers: [
+ create(:provider, :accredited_provider, sites: [build(:site)], study_sites: [build(:site, :study_site)], courses: [build(:course)])
+ ]
+ )
+ )
+ end
+
+ def when_i_visit_the_courses_page
+ publish_provider_courses_index_page.load(
+ provider_code: provider.provider_code, recruitment_cycle_year: provider.recruitment_cycle_year
+ )
+ end
+
+ def provider
+ @current_user.providers.first
+ end
+end
diff --git a/spec/features/publish/viewing_training_partners_and_their_courses_spec.rb b/spec/features/publish/viewing_training_partners_and_their_courses_spec.rb
new file mode 100644
index 0000000000..ddc7d64cb5
--- /dev/null
+++ b/spec/features/publish/viewing_training_partners_and_their_courses_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+feature 'Viewing courses as an accredited provider', { can_edit_current_and_next_cycles: false } do
+ before do
+ allow(Settings.features).to receive(:provider_partnerships).and_return(true)
+ given_i_am_authenticated_as_an_accredited_provider_user
+ and_some_courses_exist_with_one_i_accredit
+ when_i_visit_the_publish_training_partner_index_page
+ end
+
+ scenario 'i can see who lists me as their accredited provider' do
+ then_i_should_see_a_list_of_training_partners
+ and_i_should_see_a_count_of_the_courses_i_accredit
+ end
+
+ scenario 'i can see which courses i am the accredited provider for' do
+ and_i_click_on_a_training_provider
+ then_i_see_the_courses_i_accredit_for
+ end
+
+ def given_i_am_authenticated_as_an_accredited_provider_user
+ given_i_am_authenticated(user: create(:user, providers: [create(:provider, :accredited_provider)]))
+ end
+
+ def and_some_courses_exist_with_one_i_accredit
+ create(:provider_partnership, training_provider:, accredited_provider: accrediting_provider)
+ given_a_course_exists(
+ enrichments: [build(:course_enrichment, :published)],
+ provider: training_provider,
+ accrediting_provider:
+ )
+
+ create(:course, enrichments: [build(:course_enrichment, :published)], provider: training_provider)
+ end
+
+ def when_i_visit_the_publish_training_partner_index_page
+ publish_training_partner_index_page.load(
+ provider_code: accrediting_provider.provider_code, recruitment_cycle_year: accrediting_provider.recruitment_cycle_year
+ )
+ end
+
+ def then_i_should_see_a_list_of_training_partners
+ expect(publish_training_partner_index_page.training_provider_rows.size).to eq(1)
+
+ expect(publish_training_partner_index_page.training_provider_rows.first.name).to have_text(training_provider.provider_name)
+ end
+
+ def and_i_should_see_a_count_of_the_courses_i_accredit
+ expect(publish_training_partner_index_page.training_provider_rows.first.course_count).to have_text('1')
+ end
+
+ def and_i_click_on_a_training_provider
+ publish_training_partner_index_page.training_provider_rows.first.name.click
+ end
+
+ def then_i_see_the_courses_i_accredit_for
+ expect(publish_training_partners_course_index_page).to be_displayed
+ expect(publish_training_partners_course_index_page.courses.size).to eq(1)
+ expect(publish_training_partners_course_index_page.courses.first.name).to have_text(course.name)
+ end
+
+ def accrediting_provider
+ @current_user.providers.first
+ end
+
+ def training_provider
+ @training_partner ||= create(:provider)
+ end
+end
diff --git a/spec/features/publish/viewing_training_providers_and_their_courses_spec.rb b/spec/features/publish/viewing_training_providers_and_their_courses_spec.rb
index 5d55aca33b..39097233dd 100644
--- a/spec/features/publish/viewing_training_providers_and_their_courses_spec.rb
+++ b/spec/features/publish/viewing_training_providers_and_their_courses_spec.rb
@@ -4,6 +4,7 @@
feature 'Viewing courses as an accredited provider', { can_edit_current_and_next_cycles: false } do
before do
+ allow(Settings.features).to receive(:provider_partnerships).and_return(false)
given_i_am_authenticated_as_an_accredited_provider_user
and_some_courses_exist_with_one_i_accredit
when_i_visit_the_publish_training_provider_index_page
diff --git a/spec/support/feature_helpers/course_steps.rb b/spec/support/feature_helpers/course_steps.rb
index d4fa963704..cba7038940 100644
--- a/spec/support/feature_helpers/course_steps.rb
+++ b/spec/support/feature_helpers/course_steps.rb
@@ -5,7 +5,7 @@ module CourseSteps
attr_reader :course
def given_a_course_exists(*traits, **overrides)
- @course ||= create(:course, *traits, **overrides, provider: current_user.providers.first)
+ @course ||= create(:course, *traits, **overrides, provider: overrides.delete(:provider) || current_user.providers.first)
end
def given_a_site_exists(*traits, **overrides)
diff --git a/spec/support/page_objects/publish/training_partner_index.rb b/spec/support/page_objects/publish/training_partner_index.rb
new file mode 100644
index 0000000000..d09f410387
--- /dev/null
+++ b/spec/support/page_objects/publish/training_partner_index.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require_relative '../sections/training_partner'
+
+module PageObjects
+ module Publish
+ class TrainingPartnerIndex < PageObjects::Base
+ set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/training-partners'
+
+ sections :training_provider_rows, Sections::TrainingPartner, '[data-qa="provider__training_partners_list"]'
+ end
+ end
+end
diff --git a/spec/support/page_objects/publish/training_partners/course_index.rb b/spec/support/page_objects/publish/training_partners/course_index.rb
new file mode 100644
index 0000000000..601b457111
--- /dev/null
+++ b/spec/support/page_objects/publish/training_partners/course_index.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Publish
+ module TrainingPartners
+ class CourseIndex < PageObjects::Base
+ set_url '/publish/organisations/{provider_code}/{recruitment_cycle_year}/training-partners/{training_provider_code}/courses'
+
+ sections :courses, '[data-qa="courses__table-section"]' do
+ element :name, '[data-qa="courses-table__course-name"]'
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/page_objects/sections/training_partner.rb b/spec/support/page_objects/sections/training_partner.rb
new file mode 100644
index 0000000000..137776671e
--- /dev/null
+++ b/spec/support/page_objects/sections/training_partner.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+require_relative 'base'
+
+module PageObjects
+ module Sections
+ class TrainingPartner < PageObjects::Sections::Base
+ element :name, '[data-qa="training_partner_name"]'
+ element :course_count, '[data-qa="course_count"]'
+ end
+ end
+end