Skip to content

Commit

Permalink
Merge branch 'master' into select-claim-school-form
Browse files Browse the repository at this point in the history
  • Loading branch information
felixclack authored May 9, 2024
2 parents 6523cdf + cae7f9c commit 8ab1427
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 165 deletions.
13 changes: 1 addition & 12 deletions app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ def update
return
end

case params[:slug]
when "still-teaching"
check_still_teaching_params
else
current_claim.attributes = claim_params
end

current_claim.attributes = claim_params
current_claim.reset_dependent_answers unless params[:slug] == "select-mobile"
current_claim.reset_eligibility_dependent_answers(reset_attrs) unless params[:slug] == "qualification-details"

Expand Down Expand Up @@ -229,11 +223,6 @@ def no_eligible_itt_subject?
!current_claim.eligible_itt_subject
end

def check_still_teaching_params
updated_claim_params = StillTeachingForm.extract_params(claim_params)
current_claim.attributes = updated_claim_params
end

def retrieve_student_loan_details
# student loan details are currently retrieved for TSLR and ECP/LUPP journeys only
return unless ["student-loans", "additional-payments"].include?(current_journey_routing_name)
Expand Down
4 changes: 2 additions & 2 deletions app/forms/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def backlink_path
.claim_path(params[:journey], page_sequence.previous_slug)
end

def i18n_errors_path(msg)
def i18n_errors_path(msg, args = {})
base_key = :"forms.#{i18n_form_namespace}.errors.#{msg}"
I18n.t("#{i18n_namespace}.#{base_key}", default: base_key)
I18n.t("#{i18n_namespace}.#{base_key}", default: base_key, **args)
end

def permitted_params
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Journeys
module TeacherStudentLoanReimbursement
class StillTeachingForm < Form
attribute :employment_status
attribute :current_school_id

validates :employment_status, presence: {message: ->(form, _) { form.error_message }}

def save
return false unless valid?

update!(
eligibility_attributes: {
employment_status:,
current_school_id: currently_at_school? ? current_school_id : nil
}
)
end

def school
claim.logged_in_with_tid_and_has_recent_tps_school? ? claim.recent_tps_school : claim.eligibility.claim_school
end

def error_message
if school.open?
i18n_errors_path("select_which_school_currently", school_name: school.name)
else
i18n_errors_path("select_are_you_still_employed")
end
end

# Helper used in the view to choose partials and locale keys
def tps_or_claim_school
claim.logged_in_with_tid_and_has_recent_tps_school? ? "tps_school" : "claim_school"
end

private

def currently_at_school?
%w[claim_school recent_tps_school].include?(employment_status)
end
end
end
end
18 changes: 0 additions & 18 deletions app/forms/still_teaching_form.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/journeys/teacher_student_loan_reimbursement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module TeacherStudentLoanReimbursement
"qualification-details" => QualificationDetailsForm,
"qts-year" => QtsYearForm,
"subjects-taught" => SubjectsTaughtForm,
"still-teaching" => StillTeachingForm,
"leadership-position" => LeadershipPositionForm,
"mostly-performed-leadership-duties" => MostlyPerformedLeadershipDutiesForm,
"reset-claim" => ResetClaimForm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def claim_school

def current_school
[
t("student_loans.forms.still_teaching.questions.which_school_currently"),
t("student_loans.forms.still_teaching.questions.tps_school"),
eligibility.current_school_name,
"still-teaching"
]
Expand Down
2 changes: 1 addition & 1 deletion app/models/policies/student_loans/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Eligibility < ApplicationRecord
belongs_to :current_school, optional: true, class_name: "School"

validates :claim_school, on: [:"select-claim-school"], presence: {message: ->(object, _data) { object.select_claim_school_presence_error_message }}, unless: :claim_school_somewhere_else?
validates :employment_status, on: [:"still-teaching", :submit], presence: {message: ->(object, _data) { "Select if you still work at #{object.claim_school_name}, another school or no longer teach in England" }}
validates :employment_status, on: [:submit], presence: {message: ->(object, _data) { "Select if you still work at #{object.claim_school_name}, another school or no longer teach in England" }}
validates :had_leadership_position, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you were employed in a leadership position"}
validates :mostly_performed_leadership_duties, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you spent more than half your working hours on leadership duties"}, if: :had_leadership_position?
validates_numericality_of :student_loan_repayment_amount, message: "Enter a valid monetary amount", allow_nil: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 99999
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<% if claim_school.open? %>
<%= fields.hidden_field :current_school_id, value: claim_school.id %>
<% if school.open? %>
<%= form.hidden_field :current_school_id, value: school.id %>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :claim_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_claim_school, "Yes, at #{claim_school.name}", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :claim_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_claim_school, "Yes, at #{school.name}", class: "govuk-label govuk-radios__label" %>
</div>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_different_school, "Yes, at another school", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_different_school, "Yes, at another school", class: "govuk-label govuk-radios__label" %>
</div>
<% else %>
<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_different_school, "Yes", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_different_school, "Yes", class: "govuk-label govuk-radios__label" %>
</div>
<% end %>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :no_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_no_school, "No", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :no_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_no_school, "No", class: "govuk-label govuk-radios__label" %>
</div>
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<%= fields.hidden_field :current_school_id, value: current_school.id %>
<%= form.hidden_field :current_school_id, value: school.id %>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :recent_tps_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_recent_tps_school, "Yes, at #{current_school.name}", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :recent_tps_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_recent_tps_school, "Yes, at #{school.name}", class: "govuk-label govuk-radios__label" %>
<div id="school-checker-item-hint" class="govuk-hint govuk-radios__hint">
<%= current_school.address %>
<%= school.address %>
</div>
</div>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_different_school, "Somewhere else", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :different_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_different_school, "Somewhere else", class: "govuk-label govuk-radios__label" %>
</div>

<div class="govuk-radios__divider">or</div>

