Skip to content

Commit

Permalink
Update error messages in claimant journey
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Sep 4, 2024
1 parent 7ec91ac commit 56ce3d5
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class ContractTypeForm < Form
attribute :contract_type, :string

validates :contract_type,
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)}
inclusion: {
in: ->(form) { form.radio_options.map(&:id) },
message: ->(object, data) { i18n_error_message(:inclusion, school_name: object.school.name).call(object, data) }
}

def radio_options
[
Expand Down Expand Up @@ -34,6 +37,10 @@ def save
journey_session.save!
end

def school
journey_session.answers.school
end

private

def reset_dependent_answers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ class FixedTermContractForm < Form
attribute :fixed_term_full_year, :boolean

validates :fixed_term_full_year,
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)}
inclusion: {
in: ->(form) { form.radio_options.map(&:id) },
message: ->(object, data) { i18n_error_message(:inclusion, current_academic_year: object.current_academic_year).call(object, data) }
}

def radio_options
[
OpenStruct.new(
id: true,
name: t("options.true", current_academic_year: current_academic_year.to_s(:long))
name: t("options.true", current_academic_year: current_academic_year)
),
OpenStruct.new(
id: false,
name: t("options.false", current_academic_year: current_academic_year.to_s(:long))
name: t("options.false", current_academic_year: current_academic_year)
)
]
end
Expand All @@ -27,7 +30,7 @@ def save
end

def current_academic_year
@current_academic_year ||= AcademicYear.current
@current_academic_year ||= AcademicYear.current.to_s(:long)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ class FurtherEducationTeachingStartYearForm < Form
attribute :further_education_teaching_start_year, :string

validates :further_education_teaching_start_year,
presence: {message: i18n_error_message(:blank)}
presence: {
message: ->(object, data) { i18n_error_message(:blank, before_year: object.before_year).call(object, data) }
}

def radio_options
years_before = -4
YEARS_BEFORE = -4

array = (years_before..0).map do |delta|
def radio_options
array = (YEARS_BEFORE..0).map do |delta|
academic_year = AcademicYear.current + delta
OpenStruct.new(
id: academic_year.start_year.to_s,
name: t("options.between_dates", start_year: academic_year.start_year, end_year: academic_year.end_year)
)
end

academic_year = AcademicYear.current + years_before
array << OpenStruct.new(
id: "pre-#{academic_year.start_year}",
name: t("options.before_date", year: academic_year.start_year)
id: "pre-#{before_year}",
name: t("options.before_date", year: before_year)
)

array
Expand All @@ -32,6 +33,11 @@ def save
journey_session.answers.assign_attributes(further_education_teaching_start_year:)
journey_session.save!
end

def before_year
academic_year = AcademicYear.current + YEARS_BEFORE
academic_year.start_year
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class TeachingHoursPerWeekForm < Form
attribute :teaching_hours_per_week, :string

validates :teaching_hours_per_week,
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)}
inclusion: {
in: ->(form) { form.radio_options.map(&:id) },
message: ->(object, data) { i18n_error_message(:inclusion, school_name: object.school.name).call(object, data) }
}

def radio_options
@radio_options ||= [
Expand All @@ -29,6 +32,10 @@ def save
journey_session.answers.assign_attributes(teaching_hours_per_week:)
journey_session.save!
end

def school
journey_session.answers.school
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class TeachingHoursPerWeekNextTermForm < Form
attribute :teaching_hours_per_week_next_term, :string

validates :teaching_hours_per_week_next_term,
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)}
inclusion: {
in: ->(form) { form.radio_options.map(&:id) },
message: ->(object, data) { i18n_error_message(:inclusion, school_name: object.school.name).call(object, data) }
}

