Skip to content

Commit

Permalink
Add AddAnotherQualificationForm
Browse files Browse the repository at this point in the history
This adds a new form for capturing the logic around adding a new
qualification to ensure we can add validation correctly.
  • Loading branch information
thomasleese committed Feb 28, 2024
1 parent 0b4c4bf commit 87ba13a
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 73 deletions.
54 changes: 33 additions & 21 deletions app/controllers/teacher_interface/qualifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,47 @@ def update_part_of_degree
end

def add_another
@form = AddAnotherQualificationForm.new
end

def submit_add_another
if ActiveModel::Type::Boolean.new.cast(
params.dig(:qualification, :add_another),
)
history_stack.replace_self(
path: check_teacher_interface_application_form_qualifications_path,
origin: false,
check: true,
@form =
AddAnotherQualificationForm.new(
add_another:
params.dig(
:teacher_interface_add_another_qualification_form,
:add_another,
),
)

redirect_to %i[new teacher_interface application_form qualification]
else
came_from_check_collection =
history_stack.last_entry&.fetch(:path) ==
check_teacher_interface_application_form_qualifications_path
if @form.save(validate: true)
if @form.add_another
history_stack.replace_self(
path: check_teacher_interface_application_form_qualifications_path,
origin: false,
check: true,
)

if came_from_check_collection ||
application_form.qualifications.count == 1
redirect_to %i[teacher_interface application_form]
redirect_to %i[new teacher_interface application_form qualification]
else
redirect_to %i[
check
teacher_interface
application_form
qualifications
]
came_from_check_collection =
history_stack.last_entry&.fetch(:path) ==
check_teacher_interface_application_form_qualifications_path

if came_from_check_collection ||
application_form.qualifications.count == 1
redirect_to %i[teacher_interface application_form]
else
redirect_to %i[
check
teacher_interface
application_form
qualifications
]
end
end
else
render :add_another, status: :unprocessable_entity
end
end

Expand Down
11 changes: 11 additions & 0 deletions app/forms/teacher_interface/add_another_qualification_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module TeacherInterface
class AddAnotherQualificationForm < BaseForm
attribute :add_another, :boolean
validates :add_another, inclusion: { in: [true, false] }

def update_model
end
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% content_for :page_title, t("application_form.tasks.sections.qualifications") %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_path) %>

<span class="govuk-caption-l"><%= I18n.t("application_form.tasks.sections.qualifications") %></span>

<%= form_with model: Qualification.new, url: %i[add_another teacher_interface application_form qualifications] do |f| %>
<%= form_with model: @form, url: %i[add_another teacher_interface application_form qualifications] do |f| %>
<%= f.govuk_error_summary %>

<span class="govuk-caption-l"><%= I18n.t("application_form.tasks.sections.qualifications") %></span>

<%= f.govuk_collection_radio_buttons :add_another,
[OpenStruct.new(value: :true), OpenStruct.new(value: :false)],
:value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% content_for :page_title, t(".title") %>
<% content_for :back_link_url, back_history_path(default: teacher_interface_application_form_work_histories_path) %>

<%= form_with model: @form, url: %i[add_another teacher_interface application_form work_histories], method: :post do |f| %>
<%= form_with model: @form, url: %i[add_another teacher_interface application_form work_histories] do |f| %>
<%= f.govuk_error_summary %>

<h1 class="govuk-heading-l">
Expand Down
14 changes: 6 additions & 8 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ en:
region_id: This means you have all the qualifications needed to teach in a state school.<br /><br />You’ll need to show that you completed your teaching qualification in the country that you select.
eligibility_interface_work_experience_form:
work_experience: Your teaching work experience can be gained in any country but must be from after you qualified as a teacher.
qualification:
add_another: You can use the next section to tell us about additional degrees if you want to.
teacher:
email: We’ll use this to send you an email with a link to continue with your QTS application. Do not use a work or university email that you might lose access to.
teacher_interface_add_another_qualification_form:
add_another: You can use the next section to tell us about additional degrees if you want to.
teacher_interface_alternative_name_form:
has_alternative_name: If your name appears differently on your ID documents or qualifications you need to upload proof of your name change, for example, your marriage or civil partnership certificate.
alternative_given_names: Enter your full name apart from your family name
Expand Down Expand Up @@ -161,12 +161,12 @@ en:
reference_hint: Reference hint
accepted_tests: Accepted tests (we can accept)
check_url: Check website
qualification:
teacher:
email: Email address
teacher_interface_add_another_qualification_form:
add_another_options:
true: "Yes"
false: "No"
teacher:
email: Email address
teacher_interface_add_another_work_history_form:
add_another_options:
true: "Yes"
Expand Down Expand Up @@ -300,7 +300,7 @@ en:
region_id: In which state/territory are you currently recognised as a teacher?
eligibility_interface_work_experience_form:
work_experience: How long have you worked as a recognised teacher?
qualification:
teacher_interface_add_another_qualification_form:
add_another: Add another qualification?
teacher_interface_add_another_work_history_form:
add_another: Add another role?
Expand Down Expand Up @@ -340,5 +340,3 @@ en:
start_date: When did you start this role?
still_employed: Are you still employed at this school?
end_date: Your end date
work_history:
add_another: Add another workplace?
4 changes: 4 additions & 0 deletions config/locales/teacher_interface.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ en:
blank: Enter your alternate family name
has_alternative_name:
inclusion: Tell us whether you have an alternative name
teacher_interface/add_another_qualification_form:
attributes:
add_another:
inclusion: Select whether you need to add another qualification
teacher_interface/add_another_upload_form:
attributes:
add_another:
Expand Down
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@
collection do
get "check", to: "qualifications#check_collection"