<div class="govuk-radios__item">
<%= fields.radio_button(:employment_status, :no_school, class: "govuk-radios__input") %>
<%= fields.label :employment_status_no_school, "I'm no longer employed to teach at a state-funded secondary school in England", class: "govuk-label govuk-radios__label" %>
<%= form.radio_button(:employment_status, :no_school, class: "govuk-radios__input") %>
<%= form.label :employment_status_no_school, "I'm no longer employed to teach at a state-funded secondary school in England", class: "govuk-label govuk-radios__label" %>
</div>
38 changes: 14 additions & 24 deletions app/views/student_loans/claims/still_teaching.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
<% content_for(:page_title, page_title(t("student_loans.questions.employment_status"), journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %>
<% content_for(:page_title, page_title(t("student_loans.forms.still_teaching.questions.#{@form.tps_or_claim_school}"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render("shared/error_summary", instance: current_claim, errored_field_id_overrides: { "eligibility.employment_status": "claim_eligibility_attributes_employment_status_claim_school" }) if current_claim.errors.any? %>
<%= render("shared/error_summary", instance: @form, errored_field_id_overrides: { "employment_status": "claim_employment_status_claim_school" }) if @form.errors.any? %>

<%= form_for current_claim, url: claim_path(current_journey_routing_name) do |form| %>
<%= form_group_tag current_claim do %>
<%= form.fields_for :eligibility, include_id: false do |fields| %>
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<% if current_claim.logged_in_with_tid_and_has_recent_tps_school? %>
<h1 class="govuk-fieldset__heading"><%= t("student_loans.forms.still_teaching.questions.which_school_currently") %></h1>
<% else %>
<h1 class="govuk-fieldset__heading"><%= t("student_loans.questions.employment_status") %></h1>
<% end %>
</legend>
<%= form_for @form, url: claim_path(current_journey_routing_name) do |form| %>
<%= form_group_tag @form do %>
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading"><%= t("student_loans.forms.still_teaching.questions.#{@form.tps_or_claim_school}") %></h1>
</legend>

<%= errors_tag current_claim.eligibility, :employment_status %>
<%= errors_tag @form, :employment_status %>

<div class="govuk-radios">
<%= fields.hidden_field :employment_status %>
<div class="govuk-radios">
<%= form.hidden_field :employment_status %>

<% if current_claim.logged_in_with_tid_and_has_recent_tps_school? %>
<%= render partial: "still_teaching_with_tps_school", locals: { current_claim: current_claim, fields: fields, current_school: current_claim.recent_tps_school } %>
<% else %>
<%= render partial: "still_teaching_with_claim_school", locals: { current_claim: current_claim, fields: fields, claim_school: current_claim.eligibility.claim_school } %>
<% end %>
</div>
</fieldset>
<% end %>
<%= render partial: "still_teaching_with_#{@form.tps_or_claim_school}", locals: { current_claim: @form.claim, form: form, school: @form.school } %>
</div>
</fieldset>
<% end %>
<%= form.submit "Continue", class: "govuk-button" %>
<% end %>
Expand Down
8 changes: 6 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ en:
select_subject: Select if you taught Biology, Chemistry, Physics, Computing, Languages or you did not teach any of these subjects
still_teaching:
questions:
which_school_currently: "Which school are you currently employed to teach at?"
tps_school: Which school are you currently employed to teach at?
claim_school: Are you still employed to teach at a school in England?
errors:
select_which_school_currently:
Select if you still work at %{school_name}, another school or no longer teach in England
select_are_you_still_employed: Select yes if you are still employed to teach at a school in England
teacher_reference_number:
questions:
teacher_reference_number: "What is your teacher reference number (TRN)?"
Expand All @@ -349,7 +354,6 @@ en:
questions:
academic_year: "Academic year you completed your Initial Teacher Training (ITT)"
claim_school_select_error: "Select the school you taught at between %{financial_year}"
employment_status: "Are you still employed to teach at a school in England?"
subjects_taught: "Which of the following subjects did you teach at %{school} between %{financial_year}?"
eligible_subjects:
biology_taught: "Biology"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

check "Physics"
click_on "Continue"
expect(page).to have_text(I18n.t("student_loans.questions.employment_status"))
expect(page).to have_text(I18n.t("student_loans.forms.still_teaching.questions.claim_school"))

choose_still_teaching("Yes, at #{school.name}")
expect(page).to have_text(leadership_position_question)
Expand Down
4 changes: 2 additions & 2 deletions spec/features/student_loans_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def answer_eligibility_questions_and_fill_in_personal_details

check "Physics"
click_on "Continue"
expect(page).to have_text(I18n.t("student_loans.questions.employment_status"))
expect(page).to have_text(I18n.t("student_loans.forms.still_teaching.questions.claim_school"))

choose_still_teaching("Yes, at #{school.name}")
expect(claim.eligibility.reload.employment_status).to eql("claim_school")
Expand Down Expand Up @@ -274,7 +274,7 @@ def fill_in_remaining_personal_details_and_submit

check "Physics"
click_on "Continue"
expect(page).to have_text(I18n.t("student_loans.questions.employment_status"))
expect(page).to have_text(I18n.t("student_loans.forms.still_teaching.questions.claim_school"))

choose_still_teaching("Yes, at #{school.name}")
expect(claim.eligibility.reload.employment_status).to eql("claim_school")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def navigate_to_check_email_page(school:)
click_on "Continue"

# - Are you still employed to teach at
expect(page).to have_text(I18n.t("student_loans.questions.employment_status"))
expect(page).to have_text(I18n.t("student_loans.forms.still_teaching.questions.claim_school"))
choose_still_teaching("Yes, at #{school.name}")

# - leadership-position question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
end

scenario "Selects school" do
# - "Selects suggested school retrieved from TPS" do
navigate_to_still_teaching_page

# - Tries to continue without selecting option
click_on "Continue"
expect(page).to have_text("Select if you still work at #{eligible_school.name}, another school or no longer teach in England")

# - Selects suggested school retrieved from TPS
choose(eligible_school.name)
click_on "Continue"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def navigate_to_teacher_reference_number_page(school:)
click_on "Continue"

# - Are you still employed to teach at
expect(page).to have_text(I18n.t("student_loans.questions.employment_status"))
expect(page).to have_text(I18n.t("student_loans.forms.still_teaching.questions.claim_school"))
choose_still_teaching("Yes, at #{school.name}")

# - leadership-position question
Expand Down
11 changes: 11 additions & 0 deletions spec/forms/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ def initialize(claim)
expect(I18n).to have_received(:t)
.with("test_i18n_ns.forms.test_slug.errors.message", default: :"forms.test_slug.errors.message")
end

context "when more arguments are supplied" do
before do
form.i18n_errors_path("message", school_name: "Academy for Lizards")
end

it do
expect(I18n).to have_received(:t)
.with("test_i18n_ns.forms.test_slug.errors.message", default: :"forms.test_slug.errors.message", school_name: "Academy for Lizards")
end
end
end

describe "#permitted_params" do
Expand Down
Loading

0 comments on commit 8ab1427

Please sign in to comment.