Skip to content

Commit

Permalink
Merge pull request #2937 from DFE-Digital/fe-teaching-qualification
Browse files Browse the repository at this point in the history
[LUPEYALPHA-554] add teaching qualification form to FE journey
  • Loading branch information
asmega authored Jul 2, 2024
2 parents 519e8f8 + a5dc857 commit b3639c0
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Journeys
module FurtherEducationPayments
class TeachingQualificationForm < Form
attribute :teaching_qualification, :string

validates :teaching_qualification,
presence: {message: i18n_error_message(:inclusion)},
inclusion: {in: ->(form) { form.radio_options.map(&:id) }, message: i18n_error_message(:inclusion)}

def radio_options
[
OpenStruct.new(
id: "yes",
name: "Yes"
),
OpenStruct.new(
id: "not-yet",
name: "Not yet, I am currently enrolled on one and working towards completing it"
),
OpenStruct.new(
id: "no-but-planned",
name: "No, but I plan to enrol on one in the next 12 months"
),
OpenStruct.new(
id: "no-not-planned",
name: "No, and I do not plan to enrol on one in the next 12 months "
)
]
end

def save
return false unless valid?

journey_session.answers.assign_attributes(teaching_qualification:)
journey_session.save!
end
end
end
end
3 changes: 2 additions & 1 deletion app/models/journeys/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module FurtherEducationPayments
"contract-type" => ContractTypeForm,
"teaching-hours-per-week" => TeachingHoursPerWeekForm,
"further-education-teaching-start-year" => FurtherEducationTeachingStartYearForm,
"subjects-taught" => SubjectsTaughtForm
"subjects-taught" => SubjectsTaughtForm,
"teaching-qualification" => TeachingQualificationForm
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SessionAnswers < Journeys::SessionAnswers
attribute :teaching_hours_per_week, :string
attribute :further_education_teaching_start_year, :string
attribute :subjects_taught, default: []
attribute :teaching_qualification, :string

def school
@school ||= School.find(school_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SlugSequence
building-and-construction-courses
teaching-courses
half-teaching-hours
qualification
teaching-qualification
poor-performance
]

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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_collection_radio_buttons :teaching_qualification, @form.radio_options, :id, :name,
legend: {
text: @form.t(:question),
tag: "h1",
size: "l"
},
hint: { text: @form.t(:hint) } %>

<%= f.govuk_submit %>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,11 @@ en:
hint: Select all that apply
errors:
inclusion: Select the subject areas you teach in or select you do not teach any of the listed subject areas
teaching_qualification:
question: Do you have a teaching qualification?
hint: Your response will be noted for future claims. If you don’t have a teaching qualification yet, make sure that you enrol on one or complete one in the next 12 months.
errors:
inclusion: Select whether you have, are currently enrolled or plan to enrol on a teaching qualification
activerecord:
errors:
models:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
expect(page).to have_content("FE half teaching hours goes here")
click_button "Continue"

expect(page).to have_content("FE qualification goes here")
expect(page).to have_content("Do you have a teaching qualification?")
choose("Yes")
click_button "Continue"

expect(page).to have_content("FE poor performance 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 @@ -48,7 +48,8 @@
expect(page).to have_content("FE half teaching hours goes here")
click_button "Continue"

expect(page).to have_content("FE qualification goes here")
expect(page).to have_content("Do you have a teaching qualification?")
choose("Yes")
click_button "Continue"

expect(page).to have_content("FE poor performance goes here")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "rails_helper"

RSpec.describe Journeys::FurtherEducationPayments::TeachingQualificationForm, type: :model do
let(:journey) { Journeys::FurtherEducationPayments }
let(:journey_session) { create(:further_education_payments_session) }
let(:teaching_qualification) { nil }

let(:params) do
ActionController::Parameters.new(
claim: {
teaching_qualification:
}
)
end

subject do
described_class.new(
journey_session:,
journey:,
params:
)
end

describe "validations" do
context "when no option selected" do
let(:teaching_qualification) { nil }

it do
is_expected.not_to(
allow_value(nil)
.for(:teaching_qualification)
.with_message("Select whether you have, are currently enrolled or plan to enrol on a teaching qualification")
)
end
end

context "when non-existent injection option selected" do
let(:teaching_qualification) { "foo" }

it do
is_expected.not_to(
allow_value("foo")
.for(:teaching_qualification)
.with_message("Select whether you have, are currently enrolled or plan to enrol on a teaching qualification")
)
end
end
end

describe "#save" do
let(:teaching_qualification) { "yes" }

it "updates the journey session" do
expect { expect(subject.save).to be(true) }.to(
change { journey_session.reload.answers.teaching_qualification }.to("yes")
)
end
end
end

0 comments on commit b3639c0

Please sign in to comment.