Skip to content

Commit

Permalink
Adds the trainee details page
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjlynch committed Jun 20, 2024
1 parent 94c6cd9 commit fea3664
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion app/models/journeys/get_a_teacher_relocation_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SlugSequence
ELIGIBILITY_SLUGS = [
"application-route",
"state-funded-secondary-school",
"trainee-details",
"check-your-answers-part-one"
]

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
)
) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= 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 %>
</div>
</div>


18 changes: 18 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<ul>
<li>pay a salary</li>
<li>lead to qualified teacher status (QTS)</li>
<li>be accredited by the UK government</li>
</ul>
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit fea3664

Please sign in to comment.