From 1a378d85e335fed47f2d04539e5c66ec34fdfb25 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 26 Jun 2024 15:31:38 +0100 Subject: [PATCH] add teaching hours per week to FE journey --- .../teaching_hours_per_week_form.rb | 34 +++++++++++++ .../journeys/further_education_payments.rb | 1 + .../session_answers.rb | 1 + .../claims/teaching_hours_per_week.html.erb | 22 +++++--- config/locales/en.yml | 5 ++ ... => further_education_payments_answers.rb} | 0 .../happy_js_path_spec.rb | 3 +- .../happy_path_spec.rb | 3 +- .../teaching_hours_per_week_form_spec.rb | 50 +++++++++++++++++++ 9 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 app/forms/journeys/further_education_payments/teaching_hours_per_week_form.rb rename spec/factories/journeys/further_education_payments/{session_answers.rb => further_education_payments_answers.rb} (100%) create mode 100644 spec/forms/journeys/further_education_payments/teaching_hours_per_week_form_spec.rb diff --git a/app/forms/journeys/further_education_payments/teaching_hours_per_week_form.rb b/app/forms/journeys/further_education_payments/teaching_hours_per_week_form.rb new file mode 100644 index 0000000000..4fab25abd8 --- /dev/null +++ b/app/forms/journeys/further_education_payments/teaching_hours_per_week_form.rb @@ -0,0 +1,34 @@ +module Journeys + module FurtherEducationPayments + 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)} + + def radio_options + @radio_options ||= [ + OpenStruct.new( + id: "more-than-12", + name: "More than 12 hours per week" + ), + OpenStruct.new( + id: "between-2.5-and-12", + name: "Between 2.5 and 12 hours per week" + ), + OpenStruct.new( + id: "less-than-2.5", + name: "Less than 2.5 hours per week" + ) + ] + end + + def save + return false unless valid? + + journey_session.answers.assign_attributes(teaching_hours_per_week:) + journey_session.save! + end + end + end +end diff --git a/app/models/journeys/further_education_payments.rb b/app/models/journeys/further_education_payments.rb index 786e4b5e13..1705beb167 100644 --- a/app/models/journeys/further_education_payments.rb +++ b/app/models/journeys/further_education_payments.rb @@ -13,6 +13,7 @@ module FurtherEducationPayments "further-education-provision-search" => FurtherEducationProvisionSearchForm, "select-provision" => SelectProvisionForm, "contract-type" => ContractTypeForm, + "teaching-hours-per-week" => TeachingHoursPerWeekForm, "further-education-teaching-start-year" => FurtherEducationTeachingStartYearForm, "subjects-taught" => SubjectsTaughtForm } diff --git a/app/models/journeys/further_education_payments/session_answers.rb b/app/models/journeys/further_education_payments/session_answers.rb index 5a52354cba..3921902e17 100644 --- a/app/models/journeys/further_education_payments/session_answers.rb +++ b/app/models/journeys/further_education_payments/session_answers.rb @@ -5,6 +5,7 @@ class SessionAnswers < Journeys::SessionAnswers attribute :provision_search, :string attribute :school_id, :string # GUID attribute :contract_type, :string + attribute :teaching_hours_per_week, :string attribute :further_education_teaching_start_year, :string attribute :subjects_taught, default: [] diff --git a/app/views/further_education_payments/claims/teaching_hours_per_week.html.erb b/app/views/further_education_payments/claims/teaching_hours_per_week.html.erb index 5e6ea94952..f8592511e5 100644 --- a/app/views/further_education_payments/claims/teaching_hours_per_week.html.erb +++ b/app/views/further_education_payments/claims/teaching_hours_per_week.html.erb @@ -1,7 +1,17 @@ -

- FE teaching hours per week goes here -

+
+
+ <%= form_with model: @form, url: claim_path(current_journey_routing_name), method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %> + <%= f.govuk_error_summary %> -<%= form_with model: @form, url: claim_path(current_journey_routing_name), method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %> - <%= f.govuk_submit %> -<% end %> + <%= f.govuk_collection_radio_buttons :teaching_hours_per_week, @form.radio_options, :id, :name, + legend: { + text: @form.t(:question, school_name: journey_session.answers.school.name), + tag: "h1", + size: "l" + }, + hint: { text: @form.t(:hint) } %> + + <%= f.govuk_submit %> + <% end %> +
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index b47d0b3421..3100758e5c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -800,6 +800,11 @@ en: question: What type of contract do you have with %{school_name}? errors: inclusion: Select the contract type you have + teaching_hours_per_week: + question: On average, how many hours per week are you timetabled to teach at %{school_name} during the current term? + hint: ‘Teaching’ refers to the direct contact time you spend in lessons with students of all ages. + errors: + inclusion: Select how many hours per week you are timetabled to teach during the current term further_education_teaching_start_year: errors: blank: Select which academic year you started teaching in further education in England diff --git a/spec/factories/journeys/further_education_payments/session_answers.rb b/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb similarity index 100% rename from spec/factories/journeys/further_education_payments/session_answers.rb rename to spec/factories/journeys/further_education_payments/further_education_payments_answers.rb diff --git a/spec/features/further_education_payments/happy_js_path_spec.rb b/spec/features/further_education_payments/happy_js_path_spec.rb index b983e2fdaf..002d6b9856 100644 --- a/spec/features/further_education_payments/happy_js_path_spec.rb +++ b/spec/features/further_education_payments/happy_js_path_spec.rb @@ -30,7 +30,8 @@ choose("Permanent contract") click_button "Continue" - expect(page).to have_content("FE teaching hours per week goes here") + expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?") + choose("More than 12 hours per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 3329e7e20a..75d2ae0e99 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -27,7 +27,8 @@ choose("Permanent contract") click_button "Continue" - expect(page).to have_content("FE teaching hours per week goes here") + expect(page).to have_content("On average, how many hours per week are you timetabled to teach at #{college.name} during the current term?") + choose("More than 12 hours per week") click_button "Continue" expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") diff --git a/spec/forms/journeys/further_education_payments/teaching_hours_per_week_form_spec.rb b/spec/forms/journeys/further_education_payments/teaching_hours_per_week_form_spec.rb new file mode 100644 index 0000000000..e0014504ea --- /dev/null +++ b/spec/forms/journeys/further_education_payments/teaching_hours_per_week_form_spec.rb @@ -0,0 +1,50 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::TeachingHoursPerWeekForm, type: :model do + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) { create(:further_education_payments_session, answers:) } + let(:answers) { build(:further_education_payments_answers, answers_hash) } + let(:college) { create(:school) } + let(:answers_hash) do + {school_id: college.id} + end + let(:teaching_hours_per_week) { nil } + + let(:params) do + ActionController::Parameters.new( + claim: { + teaching_hours_per_week: + } + ) + end + + subject do + described_class.new( + journey_session:, + journey:, + params: + ) + end + + describe "validations" do + let(:teaching_hours_per_week) { nil } + + it do + is_expected.not_to( + allow_value(nil) + .for(:teaching_hours_per_week) + .with_message("Select how many hours per week you are timetabled to teach during the current term") + ) + end + end + + describe "#save" do + let(:teaching_hours_per_week) { "more-than-12" } + + it "updates the journey session" do + expect { expect(subject.save).to be(true) }.to( + change { journey_session.reload.answers.teaching_hours_per_week }.to(teaching_hours_per_week) + ) + end + end +end