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") %>

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_partnerships.html.erb b/app/components/add_course_button_enrichments.html.erb similarity index 100% rename from app/components/add_course_button_partnerships.html.erb rename to app/components/add_course_button_enrichments.html.erb diff --git a/app/components/add_course_button_partnerships.rb b/app/components/add_course_button_enrichments.rb similarity index 63% rename from app/components/add_course_button_partnerships.rb rename to app/components/add_course_button_enrichments.rb index 5a39e807d8..6f6d59883d 100644 --- a/app/components/add_course_button_partnerships.rb +++ b/app/components/add_course_button_enrichments.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class AddCourseButtonPartnerships < ViewComponent::Base +class AddCourseButtonEnrichments < ViewComponent::Base include RecruitmentCycleHelper attr_reader :provider @@ -22,13 +22,13 @@ def incomplete_sections def incomplete_sections_hash { site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year), - accredited_partner_not_present?: publish_provider_recruitment_cycle_accredited_partnerships_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_partner_not_present?: 'accredited partner', + accredited_provider_not_present?: 'accredited provider', site_not_present?: 'school' } @@ -36,23 +36,23 @@ def incomplete_section_label_suffix(section) end def required_organisation_details_present? - accredited_partner_present? && site_present? + accredited_provider_present? && site_present? end - def accredited_partner_present? + def accredited_provider_present? return true if accredited_provider? - provider.accredited_partners.any? + provider.accredited_providers.any? end def site_present? provider.sites.any? end - def accredited_partner_not_present? - return false if provider.accredited_provider? + def accredited_provider_not_present? + return false if provider.accredited? - !accredited_partner_present? + !accredited_provider_present? end def site_not_present? @@ -60,10 +60,10 @@ def site_not_present? end def accredited_provider? - provider.accredited_provider? + provider.accredited? end def incomplete_section_article(section) - incomplete_section_label_suffix(section) == 'accredited partner' ? 'an' : 'a' + incomplete_section_label_suffix(section) == 'accredited provider' ? 'an' : 'a' end end 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/config/locales/en.yml b/config/locales/en.yml index 02ab8b6efd..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: 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