From 2139aecc25c6663ac90b99887c0e463f019b26c6 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Tue, 25 Jun 2024 16:31:11 +0100 Subject: [PATCH] add FE contract type --- .../contract_type_form.rb | 36 ++++++++++++++ .../journeys/further_education_payments.rb | 1 + .../session_answers.rb | 5 ++ .../claims/contract_type.html.erb | 13 +++-- config/locales/en.yml | 4 ++ .../session_answers.rb | 4 ++ .../happy_js_path_spec.rb | 3 +- .../happy_path_spec.rb | 3 +- .../contract_type_form_spec.rb | 48 +++++++++++++++++++ 9 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 app/forms/journeys/further_education_payments/contract_type_form.rb create mode 100644 spec/factories/journeys/further_education_payments/session_answers.rb create mode 100644 spec/forms/journeys/further_education_payments/contract_type_form_spec.rb diff --git a/app/forms/journeys/further_education_payments/contract_type_form.rb b/app/forms/journeys/further_education_payments/contract_type_form.rb new file mode 100644 index 0000000000..ab2f408ced --- /dev/null +++ b/app/forms/journeys/further_education_payments/contract_type_form.rb @@ -0,0 +1,36 @@ +module Journeys + module FurtherEducationPayments + class ContractTypeForm < Form + attribute :contract_type, :string + + validates :contract_type, + inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)} + + def radio_options + [ + OpenStruct.new( + id: "permanent", + name: "Permanent contract", + hint: "This includes full-time and part-time contracts" + ), + OpenStruct.new( + id: "fixed-term", + name: "Fixed-term contract" + ), + OpenStruct.new( + id: "variable-hours", + name: "Variable hours contract", + hint: "This includes zero hours contract and hourly paid" + ) + ] + end + + def save + return if invalid? + + journey_session.answers.assign_attributes(contract_type:) + 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 831bde3558..1ff183dfe7 100644 --- a/app/models/journeys/further_education_payments.rb +++ b/app/models/journeys/further_education_payments.rb @@ -12,6 +12,7 @@ module FurtherEducationPayments "teaching-responsibilities" => TeachingResponsibilitiesForm, "further-education-provision-search" => FurtherEducationProvisionSearchForm, "select-provision" => SelectProvisionForm, + "contract-type" => ContractTypeForm, "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 07cedd8d3d..4210d73a3b 100644 --- a/app/models/journeys/further_education_payments/session_answers.rb +++ b/app/models/journeys/further_education_payments/session_answers.rb @@ -4,7 +4,12 @@ class SessionAnswers < Journeys::SessionAnswers attribute :teaching_responsibilities, :boolean attribute :provision_search, :string attribute :school_id, :string # GUID + attribute :contract_type, :string attribute :subjects_taught, default: [] + + def school + @school ||= School.find(school_id) + end end end end diff --git a/app/views/further_education_payments/claims/contract_type.html.erb b/app/views/further_education_payments/claims/contract_type.html.erb index ca9afd0738..6da1881189 100644 --- a/app/views/further_education_payments/claims/contract_type.html.erb +++ b/app/views/further_education_payments/claims/contract_type.html.erb @@ -1,7 +1,12 @@ -

- FE contract type 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 %> + + <%= f.govuk_collection_radio_buttons :contract_type, @form.radio_options, :id, :name, :hint, + legend: { + text: @form.t(:question, school_name: journey_session.answers.school.name), + tag: "h1", + size: "l" + } %> + <%= f.govuk_submit %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 58e74ef139..63e910cfb4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -788,6 +788,10 @@ en: select_provision: errors: blank: Select the college you teach at + contract_type: + question: What type of contract do you have with %{school_name}? + errors: + inclusion: Select the contract type you have subjects_taught: question: Which subject areas do you teach? hint: Select all that apply diff --git a/spec/factories/journeys/further_education_payments/session_answers.rb b/spec/factories/journeys/further_education_payments/session_answers.rb new file mode 100644 index 0000000000..9c2bf044aa --- /dev/null +++ b/spec/factories/journeys/further_education_payments/session_answers.rb @@ -0,0 +1,4 @@ +FactoryBot.define do + factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do + end +end 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 728b02af49..11c728af8d 100644 --- a/spec/features/further_education_payments/happy_js_path_spec.rb +++ b/spec/features/further_education_payments/happy_js_path_spec.rb @@ -26,7 +26,8 @@ expect(page).to have_selector "input[type=radio][checked=checked][value='#{college.id}']", visible: false click_button "Continue" - expect(page).to have_content("FE contract type goes here") + expect(page).to have_content("What type of contract do you have with #{college.name}?") + choose("Permanent contract") click_button "Continue" expect(page).to have_content("FE teaching hours per week goes here") diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index f6213fa09f..7e38c5c95b 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -23,7 +23,8 @@ choose college.name click_button "Continue" - expect(page).to have_content("FE contract type goes here") + expect(page).to have_content("What type of contract do you have with #{college.name}?") + choose("Permanent contract") click_button "Continue" expect(page).to have_content("FE teaching hours per week goes here") diff --git a/spec/forms/journeys/further_education_payments/contract_type_form_spec.rb b/spec/forms/journeys/further_education_payments/contract_type_form_spec.rb new file mode 100644 index 0000000000..47eb4cb6ea --- /dev/null +++ b/spec/forms/journeys/further_education_payments/contract_type_form_spec.rb @@ -0,0 +1,48 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::ContractTypeForm, type: :model do + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) { create(:further_education_payments_session, answers:) } + let(:answers) { build(:further_education_payments_answers, school_id: college.id) } + let(:college) { create(:school) } + let(:contract_type) { nil } + + let(:params) do + ActionController::Parameters.new( + claim: { + contract_type: + } + ) + end + + subject do + described_class.new( + journey_session:, + journey:, + params: + ) + end + + describe "validations" do + context "when no option selected" do + it do + is_expected.not_to( + allow_value(nil) + .for(:contract_type) + .with_message("Select the contract type you have") + ) + end + end + end + + describe "#save" do + let(:contract_type) { %w[permanent fixed-term variable-hours].sample } + + it "updates the journey session" do + expect { expect(subject.save).to be(true) }.to( + change { journey_session.reload.answers.contract_type } + .to(contract_type) + ) + end + end +end