From d1dc588b6c7f75967f79177bc2bfc2759e69ad82 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 25 Jun 2024 17:18:54 +0100 Subject: [PATCH] add academic start year form for FE journey --- ...ther_education_teaching_start_year_form.rb | 37 +++++++++++ .../journeys/further_education_payments.rb | 1 + .../session_answers.rb | 1 + .../slug_sequence.rb | 2 +- ...cademic_year_in_further_education.html.erb | 7 -- ...her_education_teaching_start_year.html.erb | 28 ++++++++ config/locales/en.yml | 3 + .../happy_js_path_spec.rb | 3 +- .../happy_path_spec.rb | 3 +- ...education_teaching_start_year_form_spec.rb | 66 +++++++++++++++++++ 10 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 app/forms/journeys/further_education_payments/further_education_teaching_start_year_form.rb delete mode 100644 app/views/further_education_payments/claims/academic_year_in_further_education.html.erb create mode 100644 app/views/further_education_payments/claims/further_education_teaching_start_year.html.erb create mode 100644 spec/forms/journeys/further_education_payments/further_education_teaching_start_year_form_spec.rb diff --git a/app/forms/journeys/further_education_payments/further_education_teaching_start_year_form.rb b/app/forms/journeys/further_education_payments/further_education_teaching_start_year_form.rb new file mode 100644 index 0000000000..9f0a1031d7 --- /dev/null +++ b/app/forms/journeys/further_education_payments/further_education_teaching_start_year_form.rb @@ -0,0 +1,37 @@ +module Journeys + module FurtherEducationPayments + class FurtherEducationTeachingStartYearForm < Form + attribute :further_education_teaching_start_year, :string + + validates :further_education_teaching_start_year, + presence: {message: i18n_error_message(:blank)} + + def radio_options + years_before = -4 + + array = (years_before..0).map do |delta| + academic_year = AcademicYear.current + delta + OpenStruct.new( + id: academic_year.start_year.to_s, + name: "September #{academic_year.start_year} to August #{academic_year.end_year}" + ) + end + + academic_year = AcademicYear.current + years_before + array << OpenStruct.new( + id: "pre-#{academic_year.start_year}", + name: "I started before September #{academic_year.start_year}" + ) + + array + end + + def save + return false if invalid? + + journey_session.answers.assign_attributes(further_education_teaching_start_year:) + 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 1ff183dfe7..786e4b5e13 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, + "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 4210d73a3b..5a52354cba 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 :further_education_teaching_start_year, :string attribute :subjects_taught, default: [] def school diff --git a/app/models/journeys/further_education_payments/slug_sequence.rb b/app/models/journeys/further_education_payments/slug_sequence.rb index d9f41f5322..9565581810 100644 --- a/app/models/journeys/further_education_payments/slug_sequence.rb +++ b/app/models/journeys/further_education_payments/slug_sequence.rb @@ -7,7 +7,7 @@ class SlugSequence select-provision contract-type teaching-hours-per-week - academic-year-in-further-education + further-education-teaching-start-year subjects-taught building-and-construction-courses teaching-courses diff --git a/app/views/further_education_payments/claims/academic_year_in_further_education.html.erb b/app/views/further_education_payments/claims/academic_year_in_further_education.html.erb deleted file mode 100644 index 1c019f5e01..0000000000 --- a/app/views/further_education_payments/claims/academic_year_in_further_education.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -

