From 08622597430d744629ce449fd77a44a51f5cc5c8 Mon Sep 17 00:00:00 2001 From: George Schena Date: Tue, 27 Aug 2024 16:14:19 +0100 Subject: [PATCH] Implement interruption pages for ENIC --- ...application_review_and_submit_component.rb | 2 + .../review_enic_interruption_controller.rb | 24 +++ app/models/application_form.rb | 19 +++ .../_not_needed.html.erb | 16 ++ .../_waiting_maybe.html.erb | 17 +++ .../review_enic_interruption/show.html.erb | 10 ++ .../review_interruption/show.html.erb | 19 ++- .../candidate_interface/interruption.yml | 27 ++++ config/routes/candidate.rb | 1 + spec/models/application_form_spec.rb | 35 +++++ ...pplication_with_interruption_pages_spec.rb | 144 ++++++++++++++++++ 11 files changed, 307 insertions(+), 7 deletions(-) create mode 100644 app/controllers/candidate_interface/course_choices/review_enic_interruption_controller.rb create mode 100644 app/views/candidate_interface/course_choices/review_enic_interruption/_not_needed.html.erb create mode 100644 app/views/candidate_interface/course_choices/review_enic_interruption/_waiting_maybe.html.erb create mode 100644 app/views/candidate_interface/course_choices/review_enic_interruption/show.html.erb create mode 100644 config/locales/candidate_interface/interruption.yml create mode 100644 spec/system/candidate_interface/submitting/candidate_submitting_application_with_interruption_pages_spec.rb diff --git a/app/components/candidate_interface/application_review_and_submit_component.rb b/app/components/candidate_interface/application_review_and_submit_component.rb index 30676d10be1..8f26a828927 100644 --- a/app/components/candidate_interface/application_review_and_submit_component.rb +++ b/app/components/candidate_interface/application_review_and_submit_component.rb @@ -22,6 +22,8 @@ def application_can_submit? def review_path if short_personal_statement? candidate_interface_course_choices_course_review_interruption_path(application_choice.id) + elsif application_choice.application_form.qualifications_enic_reasons_waiting_or_maybe? || application_choice.application_form.any_qualification_enic_reason_not_needed? + candidate_interface_course_choices_course_review_enic_interruption_path(application_choice.id) else candidate_interface_course_choices_course_review_and_submit_path(application_choice.id) end diff --git a/app/controllers/candidate_interface/course_choices/review_enic_interruption_controller.rb b/app/controllers/candidate_interface/course_choices/review_enic_interruption_controller.rb new file mode 100644 index 00000000000..843b4a698cc --- /dev/null +++ b/app/controllers/candidate_interface/course_choices/review_enic_interruption_controller.rb @@ -0,0 +1,24 @@ +module CandidateInterface + module CourseChoices + class ReviewEnicInterruptionController < CandidateInterface::CourseChoices::BaseController + before_action :redirect_to_your_applications_if_submitted + before_action :viewed_enic_interruption_page, only: :show + + def show + set_enic_reviewed_cookie + end + + private + + def viewed_enic_interruption_page + if cookies[:viewed_enic_interruption_page] == 'true' + redirect_to candidate_interface_course_choices_course_review_and_submit_path(@application_choice.id) + end + end + + def set_enic_reviewed_cookie + cookies[:viewed_enic_interruption_page] = { value: 'true' } + end + end + end +end diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 1efd14612c7..a4be75a4139 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -206,6 +206,25 @@ def touch_choices application_choices.touch_all end + def any_qualification_enic_reason_not_needed? + return false if application_qualifications.empty? + return false if application_qualifications.all? { |qualification| qualification.enic_reason.nil? } + + non_uk_qualifications = application_qualifications.reject do |qualification| + qualification.institution_country.nil? || qualification.institution_country == 'GB' || qualification.enic_reason.nil? + end + + non_uk_qualifications.all?(&:enic_reason_not_needed?) + end + + def qualifications_enic_reasons_waiting_or_maybe? + return false if application_qualifications.empty? + + application_qualifications.count do |qualification| + qualification.enic_reason_waiting? || qualification.enic_reason_maybe? + end >= 1 + end + def missing_enic_reference_for_non_uk_qualifications? @missing_enic_reference_for_non_uk_qualifications ||= application_qualifications .where.not(institution_country: 'GB') diff --git a/app/views/candidate_interface/course_choices/review_enic_interruption/_not_needed.html.erb b/app/views/candidate_interface/course_choices/review_enic_interruption/_not_needed.html.erb new file mode 100644 index 00000000000..ebe4d65b634 --- /dev/null +++ b/app/views/candidate_interface/course_choices/review_enic_interruption/_not_needed.html.erb @@ -0,0 +1,16 @@ +
+
+
+

