-
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.
add academic start year form for FE journey
- Loading branch information
Showing
10 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
app/forms/journeys/further_education_payments/further_education_teaching_start_year_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,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 |
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
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
7 changes: 0 additions & 7 deletions
7
app/views/further_education_payments/claims/academic_year_in_further_education.html.erb
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/views/further_education_payments/claims/further_education_teaching_start_year.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<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 %> | ||
|
||
<%= 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 %> | ||
</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
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
66 changes: 66 additions & 0 deletions
66
...ms/journeys/further_education_payments/further_education_teaching_start_year_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,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 |