- FE academic year in further education 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_submit %> -<% end %> diff --git a/app/views/further_education_payments/claims/further_education_teaching_start_year.html.erb b/app/views/further_education_payments/claims/further_education_teaching_start_year.html.erb new file mode 100644 index 0000000000..364f22ef09 --- /dev/null +++ b/app/views/further_education_payments/claims/further_education_teaching_start_year.html.erb @@ -0,0 +1,28 @@ +
+
+ <%= 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 %> + + <%= f.govuk_radio_buttons_fieldset :further_education_teaching_start_year, + legend: { + text: "Which academic year did you start teaching in further education (FE) in England?", + tag: "h1", + size: "l" + } do %> + <% @form.radio_options[0..-2].each do |option| %> + <%= f.govuk_radio_button :further_education_teaching_start_year, option.id, + label: { text: option.name }, + link_errors: @form.radio_options.first == option %> + <% end %> + + <%= f.govuk_radio_divider %> + + <% option = @form.radio_options.last %> + <%= f.govuk_radio_button :further_education_teaching_start_year, option.id, + label: { text: option.name } %> + <% end %> + + <%= f.govuk_submit %> + <% end %> +
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index 867a014da9..b47d0b3421 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -800,6 +800,9 @@ en: question: What type of contract do you have with %{school_name}? errors: inclusion: Select the contract type you have + further_education_teaching_start_year: + errors: + blank: Select which academic year you started teaching in further education in England subjects_taught: question: Which subject areas do you teach? hint: Select all that apply 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 11c728af8d..b983e2fdaf 100644 --- a/spec/features/further_education_payments/happy_js_path_spec.rb +++ b/spec/features/further_education_payments/happy_js_path_spec.rb @@ -33,7 +33,8 @@ expect(page).to have_content("FE teaching hours per week goes here") click_button "Continue" - expect(page).to have_content("FE academic year in further education goes here") + expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") + choose("September 2023 to August 2024") click_button "Continue" expect(page).to have_content("Which subject areas do you teach?") diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 7e38c5c95b..3329e7e20a 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -30,7 +30,8 @@ expect(page).to have_content("FE teaching hours per week goes here") click_button "Continue" - expect(page).to have_content("FE academic year in further education goes here") + expect(page).to have_content("Which academic year did you start teaching in further education (FE) in England?") + choose("September 2023 to August 2024") click_button "Continue" expect(page).to have_content("Which subject areas do you teach?") diff --git a/spec/forms/journeys/further_education_payments/further_education_teaching_start_year_form_spec.rb b/spec/forms/journeys/further_education_payments/further_education_teaching_start_year_form_spec.rb new file mode 100644 index 0000000000..cdd8503fa5 --- /dev/null +++ b/spec/forms/journeys/further_education_payments/further_education_teaching_start_year_form_spec.rb @@ -0,0 +1,66 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::FurtherEducationTeachingStartYearForm, type: :model do + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) { create(:further_education_payments_session) } + let(:further_education_teaching_start_year) { nil } + + let(:params) do + ActionController::Parameters.new( + claim: { + further_education_teaching_start_year: + } + ) + end + + subject do + described_class.new( + journey_session:, + journey:, + params: + ) + end + + describe "#radio_options" do + it "returns 6 options" do + expect(subject.radio_options.size).to eql(6) + end + + it "returns expected data" do + travel_to Time.zone.local(2024, 12, 1) do + expected = [ + OpenStruct.new(id: "2020", name: "September 2020 to August 2021"), + OpenStruct.new(id: "2021", name: "September 2021 to August 2022"), + OpenStruct.new(id: "2022", name: "September 2022 to August 2023"), + OpenStruct.new(id: "2023", name: "September 2023 to August 2024"), + OpenStruct.new(id: "2024", name: "September 2024 to August 2025"), + OpenStruct.new(id: "pre-2020", name: "I started before September 2020") + ] + + expect(subject.radio_options).to eql(expected) + end + end + end + + describe "validations" do + let(:further_education_teaching_start_year) { nil } + + it do + is_expected.not_to( + allow_value(further_education_teaching_start_year) + .for(:further_education_teaching_start_year) + .with_message("Select which academic year you started teaching in further education in England") + ) + end + end + + describe "#save" do + let(:further_education_teaching_start_year) { AcademicYear.current.start_year.to_s } + + it "updates the journey session" do + expect { expect(subject.save).to be(true) }.to( + change { journey_session.reload.answers.further_education_teaching_start_year }.to(further_education_teaching_start_year) + ) + end + end +end