Skip to content

Commit

Permalink
Fix teaching hours label and error message
Browse files Browse the repository at this point in the history
The teaching hours per week label needs to be variable depending on the
option selected by the claimant. This commit updates the label and error
message to be variable.
We also now pass the parent form into the assertion form rather than
passing in the claim and contract type.
  • Loading branch information
rjlynch committed Aug 29, 2024
1 parent 1437c60 commit 4a5a85d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ def course_descriptions
@course_descriptions ||= claim.eligibility.courses_taught.map(&:description)
end

def teaching_hours_per_week
I18n.t(
[
"further_education_payments",
"forms",
"teaching_hours_per_week",
"options",
claim.eligibility.teaching_hours_per_week
].join(".")
).downcase
end

def assertions
@assertions ||= ASSERTIONS.fetch(contract_type).map do |assertion_name|
AssertionForm.new(
name: assertion_name,
claim: claim,
type: contract_type
)
AssertionForm.new(name: assertion_name, parent_form: self)
end
end

Expand Down Expand Up @@ -138,7 +146,7 @@ class AssertionForm
include ActiveModel::Model
include ActiveModel::Attributes

attr_reader :claim, :type
attr_reader :parent_form

attribute :name, :string
attribute :outcome, :boolean
Expand All @@ -153,20 +161,20 @@ class AssertionForm
"forms",
"verify_claim",
"assertions",
form.type,
form.contract_type,
form.name,
"errors",
"inclusion"
].join("."),
claimant: form.claimant,
provider: form.provider
provider: form.provider,
hours: form.hours
)
end
}

def initialize(name:, claim:, type:)
@claim = claim
@type = type
def initialize(name:, parent_form:)
@parent_form = parent_form

super(name: name)
end
Expand All @@ -181,11 +189,19 @@ def radio_options
class RadioOption < Struct.new(:id, :name, keyword_init: true); end

def claimant
claim.first_name
parent_form.claim.first_name
end

def provider
claim.school.name
parent_form.claim.school.name
end

def hours
parent_form.teaching_hours_per_week
end

def contract_type
parent_form.contract_type
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
[:assertions, f.object.contract_type, ff.object.name, :label],
claimant: f.object.claimant_name,
provider: f.object.claim.school.name,
hours: f.object.teaching_hours_per_week
),
},
hint: -> do
Expand Down
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,9 @@ en:
errors:
inclusion: "Select yes if %{claimant} is in the first 5 years of their further education teaching career in England"
teaching_hours_per_week:
label: "Is %{claimant} timetabled to teach an average of 12 hours per week during the current term?"
label: "Is %{claimant} timetabled to teach an average of %{hours} during the current term?"
errors:
inclusion: "Select yes if %{claimant} is timetabled to teach an average of 12 hours per week during the current term"
inclusion: "Select yes if %{claimant} is timetabled to teach an average of %{hours} during the current term"
hours_teaching_eligible_subjects:
label: "For at least half of their timetabled teaching hours, does %{claimant} teach 16- to 19-year-olds, including those up to age 25 with an Education, Health and Care Plan (EHCP)?"
errors:
Expand All @@ -1155,9 +1155,9 @@ en:
errors:
inclusion: "Select yes if %{claimant} has taught at least one academic term at %{provider}"
teaching_hours_per_week:
label: "Is %{claimant} timetabled to teach an average of 12 hours per week during the current term?"
label: "Is %{claimant} timetabled to teach an average of %{hours} during the current term?"
errors:
inclusion: "Select yes if %{claimant} is timetabled to teach an average of 12 hours per week during the current term"
inclusion: "Select yes if %{claimant} is timetabled to teach an average of %{hours} during the current term"
hours_teaching_eligible_subjects:
label: "For at least half of their timetabled teaching hours, does %{claimant} teach 16- to 19-year-olds, including those up to age 25 with an Education, Health and Care Plan (EHCP)?"
errors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@
create(
:further_education_payments_eligibility,
claim: claim_1,
school: fe_provider
school: fe_provider,
teaching_hours_per_week: "more_than_12"
)

