-
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 poor performance form to FE journey
- Loading branch information
Showing
8 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/forms/journeys/further_education_payments/poor_performance_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 PoorPerformanceForm < Form | ||
attribute :subject_to_formal_performance_action, :boolean | ||
attribute :subject_to_disciplinary_action, :boolean | ||
|
||
validates :subject_to_formal_performance_action, inclusion: {in: [true, false], message: i18n_error_message("performance.inclusion")} | ||
validates :subject_to_disciplinary_action, inclusion: {in: [true, false], message: i18n_error_message("disciplinary.inclusion")} | ||
|
||
def radio_options | ||
[ | ||
OpenStruct.new( | ||
id: true, | ||
name: "Yes" | ||
), | ||
OpenStruct.new( | ||
id: false, | ||
name: "No" | ||
) | ||
] | ||
end | ||
|
||
def save | ||
return false if invalid? | ||
|
||
journey_session.answers.assign_attributes( | ||
subject_to_formal_performance_action:, | ||
subject_to_disciplinary_action: | ||
) | ||
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
34 changes: 28 additions & 6 deletions
34
app/views/further_education_payments/claims/poor_performance.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,29 @@ | ||
<p class="govuk-body"> | ||
FE poor performance 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 %> | ||
<h1 class="govuk-heading-l"> | ||
<%= @form.t(:heading) %> | ||
</h1> | ||
|
||
<%= f.govuk_collection_radio_buttons :subject_to_formal_performance_action, @form.radio_options, :id, :name, | ||
legend: { | ||
text: @form.t("questions.performance.question"), | ||
tag: "h2", | ||
size: "m" | ||
}, | ||
hint: { text: @form.t("questions.performance.hint") } %> | ||
|
||
<%= f.govuk_collection_radio_buttons :subject_to_disciplinary_action, @form.radio_options, :id, :name, | ||
legend: { | ||
text: @form.t("questions.disciplinary.question"), | ||
tag: "h2", | ||
size: "m" | ||
}, | ||
hint: { text: @form.t("questions.disciplinary.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
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
57 changes: 57 additions & 0 deletions
57
spec/forms/journeys/further_education_payments/poor_performance_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,57 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::FurtherEducationPayments::PoorPerformanceForm, type: :model do | ||
let(:journey) { Journeys::FurtherEducationPayments } | ||
let(:journey_session) { create(:further_education_payments_session) } | ||
let(:subject_to_formal_performance_action) { nil } | ||
let(:subject_to_disciplinary_action) { nil } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
subject_to_formal_performance_action:, | ||
subject_to_disciplinary_action: | ||
} | ||
) | ||
end | ||
|
||
subject do | ||
described_class.new( | ||
journey_session:, | ||
journey:, | ||
params: | ||
) | ||
end | ||
|
||
describe "validations" do | ||
context "when no options selected" do | ||
it do | ||
is_expected.not_to( | ||
allow_value(nil) | ||
.for(:subject_to_formal_performance_action) | ||
.with_message("Select yes if you are subject to formal action for poor performance at work") | ||
) | ||
end | ||
|
||
it do | ||
is_expected.not_to( | ||
allow_value(nil) | ||
.for(:subject_to_disciplinary_action) | ||
.with_message("Select yes if you are subject to disciplinary action") | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:subject_to_formal_performance_action) { "true" } | ||
let(:subject_to_disciplinary_action) { "false" } | ||
|
||
it "updates the journey session" do | ||
expect { expect(subject.save).to be(true) }.to( | ||
change { journey_session.reload.answers.subject_to_formal_performance_action }.to(true) | ||
.and change { journey_session.reload.answers.subject_to_disciplinary_action }.to(false) | ||
) | ||
end | ||
end | ||
end |