<%= t('review_enic_interruption.title') %>

+ +

<%= t('review_enic_interruption.not_needed.more_likely_html') %>

+

<%= t('review_enic_interruption.not_needed.if_you_apply_enic_html', link: govuk_link_to(t('review_enic_interruption.not_needed.apply_for_enic_link'), candidate_interface_course_choices_course_review_path(current_application.id))) %>

+

<%= t('review_enic_interruption.not_needed.dont_provide_enic') %>

+
+ +
+ <%= govuk_button_to(t('review_enic_interruption.not_needed.continue_button_text'), candidate_interface_course_choices_course_review_and_submit_path(@application_choice.id), method: :get) %> + <%= govuk_link_to(t('review_enic_interruption.not_needed.save_application_button_text'), candidate_interface_course_choices_course_review_path(current_application.id)) %> +
+
+
diff --git a/app/views/candidate_interface/course_choices/review_enic_interruption/_waiting_maybe.html.erb b/app/views/candidate_interface/course_choices/review_enic_interruption/_waiting_maybe.html.erb new file mode 100644 index 00000000000..9ac8215db15 --- /dev/null +++ b/app/views/candidate_interface/course_choices/review_enic_interruption/_waiting_maybe.html.erb @@ -0,0 +1,17 @@ +
+
+
+

<%= t('review_enic_interruption.title') %>

+ +

<%= t('review_enic_interruption.waiting_maybe.planned_link_html', link: govuk_link_to(t('review_enic_interruption.waiting_maybe.enic_link_text'), t('service_name.enic.statement_of_comparability_url'))) %>

+

<%= t('review_enic_interruption.waiting_maybe.if_you_have_enic') %>

+

<%= t('review_enic_interruption.waiting_maybe.save_as_draft_html', link: govuk_link_to(t('review_enic_interruption.waiting_maybe.save_this_as_draft'), candidate_interface_course_choices_course_review_path(current_application.id))) %>

+

<%= t('review_enic_interruption.waiting_maybe.without_enic') %>

+
+ +
+ <%= govuk_button_to(t('review_enic_interruption.waiting_maybe.enter_enic'), candidate_interface_continuous_applications_details_path, method: :get) %> + <%= govuk_link_to(t('review_enic_interruption.waiting_maybe.without_entering_enic'), candidate_interface_course_choices_course_review_and_submit_path(@application_choice.id)) %> +
+
+
diff --git a/app/views/candidate_interface/course_choices/review_enic_interruption/show.html.erb b/app/views/candidate_interface/course_choices/review_enic_interruption/show.html.erb new file mode 100644 index 00000000000..e2b9220e302 --- /dev/null +++ b/app/views/candidate_interface/course_choices/review_enic_interruption/show.html.erb @@ -0,0 +1,10 @@ +<% content_for :title, t('page_titles.application_review_and_submit', provider_name: @application_choice.provider.name) %> +<% content_for(:before_content, govuk_back_link_to(candidate_interface_continuous_applications_choices_path)) %> + +<% if current_application.qualifications_enic_reasons_waiting_or_maybe? %> + <%= render 'waiting_maybe' %> +<% end %> + +<% if current_application.any_qualification_enic_reason_not_needed? %> + <%= render 'not_needed' %> +<% end %> diff --git a/app/views/candidate_interface/course_choices/review_interruption/show.html.erb b/app/views/candidate_interface/course_choices/review_interruption/show.html.erb index 140abe07f2b..805807bcaae 100644 --- a/app/views/candidate_interface/course_choices/review_interruption/show.html.erb +++ b/app/views/candidate_interface/course_choices/review_interruption/show.html.erb @@ -4,21 +4,26 @@
-

Give your application the best chance of success

-

Your personal statement is <%= "#{@word_count} #{'word'.pluralize(@word_count)}" %>.