claim_2 = create(
Expand All @@ -284,7 +285,8 @@
create(
:further_education_payments_eligibility,
claim: claim_2,
school: fe_provider
school: fe_provider,
teaching_hours_per_week: "more_than_12"
)

mock_dfe_sign_in_auth_session(
Expand Down Expand Up @@ -395,6 +397,7 @@
:further_education_payments_eligibility,
claim: claim,
school: fe_provider,
teaching_hours_per_week: "more_than_12",
contract_type: "fixed_term",
subjects_taught: ["engineering_manufacturing"],
engineering_manufacturing_courses: [
Expand Down Expand Up @@ -461,8 +464,8 @@
end

within_fieldset(
"Is Edna Krabappel timetabled to teach an average of 12 hours per " \
"week during the current term?"
"Is Edna Krabappel timetabled to teach an average of more than 12 " \
"hours per week during the current term?"
) do
choose "Yes"
end
Expand Down Expand Up @@ -518,6 +521,7 @@
claim: claim,
school: fe_provider,
contract_type: "variable_hours",
teaching_hours_per_week: "between_2_5_and_12",
subjects_taught: ["engineering_manufacturing"],
engineering_manufacturing_courses: [
"approved_level_321_transportation",
Expand Down Expand Up @@ -590,8 +594,8 @@
end

within_fieldset(
"Is Edna Krabappel timetabled to teach an average of 12 hours per " \
"week during the current term?"
"Is Edna Krabappel timetabled to teach an average of between 2.5 and " \
"12 hours per week during the current term?"
) do
choose "Yes"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
create(:school, :further_education, name: "Springfield Elementary")
end

let(:teaching_hours_per_week) { "more_than_12" }

let(:contract_type) { "fixed_term" }

let(:eligibility) do
create(
:further_education_payments_eligibility,
school: school
school: school,
teaching_hours_per_week: teaching_hours_per_week,
contract_type: contract_type
)
end

Expand Down Expand Up @@ -124,22 +130,17 @@
end

describe "AssertionForm" do
let(:contract_type) { "fixed_contract" }

subject do
described_class::AssertionForm.new(
name: assertion_name,
type: contract_type,
claim: claim
parent_form: form
)
end

context "when the assertion is `contract_type`" do
let(:assertion_name) { "contract_type" }

context "when fixed term" do
let(:contract_type) { "fixed_contract" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
"Select yes if Edna has a fixed term contract of employment at Springfield Elementary"
Expand All @@ -148,7 +149,7 @@
end

context "when variable" do
let(:contract_type) { "variable_contract" }
let(:contract_type) { "variable_hours" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
Expand Down Expand Up @@ -181,7 +182,7 @@
context "when the assertion is `taught_at_least_one_term`" do
let(:assertion_name) { "taught_at_least_one_term" }

let(:contract_type) { "variable_contract" }
let(:contract_type) { "variable_hours" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
Expand All @@ -193,10 +194,22 @@
context "when the assertion is `teaching_hours_per_week`" do
let(:assertion_name) { "teaching_hours_per_week" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
"Select yes if Edna is timetabled to teach an average of 12 hours per week during the current term"
))
context "when more that 12" do
it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
"Select yes if Edna is timetabled to teach an average of more than 12 hours per week during the current term"
))
end
end

context "when between 2.5 and 12" do
let(:teaching_hours_per_week) { "between_2_5_and_12" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
"Select yes if Edna is timetabled to teach an average of between 2.5 and 12 hours per week during the current term"
))
end
end
end

Expand All @@ -223,7 +236,7 @@
context "when the assertion is `teaching_hours_per_week_next_term`" do
let(:assertion_name) { "teaching_hours_per_week_next_term" }

let(:contract_type) { "variable_contract" }
let(:contract_type) { "variable_hours" }

it do
is_expected.not_to(allow_value(nil).for(:outcome).with_message(
Expand Down

0 comments on commit 4a5a85d

Please sign in to comment.