diff --git a/app/controllers/support/providers/accredited_provider_search_controller.rb b/app/controllers/support/providers/accredited_provider_search_controller.rb index c3b5f92331..04707bfd24 100644 --- a/app/controllers/support/providers/accredited_provider_search_controller.rb +++ b/app/controllers/support/providers/accredited_provider_search_controller.rb @@ -30,7 +30,11 @@ def update @accredited_provider_select_form = AccreditedProviderSelectForm.new(provider_id: accredited_provider_select_params[:provider_id]) if @accredited_provider_select_form.valid? - redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id: accredited_provider_select_params[:provider_id]) + if Settings.features.provider_partnerships + redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id: accredited_provider_select_params[:provider_id]) + else + redirect_to new_support_recruitment_cycle_provider_accredited_provider_path(accredited_provider_id: accredited_provider_select_params[:provider_id]) + end else @accredited_provider_search = ::AccreditedProviders::SearchService.call(query:, recruitment_cycle_year: params[:recruitment_cycle_year]) render :results @@ -76,7 +80,11 @@ def search_result_title_component end def redirect_to_next_step - redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id:) + if Settings.features.provider_partnerships + redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id:) + else + redirect_to new_support_recruitment_cycle_provider_accredited_provider_path(accredited_provider_id:) + end end end end diff --git a/app/helpers/goto_confirmation_helper.rb b/app/helpers/goto_confirmation_helper.rb index 00f93be7ce..98d77c8a0b 100644 --- a/app/helpers/goto_confirmation_helper.rb +++ b/app/helpers/goto_confirmation_helper.rb @@ -20,42 +20,42 @@ def back_link_for_onboarding_path(param_form_key:, params:, recruitment_cycle_ye end def back_link_for_adding_accredited_partner_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - if goto_confirmation?(param_form_key:, params:) - check_support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) - elsif param_form_key == :support_accredited_provider_form - search_support_recruitment_cycle_provider_accredited_partners_path - else - support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) - end - end - - def back_link_for_adding_accrediting_provider_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - if goto_confirmation?(param_form_key:, params:) - check_support_recruitment_cycle_provider_accredited_providers_path(recruitment_cycle_year, provider) - elsif param_form_key == :support_accredited_provider_form - search_support_recruitment_cycle_provider_accredited_providers_path + if Settings.features.provider_partnerships + if goto_confirmation?(param_form_key:, params:) + check_support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) + elsif param_form_key == :support_accredited_provider_form + search_support_recruitment_cycle_provider_accredited_partners_path + else + support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) + end else - support_recruitment_cycle_provider_accredited_providers_path(recruitment_cycle_year, provider) - end - end - - def publish_back_link_for_adding_accrediting_provider_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - if goto_confirmation?(param_form_key:, params:) - check_publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) - elsif param_form_key == :publish_accredited_provider_form - search_publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) - else - publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) + if goto_confirmation?(param_form_key:, params:) + check_support_recruitment_cycle_provider_accredited_providers_path(recruitment_cycle_year, provider) + elsif param_form_key == :support_accredited_provider_form + search_support_recruitment_cycle_provider_accredited_providers_path + else + support_recruitment_cycle_provider_accredited_providers_path(recruitment_cycle_year, provider) + end end end def publish_back_link_for_adding_provider_partnership_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - if goto_confirmation?(param_form_key:, params:) - check_publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) - elsif param_form_key == :publish_accredited_provider_form - search_publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) + if Settings.features.provider_partnerships + if goto_confirmation?(param_form_key:, params:) + check_publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) + elsif param_form_key == :publish_accredited_provider_form + search_publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) + else + publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) + end else - publish_provider_recruitment_cycle_provider_partnerships_path(provider.provider_code, recruitment_cycle_year) + if goto_confirmation?(param_form_key:, params:) + check_publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) + elsif param_form_key == :publish_accredited_provider_form + search_publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) + else + publish_provider_recruitment_cycle_accredited_providers_path(provider.provider_code, recruitment_cycle_year) + end end end end diff --git a/app/helpers/publish/back_link_helper.rb b/app/helpers/publish/back_link_helper.rb index 6c781a29e6..bbfe6238fb 100644 --- a/app/helpers/publish/back_link_helper.rb +++ b/app/helpers/publish/back_link_helper.rb @@ -45,11 +45,7 @@ def study_mode_path(course) end def accredited_provider_search_path(param_form_key:, params:, provider:, recruitment_cycle_year:) - if Settings.features.provider_partnerships - publish_back_link_for_adding_provider_partnership_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - else - publish_back_link_for_adding_accrediting_provider_path(param_form_key:, params:, recruitment_cycle_year:, provider:) - end + publish_back_link_for_adding_provider_partnership_path(param_form_key:, params:, recruitment_cycle_year:, provider:) end private diff --git a/app/views/publish/providers/accredited_providers/new.html.erb b/app/views/publish/providers/accredited_providers/new.html.erb index d389e45095..6ad8660477 100644 --- a/app/views/publish/providers/accredited_providers/new.html.erb +++ b/app/views/publish/providers/accredited_providers/new.html.erb @@ -12,7 +12,7 @@
<% content_for :before_content do %> - <%= govuk_back_link_to(publish_back_link_for_adding_accrediting_provider_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider)) %> + <%= govuk_back_link_to(publish_back_link_for_adding_accredited_partner_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider)) %> <% end %> <%= f.govuk_text_area( diff --git a/app/views/support/providers/accredited_providers/new.html.erb b/app/views/support/providers/accredited_providers/new.html.erb index dfdc34edc3..9491ef1acb 100644 --- a/app/views/support/providers/accredited_providers/new.html.erb +++ b/app/views/support/providers/accredited_providers/new.html.erb @@ -12,7 +12,7 @@ <%= content_for(:breadcrumbs) do %> <%= render GovukComponent::BackLinkComponent.new( text: "Back", - href: back_link_for_adding_accrediting_provider_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider) + href: back_link_for_adding_accredited_partner_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider) ) %> <% end %> diff --git a/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_spec.rb b/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_enrichments_spec.rb similarity index 97% rename from spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_spec.rb rename to spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_enrichments_spec.rb index 879f8198fc..0d825e29ff 100644 --- a/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_spec.rb +++ b/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_enrichments_spec.rb @@ -2,8 +2,9 @@ require 'rails_helper' -feature 'Searching for an accredited provider' do +feature 'Searching for an accredited provider enrichments' do before do + allow(Settings.features).to receive(:provider_partnerships).and_return(false) given_i_am_authenticated_as_an_admin_user and_there_are_accredited_providers_in_the_database end diff --git a/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_partnerships_spec.rb b/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_partnerships_spec.rb new file mode 100644 index 0000000000..87e0a0863c --- /dev/null +++ b/spec/features/support/providers/accredited_provider_search/searching_for_an_accredited_provider_partnerships_spec.rb @@ -0,0 +1,191 @@ +# frozen_string_literal: true + +require 'rails_helper' + +feature 'Searching for an accredited provider' do + before do + allow(Settings.features).to receive(:provider_partnerships).and_return(true) + given_i_am_authenticated_as_an_admin_user + and_there_are_accredited_providers_in_the_database + end + + scenario 'i can search for an accredited provider by query' do + when_i_visit_the_accredited_provider_search_page + and_i_search_with_an_invalid_query + then_i_should_see_an_error_message + + when_i_search_for_an_accredited_provider_with_a_valid_query + then_i_see_the_provider_i_searched_for + + when_i_continue_without_selecting_an_accredited_provider + then_i_should_see_an_error_message('Select an accredited provider') + and_i_should_still_see_the_provider_i_searched_for + + when_i_select_the_provider + and_i_continue_without_entering_a_description + then_i_should_see_an_error_message('Enter details about the accredited partnership') + + when_i_enter_a_description + and_i_confirm_the_changes + then_i_should_be_taken_to_the_index_page + and_i_should_see_a_success_message + and_i_should_see_the_accredited_providers + end + + scenario 'back links behaviour' do + when_i_am_on_the_confirm_page + and_i_click_the_change_link_for('accredited partner name') + then_i_should_be_taken_to_the_accredited_provider_search_page + when_i_click_the_back_link + then_i_should_be_taken_back_to_the_confirm_page + + when_i_am_on_the_confirm_page + and_i_click_the_change_link_for('accredited partner description') + then_i_should_be_taken_to_the_accredited_provider_description_page + when_i_click_the_back_link + then_i_should_be_taken_back_to_the_confirm_page + end + + private + + def given_i_am_authenticated_as_an_admin_user + given_i_am_authenticated(user: create(:user, :admin)) + end + + def and_there_are_accredited_providers_in_the_database + @accredited_provider = create(:provider, :accredited_provider, provider_name: 'UCL', users: [create(:user)]) + @accredited_provider_two = create(:provider, :accredited_provider, provider_name: 'Accredited provider two') + @accredited_provider_three = create(:provider, :accredited_provider, provider_name: 'Accredited provider three') + end + + def when_i_visit_the_accredited_provider_search_page + visit search_support_recruitment_cycle_provider_accredited_providers_path( + recruitment_cycle_year: Settings.current_recruitment_cycle_year, + provider_id: provider.id + ) + end + + def when_i_search_for_an_accredited_provider_with_a_valid_query + fill_in form_title, with: @accredited_provider.provider_name + click_continue + end + + def then_i_see_the_provider_i_searched_for + expect(page).to have_content(@accredited_provider.provider_name) + expect(page).to have_no_content(@accredited_provider_two.provider_name) + expect(page).to have_no_content(@accredited_provider_three.provider_name) + end + + def when_i_select_the_provider + choose @accredited_provider.provider_name + click_continue + end + + def then_i_should_be_taken_to_the_index_page + expect(page).to have_current_path( + support_recruitment_cycle_provider_accredited_partners_path( + recruitment_cycle_year: Settings.current_recruitment_cycle_year, + provider_id: provider.id + ) + ) + end + + def and_i_search_with_an_invalid_query + fill_in form_title, with: '' + click_continue + end + + def then_i_should_see_an_error_message(error_message = form_title) + expect(page).to have_content(error_message) + end + + def when_i_continue_without_selecting_an_accredited_provider + click_continue + end + + def and_i_should_still_see_the_provider_i_searched_for + expect(page).to have_content(@accredited_provider.provider_name) + expect(page).to have_no_content(@accredited_provider_two.provider_name) + expect(page).to have_no_content(@accredited_provider_three.provider_name) + end + + def when_i_enter_a_description + fill_in 'About the accredited partner', with: 'This is a description' + click_continue + end + + def and_i_confirm_the_changes + expect do + click_link_or_button 'Add accredited partner' + end.to have_enqueued_email(Users::OrganisationMailer, :added_as_an_organisation_to_training_partner) + end + + def and_i_should_see_a_success_message + expect(page).to have_content('Accredited partner added') + end + + def and_i_should_see_the_accredited_providers + expect(page).to have_css('.govuk-summary-card', count: 1) + expect(page).to have_content(@accredited_provider.provider_name) + end + + def click_continue + click_link_or_button 'Continue' + end + + def when_i_am_on_the_confirm_page + when_i_visit_the_accredited_provider_search_page + when_i_search_for_an_accredited_provider_with_a_valid_query + when_i_select_the_provider + when_i_enter_a_description + end + + def and_i_click_the_change_link_for(field) + within '.govuk-summary-list' do + click_link_or_button "Change #{field}" + end + end + + def then_i_should_be_taken_to_the_accredited_provider_search_page + expect(page).to have_current_path( + search_support_recruitment_cycle_provider_accredited_providers_path( + recruitment_cycle_year: Settings.current_recruitment_cycle_year, + provider_id: provider.id, + goto_confirmation: true + ) + ) + end + + def then_i_should_be_taken_to_the_accredited_provider_description_page + expect(page).to have_current_path( + new_support_recruitment_cycle_provider_accredited_partner_path( + recruitment_cycle_year: Settings.current_recruitment_cycle_year, + provider_id: provider.id, + goto_confirmation: true + ) + ) + end + + def when_i_click_the_back_link + click_link_or_button 'Back' + end + + def then_i_should_be_taken_back_to_the_confirm_page + expect(page).to have_current_path( + check_support_recruitment_cycle_provider_accredited_partners_path( + recruitment_cycle_year: Settings.current_recruitment_cycle_year, + provider_id: provider.id + ) + ) + end + + def provider + @provider ||= create(:provider) + end + + def form_title + 'Enter a provider name, UKPRN or postcode' + end + + alias_method :and_i_continue_without_entering_a_description, :click_continue +end