get "add_another", to: "qualifications#add_another"
post "add_another", to: "qualifications#submit_add_another"
get "add-another", to: "qualifications#add_another"
post "add-another", to: "qualifications#submit_add_another"

get "part-of-degree", to: "qualifications#edit_part_of_degree"
post "part-of-degree", to: "qualifications#update_part_of_degree"
Expand Down Expand Up @@ -313,8 +313,8 @@
collection do
get "check", to: "work_histories#check_collection"

get "add_another"
post "add_another", to: "work_histories#submit_add_another"
get "add-another"
post "add-another", to: "work_histories#submit_add_another"

get "requirements_unmet", to: "work_histories#requirements_unmet"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe TeacherInterface::AddAnotherQualificationForm, type: :model do
subject(:form) { described_class.new }

it { is_expected.to allow_values(true, false).for(:add_another) }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module PageObjects
module TeacherInterface
class AddAnother < SitePrism::Page
element :heading, "h1"

section :form, "form" do
section :true_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(1)"
section :false_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(2)"

element :submit_button, ".govuk-button:not(.govuk-button--secondary)"
end

def submit_yes
form.true_radio_item.choose
form.submit_button.click
end

def submit_no
form.false_radio_item.choose
form.submit_button.click
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

module PageObjects
module TeacherInterface
class AddAnotherQualification < SitePrism::Page
set_url "/teacher/application/qualifications/add_another"

element :heading, "h1"

section :form, "form" do
section :true_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(1)"
section :false_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(2)"

element :continue_button, ".govuk-button:not(.govuk-button--secondary)"
end
class AddAnotherQualification < AddAnother
set_url "/teacher/application/qualifications/add-another"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

module PageObjects
module TeacherInterface
class AddAnotherWorkHistory < SitePrism::Page
set_url "/teacher/application/work_histories/add_another"

element :heading, "h1"

section :form, "form" do
section :true_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(1)"
section :false_radio_item,
PageObjects::GovukRadioItem,
".govuk-radios__item:nth-of-type(2)"

element :continue_button, ".govuk-button:not(.govuk-button--secondary)"
end
class AddAnotherWorkHistory < AddAnother
set_url "/teacher/application/work_histories/add-another"
end
end
end
3 changes: 1 addition & 2 deletions spec/system/teacher_interface/back_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ def when_i_click_change_certificate_document_title
end

def when_i_add_another_qualification
teacher_add_another_qualification_page.form.true_radio_item.choose
teacher_add_another_qualification_page.form.continue_button.click
teacher_add_another_qualification_page.submit_yes
end

def teacher
Expand Down
3 changes: 1 addition & 2 deletions spec/system/teacher_interface/qualifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def when_i_click_continue
end

def when_i_dont_add_another_qualification
teacher_add_another_qualification_page.form.false_radio_item.choose
teacher_add_another_qualification_page.form.continue_button.click
teacher_add_another_qualification_page.submit_no
end

def and_i_see_three_qualifications
Expand Down
3 changes: 1 addition & 2 deletions spec/system/teacher_interface/work_history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def and_i_see_the_heading_with_the_number_of_months
end

def when_i_dont_add_another_work_history
teacher_add_another_work_history_page.form.false_radio_item.choose
teacher_add_another_work_history_page.form.continue_button.click
teacher_add_another_work_history_page.submit_no
end

def and_i_see_three_work_histories
Expand Down

0 comments on commit 87ba13a

Please sign in to comment.