def radio_options
@radio_options ||= [
Expand All @@ -26,8 +29,6 @@ def save
journey_session.save!
end

private

def school
journey_session.answers.school
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% content_for(:page_title, page_title(@form.t(:question, academic_year: @form.current_academic_year.to_s(:long)), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>
<% content_for(:page_title, page_title(@form.t(:question, academic_year: @form.current_academic_year), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand All @@ -7,7 +7,7 @@

<%= f.govuk_collection_radio_buttons :fixed_term_full_year, @form.radio_options, :id, :name,
legend: {
text: @form.t(:question, academic_year: @form.current_academic_year.to_s(:long)),
text: @form.t(:question, academic_year: @form.current_academic_year),
tag: "h1",
size: "l"
} %>
Expand Down
24 changes: 12 additions & 12 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -866,30 +866,30 @@ en:
further_education_provision_search:
question: Which FE provider are you employed by?
errors:
blank: Enter a college name or postcode
blank: Enter the name of the FE provider you are employed by
min_length: Enter a college name or postcode that is at least 3 characters long
select_provision:
heading: Select where you are employed
hint:
Select the further education provider you are employed by. If you work for a college or sixth-form group, you
should select the group name.
errors:
blank: Select where you are employed
blank: Select the further education provider you are employed by
contract_type:
question: What type of contract do you have with %{school_name}?
options:
permanent: Permanent contract
fixed_term: Fixed-term contract
variable_hours: Variable hours contract
errors:
inclusion: Select the contract type you have
inclusion: Select the type of contract you have with %{school_name}
fixed_term_contract:
question: Does your fixed-term contract cover the full %{academic_year} academic year?
options:
true: Yes, it covers the full %{current_academic_year} academic year
false: No, it does not cover the full %{current_academic_year} academic year
errors:
inclusion: Select yes if your fixed-term contract covers the full academic year
inclusion: Select yes if your fixed-term contract covers the full %{current_academic_year} academic year
taught_at_least_one_term:
question: Have you taught at %{school_name} for at least one academic term?
options:
Expand All @@ -906,22 +906,22 @@ en:
between_2_5_and_12: Between 2.5 and 12 hours per week
less_than_2_5: Less than 2.5 hours per week
errors:
inclusion: Select how many hours per week you are timetabled to teach during the current term
inclusion: Select the number of hours you are timetabled to teach per week at %{school_name} during the current term
teaching_hours_per_week_next_term:
question: Are you timetabled to teach at least 2.5 hours per week at %{school_name} next term?
hint: If you are unsure, you should speak to HR or apply when you know your arrangements for next term.
options:
at_least_2_5: Yes, I am timetabled to teach at least 2.5 hours per week at %{school_name} next term
less_than_2_5: No, I’m not timetabled to teach at least 2.5 hours per week at %{school_name} next term
errors:
inclusion: Select yes if you are timetabled to teach at least 2.5 hours next term otherwise select you are not
inclusion: Select yes if you are timetabled to teach at least 2.5 hours per week next term at %{school_name}
further_education_teaching_start_year:
question: Which academic year did you start teaching in further education (FE) in England?
options:
between_dates: September %{start_year} to August %{end_year}
before_date: I started before September %{year}
errors:
blank: Select which academic year you started teaching in further education in England
blank: Select the academic year you started teaching further education in England, or select ‘I started before September %{before_year}’
subjects_taught:
question: Which subject areas do you teach?
hint: Select all that apply
Expand All @@ -935,13 +935,13 @@ en:
physics: Physics
none: I do not teach any of these subjects
errors:
inclusion: Select the subject areas you teach in or select you do not teach any of the listed subject areas
inclusion: Select the subject areas that you teach, or select ‘I do not teach any of these subjects’
courses: &courses
hint: |
<p>If you are unsure whether the course(s) you teach is eligible, please email: <br/>%{email}</p>
<p>Select all that apply</p>
errors:
inclusion: Select all the courses you teach otherwise select you do not teach any of these courses
inclusion: Select the courses that you teach, or select ‘I do not teach any of these courses
building_construction_courses:
<<: *courses
question: Which building and construction courses do you teach?
Expand Down Expand Up @@ -1052,7 +1052,7 @@ en:
no_but_planned: No, but I plan to enrol on one in the next 12 months
no_not_planned: No, and I do not plan to enrol on one in the next 12 months
errors:
inclusion: Select whether you have, are currently enrolled or plan to enrol on a teaching qualification
inclusion: Select if you have a teaching qualification, or are currently enrolled on one or are planning to enrol on one
poor_performance:
heading: Tell us if you are currently under any performance measures or disciplinary action
questions:
Expand All @@ -1069,9 +1069,9 @@ en:
check with your FE provider as it will affect your eligibility.
errors:
performance:
inclusion: Select yes if you are subject to formal action for poor performance at work
inclusion: Select yes if any performance measures have been started against you
disciplinary:
inclusion: Select yes if you are subject to disciplinary action
inclusion: Select yes if you are currently subject to disciplinary action
half_teaching_hours:
question:
Are at least half of your timetabled teaching hours spent teaching 16 to 19-year-olds, including those up to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_expected.not_to(
allow_value([""])
.for(:building_construction_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand All @@ -37,7 +37,7 @@
is_expected.not_to(
allow_value(["foo"])
.for(:building_construction_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_expected.not_to(
allow_value([""])
.for(:chemistry_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand All @@ -37,7 +37,7 @@
is_expected.not_to(
allow_value(["foo"])
.for(:chemistry_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_expected.not_to(
allow_value([""])
.for(:computing_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand All @@ -37,7 +37,7 @@
is_expected.not_to(
allow_value(["foo"])
.for(:computing_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
is_expected.not_to(
allow_value(nil)
.for(:contract_type)
.with_message("Select the contract type you have")
.with_message("Select the type of contract you have with #{college.name}")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_expected.not_to(
allow_value([""])
.for(:early_years_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand All @@ -37,7 +37,7 @@
is_expected.not_to(
allow_value(["foo"])
.for(:early_years_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
is_expected.not_to(
allow_value([""])
.for(:engineering_manufacturing_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand All @@ -37,7 +37,7 @@
is_expected.not_to(
allow_value(["foo"])
.for(:engineering_manufacturing_courses)
.with_message("Select all the courses you teach otherwise select you do not teach any of these courses")
.with_message("Select the courses that you teach, or select ‘I do not teach any of these courses")
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

describe "validations" do
it do
is_expected.not_to(
allow_value(fixed_term_full_year)
.for(:fixed_term_full_year)
.with_message("Select yes if your fixed-term contract covers the full academic year")
)
travel_to Date.new(2024, 10, 1) do
is_expected.not_to(
allow_value(fixed_term_full_year)
.for(:fixed_term_full_year)
.with_message("Select yes if your fixed-term contract covers the full 2024 to 2025 academic year")
)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
is_expected.not_to(
allow_value(provision_search)
.for(:provision_search)
.with_message("Enter a college name or postcode")
.with_message("Enter the name of the FE provider you are employed by")
)
end
end
Expand Down
Loading

0 comments on commit 56ce3d5

Please sign in to comment.