-

90% of successful candidates write about <%= ApplicationForm::RECOMMENDED_PERSONAL_STATEMENT_WORD_COUNT %> words or more for their personal statement.

-

Increase your chances of getting an offer by adding more information to your personal statement.

+

<%= t('review_interruption.title') %>

+

<%= t('review_interruption.statement_count', word_count: "#{@word_count} #{'word'.pluralize(@word_count)}") %>

+

<%= t('review_interruption.success_percentage', word_count: ApplicationForm::RECOMMENDED_PERSONAL_STATEMENT_WORD_COUNT) %>

+

<%= t('review_interruption.increase_chances') %>

- Would you like to edit your personal statement before submitting your application? + <%= t('review_interruption.edit_statement') %>
- <%= govuk_button_to('Edit your personal statement', candidate_interface_edit_becoming_a_teacher_path, method: :get) %> - <%= govuk_link_to('Continue without editing', candidate_interface_course_choices_course_review_and_submit_path(@application_choice.id)) %> + <%= govuk_button_to(t('review_interruption.edit_statement_button_text'), candidate_interface_edit_becoming_a_teacher_path, method: :get) %> + + <% if current_application.qualifications_enic_reasons_waiting_or_maybe? || current_application.any_qualification_enic_reason_not_needed? %> + <%= govuk_link_to(t('review_interruption.continue_without_editing'), candidate_interface_course_choices_course_review_enic_interruption_path(@application_choice.id)) %> + <% else %> + <%= govuk_link_to(t('review_interruption.continue_without_editing'), candidate_interface_course_choices_course_review_and_submit_path(@application_choice.id)) %> + <% end %>
diff --git a/config/locales/candidate_interface/interruption.yml b/config/locales/candidate_interface/interruption.yml new file mode 100644 index 00000000000..67682d3799c --- /dev/null +++ b/config/locales/candidate_interface/interruption.yml @@ -0,0 +1,27 @@ +en: + review_interruption: + title: Give your application the best chance of success + statement_count: Your personal statement is %{word_count}. + success_percentage: 90% of successful candidates write about %{word_count} words or more for their personal statement. + increase_chances: Increase your chances of getting an offer by adding more information to your personal statement. + edit_statement: Would you like to edit your personal statement before submitting your application? + edit_statement_button_text: Edit your personal statement + continue_without_editing: Continue without editing + review_enic_interruption: + title: You have not included a UK ENIC reference number + waiting_maybe: + enic_link_text: apply for a statement of comparability from UK ENIC (opens in new tab) + planned_link_html: You have said you had, or planned to %{link} but you have not added the reference number to this application. + if_you_have_enic: If you have a UK ENIC reference number, you should add it to your qualifications details. + save_this_as_draft: save this application as a draft + save_as_draft_html: If you are still waiting then you can %{link} and come back to add your UK ENIC reference number later. + without_enic: You can also submit your application without the UK ENIC reference number and contact the training provider when it arrives. + enter_enic: Enter a UK ENIC number + without_entering_enic: Continue without adding a UK ENIC number + not_needed: + more_likely_html: Including a UK ENIC reference number in your application makes youn around 30% more likely to receive an offer. + apply_for_enic_link: apply for a UK ENIC statement of comparability (opens in new tab) + if_you_apply_enic_html: If you %{link} and include the reference number in your application it makes it easier for training providers to understand your qualifications. + dont_provide_enic: If you don’t include a UK ENIC statement of comparability and the provider asks for one, it could cause delays. + continue_button_text: Continue without a UK ENIC number + save_application_button_text: Save this application as a draft diff --git a/config/routes/candidate.rb b/config/routes/candidate.rb index c0989c408bc..9f6e0b1fa6c 100644 --- a/config/routes/candidate.rb +++ b/config/routes/candidate.rb @@ -361,6 +361,7 @@ get '/:application_choice_id/review' => 'course_choices/review#show', as: :course_choices_course_review get '/:application_choice_id/review-interruption' => 'course_choices/review_interruption#show', as: :course_choices_course_review_interruption + get '/:application_choice_id/review-enic-interruption' => 'course_choices/review_enic_interruption#show', as: :course_choices_course_review_enic_interruption get '/:application_choice_id/review-and-submit' => 'course_choices/review_and_submit#show', as: :course_choices_course_review_and_submit get '/blocked-submissions' => 'course_choices/blocked_submissions#show', as: :course_choices_blocked_submissions diff --git a/spec/models/application_form_spec.rb b/spec/models/application_form_spec.rb index 51da341c2ca..68598a5c8b7 100644 --- a/spec/models/application_form_spec.rb +++ b/spec/models/application_form_spec.rb @@ -333,6 +333,41 @@ end end + describe '#qualifications_enic_reasons_waiting_or_maybe?' do + it 'returns true if 1 or more qualifications have an enic_reason of waiting or maybe' do + application_form = create(:application_form) + create(:degree_qualification, enic_reference: '12345', institution_country: 'GB', enic_reason: 'waiting', application_form: application_form) + + expect(application_form.qualifications_enic_reasons_waiting_or_maybe?).to be(true) + end + + it 'returns false if no qualifications have an enic_reason of waiting or maybe' do + application_form = create(:application_form) + create(:degree_qualification, enic_reference: '12345', institution_country: 'GB', enic_reason: 'not_needed', application_form: application_form) + + expect(application_form.qualifications_enic_reasons_waiting_or_maybe?).to be(false) + end + end + + describe '#any_qualification_enic_reason_not_needed?' do + it 'returns true if ALL qualifications have an enic_reason of not_needed' do + application_form = create(:application_form) + create(:degree_qualification, enic_reference: '12345', institution_country: 'GB', enic_reason: 'not_needed', application_form: application_form) + create(:degree_qualification, enic_reference: '12346', institution_country: 'GB', enic_reason: 'not_needed', application_form: application_form) + create(:degree_qualification, enic_reference: '12347', institution_country: 'GB', enic_reason: 'not_needed', application_form: application_form) + + expect(application_form.any_qualification_enic_reason_not_needed?).to be(true) + end + + it 'returns false if any qualification has an enic_reason that is not_needed' do + application_form = create(:application_form) + create(:degree_qualification, enic_reference: '12345', institution_country: 'GB', enic_reason: 'not_needed', application_form: application_form) + create(:degree_qualification, enic_reference: '12348', institution_country: 'GB', enic_reason: 'obtained', application_form: application_form) + + expect(application_form.qualifications_enic_reasons_waiting_or_maybe?).to be(false) + end + end + describe '#missing_enic_reference_for_non_uk_qualifications?' do it 'returns false if there are no application_qualifications which are non_uk and have no enic_reference' do application_form = create(:application_form) diff --git a/spec/system/candidate_interface/submitting/candidate_submitting_application_with_interruption_pages_spec.rb b/spec/system/candidate_interface/submitting/candidate_submitting_application_with_interruption_pages_spec.rb new file mode 100644 index 00000000000..1d5a3dd4301 --- /dev/null +++ b/spec/system/candidate_interface/submitting/candidate_submitting_application_with_interruption_pages_spec.rb @@ -0,0 +1,144 @@ +require 'rails_helper' + +RSpec.describe 'Candidate submits the application with interruption pages' do + include CandidateHelper + include SignInHelper + + scenario 'Candidate submits an application with all applications having an enic_reason of not_needed and personal statement less than 500 words', :js, time: mid_cycle do + given_i_am_signed_in + + when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_not_needed_qualification + and_i_continue_with_my_application + + when_i_save_as_draft + and_i_am_redirected_to_the_application_dashboard + and_my_application_is_still_unsubmitted + and_i_continue_with_my_application + + when_i_click_to_review_my_application + then_i_see_a_interruption_page_for_personal_statement + when_i_continue_without_editing + then_i_see_a_interruption_page_for_not_needed_enic + then_the_viewed_enic_interruption_page_cookie_to_be_set + end + + scenario 'Candidate submits an application with an application having an enic_reason of maybe and personal statement less than 500 words', :js, time: mid_cycle do + given_i_am_signed_in + + when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_waiting_or_maybe_qualification + and_i_continue_with_my_application + + when_i_save_as_draft + and_i_am_redirected_to_the_application_dashboard + and_my_application_is_still_unsubmitted + and_i_continue_with_my_application + + when_i_click_to_review_my_application + then_i_see_a_interruption_page_for_personal_statement + when_i_continue_without_editing + then_i_see_a_interruption_page_for_waiting_or_maybe_enic + then_the_viewed_enic_interruption_page_cookie_to_be_set + end + + scenario 'Candidate submits an application with an application having an enic_reason of maybe and personal statement of 500 words', :js, time: mid_cycle do + given_i_am_signed_in + + when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_waiting_or_maybe_qualification_and_personal_statement_500_words + and_i_continue_with_my_application + + when_i_save_as_draft + and_i_am_redirected_to_the_application_dashboard + and_my_application_is_still_unsubmitted + and_i_continue_with_my_application + + when_i_click_to_review_my_application + then_i_see_a_interruption_page_for_waiting_or_maybe_enic + then_the_viewed_enic_interruption_page_cookie_to_be_set + end + + def when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_not_needed_qualification + given_i_have_a_primary_course_choice(application_form_completed: true, personal_statement_words: 4) + add_not_needed_qualification + end + + def when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_waiting_or_maybe_qualification + given_i_have_a_primary_course_choice(application_form_completed: true, personal_statement_words: 4) + add_waiting_or_maybe_qualification + end + + def when_i_have_completed_my_application_and_have_added_primary_as_a_course_choice_with_waiting_or_maybe_qualification_and_personal_statement_500_words + given_i_have_a_primary_course_choice(application_form_completed: true, personal_statement_words: 500) + add_waiting_or_maybe_qualification + end + + def given_i_have_a_primary_course_choice(application_form_completed:, personal_statement_words:) + completed_section_trait = application_form_completed.present? ? :completed : :minimum_info + + @provider = create(:provider, name: 'Gorse SCITT', code: '1N1') + site = create( + :site, + name: 'Main site', + code: '-', + provider: @provider, + address_line1: 'Gorse SCITT', + address_line2: 'C/O The Bruntcliffe Academy', + address_line3: 'Bruntcliffe Lane', + address_line4: 'MORLEY, lEEDS', + postcode: 'LS27 0LZ', + ) + @course = create(:course, :open, name: 'Primary', code: '2XT2', provider: @provider) + @course_option = create(:course_option, site:, course: @course) + current_candidate.application_forms.delete_all + current_candidate.application_forms << build(:application_form, completed_section_trait, becoming_a_teacher: Faker::Lorem.words(number: personal_statement_words)) + @application_choice = create(:application_choice, :unsubmitted, course_option: @course_option, application_form: current_candidate.current_application) + end + + def add_not_needed_qualification + @application_choice.application_form.application_qualifications << build(:application_qualification, enic_reason: 'not_needed') + end + + def add_waiting_or_maybe_qualification + @application_choice.application_form.application_qualifications << build(:application_qualification, enic_reason: 'maybe') + end + + def when_i_save_as_draft + click_link_or_button 'Save as draft' + end + + def and_my_application_is_still_unsubmitted + expect(@application_choice.reload).to be_unsubmitted + end + + def and_i_am_redirected_to_the_application_dashboard + expect(page).to have_content t('page_titles.application_dashboard') + expect(page).to have_content 'Gorse SCITT' + end + + def when_i_go_back + click_link_or_button 'Back' + end + + def then_i_see_a_interruption_page_for_personal_statement + expect(page).to have_content 'Your personal statement is 4 words.' + end + + def then_i_see_a_interruption_page_for_not_needed_enic + expect(page).to have_content 'You have not included a UK ENIC reference number' + expect(page).to have_content 'Including a UK ENIC reference number in your application makes youn around 30% more likely to receive an offer.' + expect(page).to have_current_path( + candidate_interface_course_choices_course_review_enic_interruption_path(@application_choice.id), + ) + end + + def then_i_see_a_interruption_page_for_waiting_or_maybe_enic + expect(page).to have_content 'You have not included a UK ENIC reference number' + expect(page).to have_content 'If you have a UK ENIC reference number, you should add it to your qualifications details.' + expect(page).to have_current_path( + candidate_interface_course_choices_course_review_enic_interruption_path(@application_choice.id), + ) + end + + def then_the_viewed_enic_interruption_page_cookie_to_be_set + expect(page.driver.browser.manage.cookie_named('viewed_enic_interruption_page')[:value]).to eq('true') + end +end