Skip to content

Commit

Permalink
Merge pull request #2725 from DFE-Digital/CAPT-1600
Browse files Browse the repository at this point in the history
CAPT-1600 Form object for /subjects-taught (TSLR)
  • Loading branch information
your authored May 7, 2024
2 parents efeca04 + 5a823a5 commit b6fe794
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 165 deletions.
35 changes: 0 additions & 35 deletions app/assets/javascripts/components/subjects_taught.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/controllers/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def show

if params[:slug] == "select-claim-school"
update_session_with_tps_school(current_claim.tps_school_for_student_loan_in_previous_financial_year)
elsif params[:slug] == "subjects-taught" && page_sequence.in_sequence?("select-claim-school")
@backlink_path = claim_path(current_journey_routing_name, "select-claim-school")
elsif params[:slug] == "postcode-search" && postcode
redirect_to claim_path(current_journey_routing_name, "select-home-address", {"claim[postcode]": params[:claim][:postcode], "claim[address_line_1]": params[:claim][:address_line_1]}) and return unless invalid_postcode?
elsif params[:slug] == "select-home-address" && postcode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Journeys
module TeacherStudentLoanReimbursement
class SubjectsTaughtForm < Form
attr_accessor :subjects_taught

attribute :taught_eligible_subjects, :boolean
attribute :biology_taught, :boolean
attribute :chemistry_taught, :boolean
attribute :physics_taught, :boolean
attribute :computing_taught, :boolean
attribute :languages_taught, :boolean

validate :one_subject_must_be_selected

before_validation :determine_dependant_attributes

def save
return false unless valid?

update!(eligibility_attributes: attributes)
end

def claim_school_name
@claim_school_name ||= claim.eligibility.claim_school_name
end

def subject_attributes
Policies::StudentLoans::Eligibility::SUBJECT_ATTRIBUTES
end

def subject_taught_selected?(subject)
public_send(subject) == true if respond_to?(subject)
end

private

def determine_dependant_attributes
subject_attributes.each(&method(:update_subject_taught_attribute))
assign_attributes(taught_eligible_subjects: selected_subjects.empty? ? nil : !no_subject_taught_selected?)
end

def update_subject_taught_attribute(subject)
assign_attributes(subject => subject.to_s.in?(selected_subjects))
end

def no_subject_taught_selected?
"none_taught".in?(selected_subjects)
end

def selected_subjects
permitted_params.fetch(:subjects_taught, [])
end

def permitted_params
@permitted_params ||= params.fetch(:claim, {}).permit(subjects_taught: [])
end

def any_subjects_taught_selected?
subject_attributes.any?(&method(:subject_taught_selected?))
end

def not_taught_eligible_subjects?
taught_eligible_subjects == false
end

def one_subject_must_be_selected
return if not_taught_eligible_subjects? || any_subjects_taught_selected?

errors.add(:subjects_taught, i18n_errors_path(:select_subject))
end
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/student_loans_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def claim_school_question(additional_school: false)
# Accepts a `school_name` named parameter that is the school that the claimant
# was teaching at during the financial year.
def subjects_taught_question(school_name:)
translate("student_loans.questions.subjects_taught", school: school_name, financial_year: Policies::StudentLoans.current_financial_year)
translate("student_loans.forms.subjects_taught.questions.subjects_taught", school: school_name, financial_year: Policies::StudentLoans.current_financial_year)
end

# Returns the question for the leadership-position question in the Student
Expand Down
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 @@ -14,6 +14,7 @@ module TeacherStudentLoanReimbursement
"claim-school" => ClaimSchoolForm,
"qualification-details" => QualificationDetailsForm,
"qts-year" => QtsYearForm,
"subjects-taught" => SubjectsTaughtForm,
"leadership-position" => LeadershipPositionForm,
"mostly-performed-leadership-duties" => MostlyPerformedLeadershipDutiesForm
}
Expand Down
5 changes: 0 additions & 5 deletions app/models/policies/student_loans/eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Eligibility < ApplicationRecord

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" }}
validate :one_subject_must_be_selected, on: [:"subjects-taught", :submit], unless: :not_taught_eligible_subjects?
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 Expand Up @@ -136,10 +135,6 @@ def made_zero_repayments?
claim.present? && claim.has_student_loan == true && student_loan_repayment_amount == 0
end

