Skip to content

Commit

Permalink
Adds the contract details page
Browse files Browse the repository at this point in the history
The contract details page in IRP write to the `one_year` attribute, so
that's what we've done too.
  • Loading branch information
rjlynch committed Jun 20, 2024
1 parent 80c30bb commit 4a1aacc
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def save

if application_route_changed?
journey_session.answers.assign_attributes(
state_funded_secondary_school: nil
state_funded_secondary_school: nil,
one_year: nil
)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Journeys
module GetATeacherRelocationPayment
class ContractDetailsForm < Form
attribute :one_year, :boolean

validates :one_year,
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(one_year: one_year)

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 @@ -11,7 +11,8 @@ module GetATeacherRelocationPayment
"claims" => {
"application-route" => ApplicationRouteForm,
"state-funded-secondary-school" => StateFundedSecondarySchoolForm,
"trainee-details" => TraineeDetailsForm
"trainee-details" => TraineeDetailsForm,
"contract-details" => ContractDetailsForm
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class AnswersPresenter < BaseAnswersPresenter
def eligibility_answers
[].tap do |a|
a << application_route
a << if answers.trainee?
trainee_details
if answers.trainee?
a << trainee_details
else
state_funded_secondary_school
a << state_funded_secondary_school
a << contract_details
end
end.compact
end
Expand Down Expand Up @@ -39,6 +40,14 @@ def trainee_details
"trainee-details"
]
end

def contract_details
[
t("get_a_teacher_relocation_payment.forms.contract_details.question"),
t("get_a_teacher_relocation_payment.forms.contract_details.answers.#{answers.one_year}.answer"),
"contract-details"
]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module GetATeacherRelocationPayment
class SessionAnswers < Journeys::SessionAnswers
attribute :application_route, :string
attribute :state_funded_secondary_school, :boolean
attribute :one_year, :boolean

def trainee?
application_route == "salaried_trainee"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SlugSequence
"application-route",
"state-funded-secondary-school",
"trainee-details",
"contract-details",
"check-your-answers-part-one"
]

Expand Down Expand Up @@ -35,6 +36,7 @@ def slugs
SLUGS.dup.tap do |sequence|
if answers.trainee?
sequence.delete("state-funded-secondary-school")
sequence.delete("contract-details")
else
sequence.delete("trainee-details")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def ineligible_reason
"application route other not accecpted"
in state_funded_secondary_school: false
"school not state funded"
in application_route: "teacher", one_year: false
"teacher contract duration of less than one year not accepted"
else
nil
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.contract_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(
:one_year,
f.object.available_options,
-> (option) { option },
-> (option) { t("get_a_teacher_relocation_payment.forms.contract_details.answers.#{option}.answer") },
legend: { text: t("get_a_teacher_relocation_payment.forms.contract_details.question") },
hint: { text: t("get_a_teacher_relocation_payment.forms.contract_details.hint") }
) %>

<%= f.govuk_submit %>
<% end %>
</div>
</div>


1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ shared:
- updated_at
- application_route
- state_funded_secondary_school
- one_year
:schools:
- id
- urn
Expand Down
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,16 @@ en:
answer: "No"
errors:
inclusion: "Select the option that applies to you"
contract_details:
question: "Are you employed on a contract lasting at least one year?"
hint: "Your contract can also be ongoing or permanent."
answers:
true:
answer: "Yes"
false:
answer: "No"
errors:
inclusion: "Select the option that applies to you"

check_your_answers:
part_one:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOneYearToInternationalRelocationPaymentsEligibilities < ActiveRecord::Migration[7.0]
def change
add_column :international_relocation_payments_eligibilities, :one_year, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_06_20_085756) do
ActiveRecord::Schema[7.0].define(version: 2024_06_20_124504) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -185,6 +185,7 @@
t.datetime "updated_at", null: false
t.string "application_route"
t.boolean "state_funded_secondary_school"
t.boolean "one_year"
end

create_table "journey_configurations", primary_key: "routing_name", id: :string, force: :cascade do |t|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
state_funded_secondary_school { true }
end

trait :with_one_year_contract do
one_year { true }
end

trait :with_email_details do
email_address { generate(:email_address) }
email_verified { true }
Expand All @@ -40,6 +44,7 @@
trait :eligible_teacher do
with_teacher_application_route
with_state_funded_secondary_school
with_one_year_contract
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
then_i_see_the_ineligible_page
end
end

context "ineligible - contract details" do
it "shows the ineligible page" do
when_i_start_the_form
and_i_complete_application_route_question_with(
option: "I am employed as a teacher in a school in England"
)
and_i_complete_the_state_funded_secondary_school_step_with(option: "Yes")
and_i_complete_the_contract_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 @@ -14,6 +14,7 @@
option: "I am employed as a teacher in a school in England"
)
and_i_complete_the_state_funded_secondary_school_step_with(option: "Yes")
and_i_complete_the_contract_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
Expand All @@ -31,5 +32,8 @@ def then_the_check_your_answers_part_one_page_shows_my_answers
expect(page).to have_text(
"Are you employed by an English state secondary school? Yes"
)
expect(page).to have_text(
"Are you employed on a contract lasting at least one year? Yes"
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
before do
journey_session.answers.assign_attributes(
application_route: existing_option,
state_funded_secondary_school: true
state_funded_secondary_school: true,
one_year: true
)
journey_session.save!
end
Expand All @@ -55,6 +56,10 @@
change { journey_session.reload.answers.state_funded_secondary_school }
.from(true)
.to(nil)
).and(
change { journey_session.reload.answers.one_year }
.from(true)
.to(nil)
)
end
end
Expand All @@ -63,8 +68,10 @@
let(:existing_option) { option }

it "doesn't reset dependent answers if the value hasn't changed" do
expect { expect(form.save).to be(true) }.not_to(
change { journey_session.reload.answers.state_funded_secondary_school }
expect { expect(form.save).to be(true) }.to(
not_change { journey_session.reload.answers.state_funded_secondary_school }
).and(
not_change { journey_session.reload.answers.one_year }
)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "rails_helper"

RSpec.describe Journeys::GetATeacherRelocationPayment::ContractDetailsForm, type: :model do
let(:journey_session) { create(:get_a_teacher_relocation_payment_session) }

let(:params) do
ActionController::Parameters.new(
claim: {
one_year: 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(:one_year)
.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.one_year }
.to(true)
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
build(
:get_a_teacher_relocation_payment_answers,
:with_teacher_application_route,
:with_state_funded_secondary_school
:with_state_funded_secondary_school,
:with_one_year_contract
)
end

Expand All @@ -30,6 +31,11 @@
"Are you employed by an English state secondary school?",
"Yes",
"state-funded-secondary-school"
],
[
"Are you employed on a contract lasting at least one year?",
"Yes",
"contract-details"
]
)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/support/get_a_teacher_relocation_payment/step_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def and_i_complete_the_trainee_details_step_with(option:)
click_button("Continue")
end

def and_i_complete_the_contract_details_step_with(option:)
assert_on_contract_details_page!

choose(option)

click_button("Continue")
end

def and_i_dont_change_my_answers
click_button("Continue")
end
Expand Down Expand Up @@ -85,6 +93,10 @@ def assert_on_check_your_answers_page!
expect(page).to have_text("Check your answers before sending your application")
end

def assert_on_contract_details_page!
expect(page).to have_text("Are you employed on a contract lasting at least one year?")
end

def assert_application_is_submitted!
expect(page).to have_content("Claim submitted")
expect(page).to have_content(
Expand Down

0 comments on commit 4a1aacc

Please sign in to comment.