Skip to content

Commit

Permalink
Add the chair of governors contact task
Browse files Browse the repository at this point in the history
This tasks forces users to collect the contact details for the chair of
governors of the school converting into an academy so that a copy of the
funding agreement letters can be sent to them.

This is our second attempt at a task that collects a contacts (we
already have 'main contact') and we wanted to try something different.

Here we collect the name, email and optionally phone number and the task
is only completed one we have these. This creates a contact and
populates it with the further information that we can derive from the
project:

- organisation = school name
- role (title) = Chair of governors
- establishment urn = Project.urn

Because of the way this works, 'deleting' the contact details in the
task and saving it WILL NOT delete the contact, this must be done via
External contacts > Change > Delete contact. Updating the details of the
contact will work, however.
  • Loading branch information
mec committed Mar 28, 2024
1 parent b2644a4 commit 70a84a1
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 1 deletion.
53 changes: 53 additions & 0 deletions app/forms/conversion/task/chair_of_governors_contact_task_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Conversion::Task::ChairOfGovernorsContactTaskForm < BaseTaskForm
attribute :name
attribute :email
attribute :phone

validates :email,
format: {with: URI::MailTo::EMAIL_REGEXP, message: "Enter a valid email address"},
allow_blank: true

validate :name_and_email_both_present?

def initialize(tasks_data, user)
@tasks_data = tasks_data
@user = user
@project = tasks_data.project
super(@tasks_data, @user)

@contact = @project.chair_of_governors_contact || Contact::Project.new

assign_attributes(
name: @contact.name,
email: @contact.email,
phone: @contact.phone
)
end

def save
if valid? && name.present? && email.present?
@contact.assign_attributes(
title: "Chair of governors",
category: :school_or_academy,
organisation_name: @project.establishment.name,
name: name,
email: email,
phone: phone,
project_id: @project.id,
establishment_urn: @project.urn
)
@contact.save!

@project.update!(chair_of_governors_contact: @contact)
end
end

def completed?
@project.chair_of_governors_contact.present?
end

private def name_and_email_both_present?
errors.add(:name, "Enter a name") if name.blank? && email.present?
errors.add(:email, "Enter an email address") if email.blank? && name.present?
end
end
1 change: 1 addition & 0 deletions app/models/conversion/task_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.layout
Conversion::Task::SponsoredSupportGrantTaskForm,
Conversion::Task::AcademyDetailsTaskForm,
Conversion::Task::MainContactTaskForm,
Conversion::Task::ChairOfGovernorsContactTaskForm,
Conversion::Task::ProposedCapacityOfTheAcademyTaskForm
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render(TaskList::TaskHeaderComponent.new(project: @project, task: @task)) %>
<% content_for :pre_content_nav do %>
<% render partial: "shared/back_link", locals: {href: project_tasks_path(@project)} %>
<% end %>
<% content_for :page_title do %>
<%= page_title(t("conversion.task.chair_of_governors_contact.title")) %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @task, url: project_edit_task_path(@project, @task.class.identifier), method: :put do |form| %>
<%= form.govuk_error_summary %>
<%= form.govuk_text_field :name, width: 20 %>
<%= form.govuk_email_field :email, width: 20 %>
<%= form.govuk_phone_field :phone, width: 10 %>
<%= form.govuk_submit t("task_list.continue_button.text") if policy(@tasks_data).update? %>
<% end %>
</div>

<div class="govuk-grid-column-one-third">
<%= render partial: "shared/tasks/task_notes" %>
</div>
</div>
14 changes: 14 additions & 0 deletions config/locales/conversion/tasks/chair_of_governors_contact.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
en:
conversion:
task:
chair_of_governors_contact:
title: Add chair of governors' contact details
hint:
html:
<p>Enter the chair of governors' name and email address. This is so they can receive their funding agreement letters.</p>
name:
title: Name
email:
title: Email
phone:
title: Phone
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
receive_grant_payment_certificate
update_esfa
confirm_date_academy_opened
chair_of_governors_contact
]

it "confirms we are checking all tasks" do
Expand Down Expand Up @@ -307,6 +308,81 @@
end
end

describe "the chair of governors contact task" do
let(:project) { create(:conversion_project, assigned_to: user) }

before do
visit project_tasks_path(project)
click_on "Add chair of governors' contact details"
end

scenario "can be submitted empty" do
click_on "Save and return"

expect(page).to have_selector "h2", text: "Task list"
end

scenario "validates that both name and email are supplied" do
fill_in "Name", with: "Jane Chair"
fill_in "Email", with: ""
click_on "Save and return"

expect(page).to have_content "Enter an email address"

fill_in "Name", with: ""
fill_in "Email", with: "[email protected]"
click_on "Save and return"

expect(page).to have_content "Enter a name"
end

scenario "validates the email format" do
fill_in "Name", with: "Jane Chair"
fill_in "Email", with: "jane.chair"
click_on "Save and return"

expect(page).to have_content "Enter a valid email"
end

scenario "creates a new contact as the chair of governors" do
fill_in "Name", with: "Jane Chair"
fill_in "Email", with: "[email protected]"
fill_in "Phone", with: "01234 567879"
click_on "Save and return"
click_on "External contacts"

expect(page).to have_content "Chair of governors"
expect(page).to have_content "Jane Chair"
expect(page).to have_content "[email protected]"
expect(page).to have_content "01234 567879"
expect(page).to have_content project.establishment.name
end

scenario "updates an existing chair of governors contact" do
chair_of_governors = create(:project_contact)
project.update(chair_of_governors_contact: chair_of_governors)

visit project_tasks_path(project)
click_on "Add chair of governors' contact details"

expect(page).to have_field "Name", with: chair_of_governors.name
expect(page).to have_field "Email", with: chair_of_governors.email
expect(page).to have_field "Phone", with: chair_of_governors.phone

fill_in "Name", with: "Jane Chair"
fill_in "Email", with: "[email protected]"
fill_in "Phone", with: "01234 567879"
click_on "Save and return"
click_on "External contacts"

expect(page).to have_content "Chair of governors"
expect(page).to have_content "Jane Chair"
expect(page).to have_content "[email protected]"
expect(page).to have_content "01234 567879"
expect(page).to have_content project.establishment.name
end
end

mandatory_tasks.each do |task|
scenario "a user can complete the actions on the mandatory #{I18n.t("conversion.task.#{task}.title")} task" do
click_on I18n.t("conversion.task.#{task}.title")
Expand Down
4 changes: 3 additions & 1 deletion spec/models/conversion/task_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
:sponsored_support_grant,
:academy_details,
:main_contact,
:chair_of_governors_contact,
:proposed_capacity_of_the_academy,
:land_questionnaire,
:land_registry,
Expand Down Expand Up @@ -58,6 +59,7 @@
Conversion::Task::SponsoredSupportGrantTaskForm,
Conversion::Task::AcademyDetailsTaskForm,
Conversion::Task::MainContactTaskForm,
Conversion::Task::ChairOfGovernorsContactTaskForm,
Conversion::Task::ProposedCapacityOfTheAcademyTaskForm
]
},
Expand Down Expand Up @@ -120,7 +122,7 @@
project = create(:conversion_project)
task_list = described_class.new(project, user)

expect(task_list.tasks.count).to eql 31
expect(task_list.tasks.count).to eql 32
expect(task_list.tasks.first).to be_a Conversion::Task::HandoverTaskForm
expect(task_list.tasks.last).to be_a Conversion::Task::ReceiveGrantPaymentCertificateTaskForm
end
Expand Down

0 comments on commit 70a84a1

Please sign in to comment.