def one_subject_must_be_selected
errors.add(:subjects_taught, "Select if you taught Biology, Chemistry, Physics, Computing, Languages or you did not teach any of these subjects") if subjects_taught.empty?
end

def ineligible_current_school?
current_school.present? && !current_school.eligible_for_student_loans_as_current_school?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/policies/student_loans/presenter_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def qts_award_year_answer(eligibility)

def subject_list(subjects)
connector = " and "
translated_subjects = subjects.map { |subject| I18n.t("student_loans.questions.eligible_subjects.#{subject}") }
translated_subjects = subjects.map { |subject| I18n.t("student_loans.forms.subjects_taught.answers.#{subject}") }
translated_subjects.sort.to_sentence(
last_word_connector: connector,
two_words_connector: connector
Expand Down
46 changes: 0 additions & 46 deletions app/views/additional_payments/claims/disciplinary_action.html.erb

This file was deleted.

56 changes: 26 additions & 30 deletions app/views/student_loans/claims/subjects_taught.html.erb
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
<% content_for(:page_title, page_title(subjects_taught_question(school_name: current_claim.eligibility.claim_school_name), journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %>
<% content_for(:page_title, page_title(subjects_taught_question(school_name: @form.claim_school_name), 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.subjects_taught": "eligible_subjects_biology_taught" }) if current_claim.errors.any? %>
<%= render("shared/error_summary", instance: @form, errored_field_id_overrides: { "subjects_taught": "claim_biology_taught" }) if @form.errors.any? %>

<%= form_for current_claim, url: claim_path(current_journey_routing_name) do |form| %>
<%= form_for @form, url: claim_path(current_journey_routing_name) do |f| %>

<%= form_group_tag current_claim do %>
<%= form.fields_for :eligibility, include_id: false do |fields| %>
<fieldset class="govuk-fieldset" id="claim_subjects_taught">
<%= form_group_tag @form do %>
<fieldset class="govuk-fieldset">

<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
<%= subjects_taught_question(school_name: current_claim.eligibility.claim_school_name) %>
</h1>
</legend>
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
<%= subjects_taught_question(school_name: f.object.claim_school_name) %>
</h1>
</legend>

<%= errors_tag current_claim.eligibility, :subjects_taught %>
<%= errors_tag f.object, :subjects_taught %>

<div class="govuk-checkboxes">
<div class="govuk-checkboxes" data-module="govuk-checkboxes">

<%- Policies::StudentLoans::Eligibility::SUBJECT_ATTRIBUTES.each do |subject| %>
<div class="govuk-checkboxes__item">
<%= fields.hidden_field subject, value: false %>
<%= fields.check_box subject, class: "govuk-checkboxes__input subject", id: "eligible_subjects_#{subject}" %>
<%= fields.label subject, t("student_loans.questions.eligible_subjects.#{subject}"), class: "govuk-label govuk-checkboxes__label", for: "eligible_subjects_#{subject}" %>
</div>
<% end %>

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

<div class="govuk-radios__item">
<%= fields.hidden_field :taught_eligible_subjects, value: true %>
<%= fields.radio_button :taught_eligible_subjects, false, class: "govuk-radios__input" %>
<%= fields.label :taught_eligible_subjects_false, t('student_loans.questions.eligible_subjects.none_taught'), class: "govuk-label govuk-radios__label" %>
<%- f.object.subject_attributes.each do |subject| %>
<div class="govuk-checkboxes__item">
<%= f.check_box :subjects_taught, { class: "govuk-checkboxes__input", id: "claim_#{subject}", include_hidden: false, checked: f.object.subject_taught_selected?(subject), multiple: true }, subject %>
<%= f.label :subjects_taught, t("student_loans.forms.subjects_taught.answers.#{subject}"), class: "govuk-label govuk-checkboxes__label", for: "claim_#{subject}" %>
</div>
<% end %>

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

<div class="govuk-checkboxes__item">
<%= f.check_box :subjects_taught, { class: "govuk-checkboxes__input", id: "claim_taught_eligible_subjects", include_hidden: false, multiple: true, data: { behaviour: "exclusive" } }, "none_taught" %>
<%= f.label :subjects_taught, t("student_loans.forms.subjects_taught.answers.none_taught"), class: "govuk-label govuk-checkboxes__label", for: "claim_taught_eligible_subjects" %>
</div>

</fieldset>
<% end %>
</div>

</fieldset>
<% end %>

<%= form.submit "Continue", class: "govuk-button" %>
<%= f.submit "Continue", class: "govuk-button" %>

<% end %>
</div>
Expand Down
12 changes: 12 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ en:
qts_award_year: When did you complete your initial teacher training (ITT)?
errors:
select_itt_year: Select when you completed your initial teacher training
subjects_taught:
questions:
subjects_taught: Which of the following subjects did you teach at %{school} between %{financial_year}?
answers:
biology_taught: Biology
chemistry_taught: Chemistry
physics_taught: Physics
computing_taught: Computing
languages_taught: Languages
none_taught: I did not teach any of these subjects
errors:
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?"
Expand Down
8 changes: 4 additions & 4 deletions spec/features/changing_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

find("a[href='#{claim_path(Journeys::TeacherStudentLoanReimbursement::ROUTING_NAME, "subjects-taught")}']").click

expect(find("#eligible_subjects_physics_taught").checked?).to eq(true)
expect(find("#claim_physics_taught").checked?).to eq(true)

check "Biology"
click_on "Continue"
Expand Down Expand Up @@ -73,8 +73,8 @@

expect(current_path).to eq(claim_path(Journeys::TeacherStudentLoanReimbursement::ROUTING_NAME, "subjects-taught"))

check I18n.t("student_loans.questions.eligible_subjects.biology_taught"), visible: false
check I18n.t("student_loans.questions.eligible_subjects.chemistry_taught"), visible: false
check I18n.t("student_loans.forms.subjects_taught.answers.biology_taught"), visible: false
check I18n.t("student_loans.forms.subjects_taught.answers.chemistry_taught"), visible: false

click_on "Continue"

Expand Down Expand Up @@ -123,7 +123,7 @@

find("a[href='#{claim_path(Journeys::TeacherStudentLoanReimbursement::ROUTING_NAME, "subjects-taught")}']").click

expect(find("#eligible_subjects_physics_taught").checked?).to eq(true)
expect(find("#claim_physics_taught").checked?).to eq(true)

click_on "Continue"

Expand Down
2 changes: 1 addition & 1 deletion spec/features/ineligible_student_loans_claims_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
claim = start_student_loans_claim
choose_school school

choose I18n.t("student_loans.questions.eligible_subjects.none_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.none_taught")
click_on "Continue"

expect(claim.eligibility.reload.taught_eligible_subjects?).to eq(false)
Expand Down
10 changes: 5 additions & 5 deletions spec/features/multiple_claim_schools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
scenario "didn't teach eligible subjects, but taught eligible subjects at a different eligible school" do
choose_school eligible_school

choose I18n.t("student_loans.questions.eligible_subjects.none_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.none_taught")
click_on "Continue"

expect(page).to have_text("You did not select an eligible subject")
Expand All @@ -57,8 +57,8 @@

choose_school eligible_school

check I18n.t("student_loans.questions.eligible_subjects.biology_taught")
check I18n.t("student_loans.questions.eligible_subjects.physics_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.biology_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.physics_taught")
click_on "Continue"

expect(claim.eligibility.reload.taught_eligible_subjects).to eq(true)
Expand All @@ -69,14 +69,14 @@
scenario "didn't teach eligible subjects and did not teach eligible subjects at a different eligible school" do
choose_school eligible_school

choose I18n.t("student_loans.questions.eligible_subjects.none_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.none_taught")
click_on "Continue"

click_on "Enter another school"

choose_school eligible_school

choose I18n.t("student_loans.questions.eligible_subjects.none_taught")
check I18n.t("student_loans.forms.subjects_taught.answers.none_taught")
click_on "Continue"

expect(page).to have_text("You did not select an eligible subject")
Expand Down
Loading

0 comments on commit b6fe794

Please sign in to comment.