Skip to content

Commit

Permalink
add FE contract type
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Jul 1, 2024
1 parent fbb7689 commit 2139aec
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/journeys/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module FurtherEducationPayments
"teaching-responsibilities" => TeachingResponsibilitiesForm,
"further-education-provision-search" => FurtherEducationProvisionSearchForm,
"select-provision" => SelectProvisionForm,
"contract-type" => ContractTypeForm,
"subjects-taught" => SubjectsTaughtForm
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<p class="govuk-body">
FE contract type goes here
</p>

<%= 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 %>
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryBot.define do
factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion spec/features/further_education_payments/happy_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2139aec

Please sign in to comment.