From 90dc2a5cf79713092022e1c579a4628d3ae60d71 Mon Sep 17 00:00:00 2001 From: Iain McNulty Date: Thu, 9 May 2024 15:13:46 +0100 Subject: [PATCH] Update Providers Reports index Add Recruitment Performance report Show mid-cycle / recruitment performance based on FeatureFlag Add specs for single / multiple providers --- .../provider_interface/reports_controller.rb | 3 +- app/models/provider.rb | 2 + .../provider_interface/reports/index.html.erb | 85 ++++++++------ .../provider_reports_page_spec.rb | 105 ------------------ .../index_provider_user_one_provider_spec.rb | 38 +++++++ .../index_provider_user_two_providers_spec.rb | 48 ++++++++ ..._providers_with_performance_report_spec.rb | 56 ++++++++++ 7 files changed, 198 insertions(+), 139 deletions(-) delete mode 100644 spec/system/provider_interface/provider_reports_page_spec.rb create mode 100644 spec/system/provider_interface/reports/index_provider_user_one_provider_spec.rb create mode 100644 spec/system/provider_interface/reports/index_provider_user_two_providers_spec.rb create mode 100644 spec/system/provider_interface/reports/index_provider_user_two_providers_with_performance_report_spec.rb diff --git a/app/controllers/provider_interface/reports_controller.rb b/app/controllers/provider_interface/reports_controller.rb index 5275345181f..a314f2e8cd1 100644 --- a/app/controllers/provider_interface/reports_controller.rb +++ b/app/controllers/provider_interface/reports_controller.rb @@ -1,7 +1,8 @@ module ProviderInterface class ReportsController < ProviderInterfaceController def index - @providers = current_user.providers + @providers = current_user.providers.preload(:performance_reports) + @performance_reports = current_user.providers.any? { _1.performance_reports.present? } end end end diff --git a/app/models/provider.rb b/app/models/provider.rb index 873c27809dc..f1ddc9ee092 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -16,6 +16,8 @@ class Provider < ApplicationRecord has_many :vendor_api_requests has_many :vendor_api_tokens + has_many :performance_reports, class_name: 'Publications::ProviderRecruitmentPerformanceReport' + enum region_code: { east_midlands: 'east_midlands', eastern: 'eastern', diff --git a/app/views/provider_interface/reports/index.html.erb b/app/views/provider_interface/reports/index.html.erb index 5094e03809c..1991dd937bc 100644 --- a/app/views/provider_interface/reports/index.html.erb +++ b/app/views/provider_interface/reports/index.html.erb @@ -5,6 +5,58 @@

<%= t('page_titles.provider.reports') %>

+ + <% if FeatureFlag.active?(:recruitment_performance_report) %> + <% if @performance_reports %> +

+ Weekly recruitment performance report +

+ <% end %> + + <% @providers.select { _1.performance_reports.any? }.each do |provider| %> +

<%= provider.name %>

+ <% report = provider.performance_reports.last %> + + <% end %> + <% else %> +

+ Mid-cycle recruitment performance report +

+ + <% @providers.select { mid_cycle_report_present_for?(_1) }.each do |provider| %> +

<%= provider.name %>

+ + + <% end %> + <% end %> + +

Application data for this recruitment cycle

+ <% @providers.each do |provider| %> + <% if @providers.many? %> +

<%= provider.name %>

+ <% end %> + + <% end %> + +

Download and export

- <% if @providers.many? %> - <% @providers.each do |provider| %> -

<%= provider.name %>

- - <% end %> - <% end %> diff --git a/spec/system/provider_interface/provider_reports_page_spec.rb b/spec/system/provider_interface/provider_reports_page_spec.rb deleted file mode 100644 index 01ef6264dbd..00000000000 --- a/spec/system/provider_interface/provider_reports_page_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'Provider reports page' do - include CourseOptionHelpers - include DfESignInHelpers - - scenario 'the application data and HESA export pages are linked correctly' do - given_i_am_a_provider_user_with_permissions_to_see_applications_for_my_provider - and_i_sign_in_to_the_provider_interface - - when_i_visit_the_reports_page - then_i_should_see_a_link_to_the_hesa_export_page - and_the_page_contains_breadcrumbs_including_the_reports_page - - when_i_visit_the_reports_page_and_i_click_the_export_data_link - then_i_should_be_on_the_data_export_page - and_the_page_contains_breadcrumbs_including_the_reports_page - - when_i_visit_the_reports_page - then_i_should_see_links_for_all_the_provider_status_application_records - - when_i_visit_the_reports_page - then_i_should_see_new_links_for_all_the_provider_reports - - given_there_are_mid_cycle_reports - when_i_visit_the_reports_page - then_i_should_see_new_links_for_all_providers_mid_cycle_reports - end - - def given_i_am_a_provider_user_with_permissions_to_see_applications_for_my_provider - provider_exists_in_dfe_sign_in - @provider_user = provider_user_exists_in_apply_database - end - - def when_i_visit_the_reports_page_and_i_click_the_export_data_link - visit provider_interface_reports_path - click_link_or_button 'Export application data' - end - - def when_i_visit_the_reports_page - visit provider_interface_reports_path - end - - def then_i_should_see_a_link_to_the_data_export_page - expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)') - click_link_or_button('Export data for Higher Education Statistics Agency (HESA)') - then_i_should_be_redirected_to_the_hesa_export_page - end - - def then_i_should_see_a_link_to_the_hesa_export_page - expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)') - click_link_or_button('Export data for Higher Education Statistics Agency (HESA)') - then_i_should_be_redirected_to_the_hesa_export_page - end - - def and_the_page_contains_breadcrumbs_including_the_reports_page - within '.govuk-breadcrumbs' do - expect(page).to have_link('Reports') - end - end - - def then_i_should_be_redirected_to_the_hesa_export_page - expect(page).to have_current_path(provider_interface_reports_hesa_exports_path) - end - - def then_i_should_be_on_the_data_export_page - expect(page).to have_current_path(provider_interface_new_application_data_export_path) - expect(page).to have_content('Export application data (CSV)') - end - - def then_i_should_see_links_for_all_the_provider_status_application_records - @provider_user.providers.each do |provider| - expect(page).to have_content(provider.name) - expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: provider)) - end - end - - def then_i_should_see_new_links_for_all_the_provider_reports - @provider_user.providers.each do |provider| - expect(page).to have_content(provider.name) - expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: provider)) - expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: provider)) - expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: provider)) - end - end - - def given_there_are_mid_cycle_reports - create( - :provider_mid_cycle_report, - provider: @provider_user.providers.first, - publication_date: Date.new(2023, 6, 1), - ) - end - - def then_i_should_see_new_links_for_all_providers_mid_cycle_reports - expect(page).to have_link( - '2022 to 2023 recruitment cycle performance', - href: provider_interface_reports_provider_mid_cycle_report_path(provider_id: @provider_user.providers.first), - ) - expect(page).to have_no_link( - '2022 to 2023 recruitment cycle performance', - href: provider_interface_reports_provider_mid_cycle_report_path(provider_id: @provider_user.providers.last), - ) - end -end diff --git a/spec/system/provider_interface/reports/index_provider_user_one_provider_spec.rb b/spec/system/provider_interface/reports/index_provider_user_one_provider_spec.rb new file mode 100644 index 00000000000..0b78d891700 --- /dev/null +++ b/spec/system/provider_interface/reports/index_provider_user_one_provider_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.feature 'Provider reports index' do + include DfESignInHelpers + scenario 'when provider user has one provider' do + given_a_provider_and_provider_user_exists + and_i_am_signed_in_as_provider_user + when_i_visit_the_reports_index + then_the_page_has_the_right_content + end + + def when_i_visit_the_reports_index + visit provider_interface_reports_path + expect(page).to have_current_path('/provider/reports') + end + + def given_a_provider_and_provider_user_exists + @provider_user = create(:provider_user, :with_dfe_sign_in, email_address: 'email@provider.ac.uk') + @provider = @provider_user.providers.first + end + + def then_the_page_has_the_right_content + expect(page).to have_css('h1', text: 'Reports') + expect(page).to have_css('h2', text: 'Application data for this recruitment cycle') + expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: @provider)) + expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: @provider)) + expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: @provider)) + expect(page).to have_css('h2', text: 'Download and export') + expect(page).to have_link('Export application data', href: provider_interface_new_application_data_export_path) + expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)', href: provider_interface_reports_hesa_exports_path) + end + + def and_i_am_signed_in_as_provider_user + provider_exists_in_dfe_sign_in + provider_signs_in_using_dfe_sign_in + expect(page).to have_current_path('/provider/applications') + end +end diff --git a/spec/system/provider_interface/reports/index_provider_user_two_providers_spec.rb b/spec/system/provider_interface/reports/index_provider_user_two_providers_spec.rb new file mode 100644 index 00000000000..c0e3e9a7145 --- /dev/null +++ b/spec/system/provider_interface/reports/index_provider_user_two_providers_spec.rb @@ -0,0 +1,48 @@ +require 'rails_helper' + +RSpec.feature 'Provider with two providers reports index' do + include DfESignInHelpers + scenario 'when a provider user has more than one provider' do + given_a_provider_user_with_two_providers_exists + and_i_am_signed_in_as_provider_user + when_i_visit_the_reports_index + and_the_page_has_all_the_right_elements + end + + def when_i_visit_the_reports_index + visit provider_interface_reports_path + expect(page).to have_current_path('/provider/reports') + end + + def given_a_provider_user_with_two_providers_exists + @provider_user = create(:provider_user, :with_dfe_sign_in, email_address: 'email@provider.ac.uk') + @provider = @provider_user.providers.first + @second_provider = create(:provider) + # add a second provider to the users account + @provider_user.providers << @second_provider + end + + def and_the_page_has_all_the_right_elements + expect(page).to have_css('h1', text: 'Reports') + expect(page).to have_css('h2', text: 'Application data for this recruitment cycle') + expect(page).to have_link('Export application data', href: provider_interface_new_application_data_export_path) + expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)', href: provider_interface_reports_hesa_exports_path) + expect(page).to have_css('h3', text: @provider.name) + expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: @provider)) + expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: @provider)) + expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: @second_provider)) + expect(page).to have_css('h3', text: @second_provider.name) + expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: @second_provider)) + expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: @second_provider)) + expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: @second_provider)) + expect(page).to have_css('h2', text: 'Download and export') + expect(page).to have_link('Export application data', href: provider_interface_new_application_data_export_path) + expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)', href: provider_interface_reports_hesa_exports_path) + end + + def and_i_am_signed_in_as_provider_user + provider_exists_in_dfe_sign_in + provider_signs_in_using_dfe_sign_in + expect(page).to have_current_path('/provider/applications') + end +end diff --git a/spec/system/provider_interface/reports/index_provider_user_two_providers_with_performance_report_spec.rb b/spec/system/provider_interface/reports/index_provider_user_two_providers_with_performance_report_spec.rb new file mode 100644 index 00000000000..f0c45c10509 --- /dev/null +++ b/spec/system/provider_interface/reports/index_provider_user_two_providers_with_performance_report_spec.rb @@ -0,0 +1,56 @@ +require 'rails_helper' + +RSpec.feature 'Provider with two providers reports index' do + include DfESignInHelpers + before { FeatureFlag.activate(:recruitment_performance_report) } + + scenario 'when provider user has multiple provider with performance report' do + given_a_provider_user_with_two_providers_exists + and_a_provider_has_a_recruitment_peroformance_report + and_i_am_signed_in_as_provider_user + when_i_visit_the_reports_index + then_the_page_has_the_right_content + end + + def when_i_visit_the_reports_index + visit provider_interface_reports_path + expect(page).to have_current_path('/provider/reports', ignore_query: true) + end + + def and_a_provider_has_a_recruitment_peroformance_report + create(:provider_recruitment_performance_report, provider: @provider) + end + + def given_a_provider_user_with_two_providers_exists + @provider_user = create(:provider_user, :with_dfe_sign_in, email_address: 'email@provider.ac.uk') + @provider = @provider_user.providers.first + @second_provider = create(:provider) + @provider_user.providers << @second_provider + end + + def then_the_page_has_the_right_content + expect(page).to have_css('h1', text: 'Reports') + expect(page).to have_css('h2', text: 'Weekly recruitment performance report') + expect(page).to have_link('Weekly report for week ending 2024-06-01', href: provider_interface_reports_provider_recruitment_performance_report_path(@provider)) + expect(page).to have_css('h2', text: 'Application data for this recruitment cycle') + expect(page).to have_link('Export application data', href: provider_interface_new_application_data_export_path) + expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)', href: provider_interface_reports_hesa_exports_path) + expect(page).to have_css('h3', text: @provider.name) + expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: @provider)) + expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: @provider)) + expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: @provider)) + expect(page).to have_css('h3', text: @second_provider.name) + expect(page).to have_link('Status of active applications', href: provider_interface_reports_provider_status_of_active_applications_path(provider_id: @second_provider)) + expect(page).to have_link('Sex, disability, ethnicity and age of candidates', href: provider_interface_reports_provider_diversity_report_path(provider_id: @second_provider)) + expect(page).to have_link('Withdrawals', href: provider_interface_reports_provider_withdrawal_report_path(provider_id: @second_provider)) + expect(page).to have_css('h2', text: 'Download and export') + expect(page).to have_link('Export application data', href: provider_interface_new_application_data_export_path) + expect(page).to have_link('Export data for Higher Education Statistics Agency (HESA)', href: provider_interface_reports_hesa_exports_path) + end + + def and_i_am_signed_in_as_provider_user + provider_exists_in_dfe_sign_in + provider_signs_in_using_dfe_sign_in + expect(page).to have_current_path('/provider/applications', ignore_query: true) + end +end