-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2927 from DFE-Digital/fe-teaching-hours-per-week
[LUPEYALPHA-549] Add teaching hours per week to FE journey
- Loading branch information
Showing
9 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/forms/journeys/further_education_payments/teaching_hours_per_week_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 16 additions & 6 deletions
22
app/views/further_education_payments/claims/teaching_hours_per_week.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
<p class="govuk-body"> | ||
FE teaching hours per week goes here | ||
</p> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= 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 %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
spec/forms/journeys/further_education_payments/teaching_hours_per_week_form_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |