From fea36647cb6ce6a7cad90269bbddbd47638e6045 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Thu, 20 Jun 2024 11:36:56 +0100 Subject: [PATCH] Adds the trainee details page In IRP the trainee details page writes it's value to the state_funded_secondary_school so we've preserved this behaviour with the trainee details form writing to this field. --- .../trainee_details_form.rb | 27 ++++++++ .../get_a_teacher_relocation_payment.rb | 3 +- .../answers_presenter.rb | 14 +++- .../session_answers.rb | 4 ++ .../slug_sequence.rb | 9 ++- .../claims/trainee_details.html.erb | 34 ++++++++++ config/locales/en.yml | 18 +++++ ...et_a_teacher_relocation_payment_answers.rb | 16 ++--- ...eligible_route_completing_the_form_spec.rb | 11 ++++ .../trainee_route_completing_the_form_spec.rb | 11 ++-- .../trainee_details_form_spec.rb | 46 +++++++++++++ .../answers_presenter_spec.rb | 65 +++++++++++++------ .../step_helpers.rb | 19 +++++- 13 files changed, 240 insertions(+), 37 deletions(-) create mode 100644 app/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form.rb create mode 100644 app/views/get_a_teacher_relocation_payment/claims/trainee_details.html.erb create mode 100644 spec/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form_spec.rb diff --git a/app/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form.rb b/app/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form.rb new file mode 100644 index 0000000000..649c07806f --- /dev/null +++ b/app/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form.rb @@ -0,0 +1,27 @@ +module Journeys + module GetATeacherRelocationPayment + class TraineeDetailsForm < Form + attribute :state_funded_secondary_school, :boolean + + validates :state_funded_secondary_school, + inclusion: { + in: [true, false], + message: i18n_error_message(:inclusion) + } + + def available_options + [true, false] + end + + def save + return false unless valid? + + journey_session.answers.assign_attributes( + state_funded_secondary_school: state_funded_secondary_school + ) + + journey_session.save! + end + end + end +end diff --git a/app/models/journeys/get_a_teacher_relocation_payment.rb b/app/models/journeys/get_a_teacher_relocation_payment.rb index b559c37da7..1cdd9fce83 100644 --- a/app/models/journeys/get_a_teacher_relocation_payment.rb +++ b/app/models/journeys/get_a_teacher_relocation_payment.rb @@ -10,7 +10,8 @@ module GetATeacherRelocationPayment FORMS = { "claims" => { "application-route" => ApplicationRouteForm, - "state-funded-secondary-school" => StateFundedSecondarySchoolForm + "state-funded-secondary-school" => StateFundedSecondarySchoolForm, + "trainee-details" => TraineeDetailsForm } } end diff --git a/app/models/journeys/get_a_teacher_relocation_payment/answers_presenter.rb b/app/models/journeys/get_a_teacher_relocation_payment/answers_presenter.rb index e30bd3cee4..68374663a0 100644 --- a/app/models/journeys/get_a_teacher_relocation_payment/answers_presenter.rb +++ b/app/models/journeys/get_a_teacher_relocation_payment/answers_presenter.rb @@ -6,7 +6,11 @@ class AnswersPresenter < BaseAnswersPresenter def eligibility_answers [].tap do |a| a << application_route - a << state_funded_secondary_school + a << if answers.trainee? + trainee_details + else + state_funded_secondary_school + end end.compact end @@ -27,6 +31,14 @@ def state_funded_secondary_school "state-funded-secondary-school" ] end + + def trainee_details + [ + t("get_a_teacher_relocation_payment.forms.trainee_details.question"), + t("get_a_teacher_relocation_payment.forms.trainee_details.answers.#{answers.state_funded_secondary_school}.answer"), + "trainee-details" + ] + end end end end diff --git a/app/models/journeys/get_a_teacher_relocation_payment/session_answers.rb b/app/models/journeys/get_a_teacher_relocation_payment/session_answers.rb index 825291cb7f..55321f7c6b 100644 --- a/app/models/journeys/get_a_teacher_relocation_payment/session_answers.rb +++ b/app/models/journeys/get_a_teacher_relocation_payment/session_answers.rb @@ -3,6 +3,10 @@ module GetATeacherRelocationPayment class SessionAnswers < Journeys::SessionAnswers attribute :application_route, :string attribute :state_funded_secondary_school, :boolean + + def trainee? + application_route == "salaried_trainee" + end end end end diff --git a/app/models/journeys/get_a_teacher_relocation_payment/slug_sequence.rb b/app/models/journeys/get_a_teacher_relocation_payment/slug_sequence.rb index f52149711e..6feb4fcc6b 100644 --- a/app/models/journeys/get_a_teacher_relocation_payment/slug_sequence.rb +++ b/app/models/journeys/get_a_teacher_relocation_payment/slug_sequence.rb @@ -4,6 +4,7 @@ class SlugSequence ELIGIBILITY_SLUGS = [ "application-route", "state-funded-secondary-school", + "trainee-details", "check-your-answers-part-one" ] @@ -31,7 +32,13 @@ def initialize(journey_session) end def slugs - SLUGS + SLUGS.dup.tap do |sequence| + if answers.trainee? + sequence.delete("state-funded-secondary-school") + else + sequence.delete("trainee-details") + end + end end end end diff --git a/app/views/get_a_teacher_relocation_payment/claims/trainee_details.html.erb b/app/views/get_a_teacher_relocation_payment/claims/trainee_details.html.erb new file mode 100644 index 0000000000..0969bad3ac --- /dev/null +++ b/app/views/get_a_teacher_relocation_payment/claims/trainee_details.html.erb @@ -0,0 +1,34 @@ +<% content_for( + :page_title, + page_title( + t("get_a_teacher_relocation_payment.forms.trainee_details.question"), + journey: current_journey_routing_name, + show_error: @form.errors.any? + ) +) %> +
+
+ <%= form_for( + @form, + url: claim_path(current_journey_routing_name), + builder: GOVUKDesignSystemFormBuilder::FormBuilder + ) do |f| %> + <% if f.object.errors.any? %> + <%= render("shared/error_summary", instance: f.object) %> + <% end %> + + <%= f.govuk_collection_radio_buttons( + :state_funded_secondary_school, + f.object.available_options, + -> (option) { option }, + -> (option) { t("get_a_teacher_relocation_payment.forms.trainee_details.answers.#{option}.answer") }, + legend: { text: t("get_a_teacher_relocation_payment.forms.trainee_details.question") }, + hint: { html: t("get_a_teacher_relocation_payment.forms.trainee_details.hint_html") } + ) %> + + <%= f.govuk_submit %> + <% end %> +
+
+ + diff --git a/config/locales/en.yml b/config/locales/en.yml index d13c40c9ed..1b2810bb99 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -707,6 +707,24 @@ en: answer: "No" errors: inclusion: "Select the option that applies to you" + trainee_details: + question: "Are you on a teacher training course in England which meets the following conditions?" + hint_html: > + The course must: + + Check with your training provider if you're not sure. + answers: + true: + answer: "Yes" + false: + answer: "No" + errors: + inclusion: "Select the option that applies to you" + check_your_answers: part_one: primary_heading: "Check your answers" diff --git a/spec/factories/journeys/get_a_teacher_relocation_payment/get_a_teacher_relocation_payment_answers.rb b/spec/factories/journeys/get_a_teacher_relocation_payment/get_a_teacher_relocation_payment_answers.rb index ebe90bb712..c3238336e5 100644 --- a/spec/factories/journeys/get_a_teacher_relocation_payment/get_a_teacher_relocation_payment_answers.rb +++ b/spec/factories/journeys/get_a_teacher_relocation_payment/get_a_teacher_relocation_payment_answers.rb @@ -7,10 +7,14 @@ national_insurance_number { generate(:national_insurance_number) } end - trait :with_application_route do + trait :with_teacher_application_route do application_route { "teacher" } end + trait :with_trainee_application_route do + application_route { "salaried_trainee" } + end + trait :with_state_funded_secondary_school do state_funded_secondary_school { true } end @@ -34,16 +38,8 @@ end trait :eligible_teacher do - with_application_route + with_teacher_application_route with_state_funded_secondary_school end - - trait :submitable do - eligible_teacher - with_personal_details - with_email_details - with_mobile_details - with_bank_details - end end end diff --git a/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb b/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb index afaa2516fc..faed877cfe 100644 --- a/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb +++ b/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb @@ -26,6 +26,17 @@ then_i_see_the_ineligible_page end end + + context "ineligible - trainee details" do + it "shows the ineligible page" do + when_i_start_the_form + and_i_complete_application_route_question_with( + option: "I am enrolled on a salaried teacher training course in England" + ) + and_i_complete_the_trainee_details_step_with(option: "No") + then_i_see_the_ineligible_page + end + end end def then_i_see_the_ineligible_page diff --git a/spec/features/get_a_teacher_relocation_payment/trainee_route_completing_the_form_spec.rb b/spec/features/get_a_teacher_relocation_payment/trainee_route_completing_the_form_spec.rb index 02baa149d6..02d3382873 100644 --- a/spec/features/get_a_teacher_relocation_payment/trainee_route_completing_the_form_spec.rb +++ b/spec/features/get_a_teacher_relocation_payment/trainee_route_completing_the_form_spec.rb @@ -7,16 +7,15 @@ create(:journey_configuration, :get_a_teacher_relocation_payment) end - # FIXME RL temp disabling this form as the teacher journey has a different - # second page - xdescribe "navigating forward" do + describe "navigating forward" do it "submits an application" do when_i_start_the_form and_i_complete_application_route_question_with( option: "I am enrolled on a salaried teacher training course in England" ) - # TODO RL: this journey has a different second page + and_i_complete_the_trainee_details_step_with(option: "Yes") then_the_check_your_answers_part_one_page_shows_my_answers + and_i_dont_change_my_answers and_the_personal_details_section_has_been_temporarily_stubbed and_i_submit_the_application @@ -30,5 +29,9 @@ def then_the_check_your_answers_part_one_page_shows_my_answers expect(page).to have_text( "What is your employment status? I am enrolled on a salaried teacher training course in England" ) + + expect(page).to have_text( + "Are you on a teacher training course in England which meets the following conditions? Yes" + ) end end diff --git a/spec/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form_spec.rb b/spec/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form_spec.rb new file mode 100644 index 0000000000..a8aa3e29a1 --- /dev/null +++ b/spec/forms/journeys/get_a_teacher_relocation_payment/trainee_details_form_spec.rb @@ -0,0 +1,46 @@ +require "rails_helper" + +RSpec.describe Journeys::GetATeacherRelocationPayment::TraineeDetailsForm, type: :model do + let(:journey_session) { create(:get_a_teacher_relocation_payment_session) } + + let(:params) do + ActionController::Parameters.new( + claim: { + state_funded_secondary_school: option + } + ) + end + + let(:form) do + described_class.new( + journey_session: journey_session, + journey: Journeys::GetATeacherRelocationPayment, + params: params + ) + end + + describe "validations" do + subject { form } + + let(:option) { nil } + + it do + is_expected.not_to( + allow_value(nil) + .for(:state_funded_secondary_school) + .with_message("Select the option that applies to you") + ) + end + end + + describe "#save" do + let(:option) { true } + + it "updates the journey session" do + expect { expect(form.save).to be(true) }.to( + change { journey_session.reload.answers.state_funded_secondary_school } + .to(true) + ) + end + end +end diff --git a/spec/models/journeys/get_a_teacher_relocation_payment/answers_presenter_spec.rb b/spec/models/journeys/get_a_teacher_relocation_payment/answers_presenter_spec.rb index 8c9f5c5572..05309f5876 100644 --- a/spec/models/journeys/get_a_teacher_relocation_payment/answers_presenter_spec.rb +++ b/spec/models/journeys/get_a_teacher_relocation_payment/answers_presenter_spec.rb @@ -10,27 +10,54 @@ describe "#eligibility_answers" do subject { presenter.eligibility_answers } - let(:answers) do - build( - :get_a_teacher_relocation_payment_answers, - :with_application_route, - :with_state_funded_secondary_school - ) + context "when a teacher application" do + let(:answers) do + build( + :get_a_teacher_relocation_payment_answers, + :with_teacher_application_route, + :with_state_funded_secondary_school + ) + end + + it do + is_expected.to include( + [ + "What is your employment status?", + "I am employed as a teacher in a school in England", + "application-route" + ], + [ + "Are you employed by an English state secondary school?", + "Yes", + "state-funded-secondary-school" + ] + ) + end end - it do - is_expected.to include( - [ - "What is your employment status?", - "I am employed as a teacher in a school in England", - "application-route" - ], - [ - "Are you employed by an English state secondary school?", - "Yes", - "state-funded-secondary-school" - ] - ) + context "when a trainee application" do + let(:answers) do + build( + :get_a_teacher_relocation_payment_answers, + :with_trainee_application_route, + :with_state_funded_secondary_school + ) + end + + it do + is_expected.to include( + [ + "What is your employment status?", + "I am enrolled on a salaried teacher training course in England", + "application-route" + ], + [ + "Are you on a teacher training course in England which meets the following conditions?", + "Yes", + "trainee-details" + ] + ) + end end end end diff --git a/spec/support/get_a_teacher_relocation_payment/step_helpers.rb b/spec/support/get_a_teacher_relocation_payment/step_helpers.rb index 7164cb4718..7699d0c942 100644 --- a/spec/support/get_a_teacher_relocation_payment/step_helpers.rb +++ b/spec/support/get_a_teacher_relocation_payment/step_helpers.rb @@ -23,7 +23,10 @@ def and_the_personal_details_section_has_been_temporarily_stubbed journey_session.answers.assign_attributes( attributes_for( :get_a_teacher_relocation_payment_answers, - :submitable, + :with_personal_details, + :with_email_details, + :with_mobile_details, + :with_bank_details, email_address: "test-irp-claim@example.com", teacher_reference_number: "1234567", payroll_gender: "male" @@ -46,6 +49,14 @@ def and_i_complete_the_state_funded_secondary_school_step_with(option:) click_button("Continue") end + def and_i_complete_the_trainee_details_step_with(option:) + assert_on_trainee_details_page! + + choose(option) + + click_button("Continue") + end + def and_i_dont_change_my_answers click_button("Continue") end @@ -60,6 +71,12 @@ def assert_on_state_funded_secondary_school_page! ) end + def assert_on_trainee_details_page! + expect(page).to have_text( + "Are you on a teacher training course in England which meets the following conditions?" + ) + end + def assert_on_check_your_answers_part_one_page! expect(page).to have_text("Check your answers") end