Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default class extends Controller {
const text = editor.getDocument().toString().trim();
if (text.length === 0) return 0;

const words = text.split(/\s+/).filter((word) => word.length > 0);
// '-' allows one-way street to be one word
const words = text.split(/(\w|-)+/);
return words.length;
}

Expand Down
27 changes: 6 additions & 21 deletions app/controllers/jobseekers/profiles/about_you_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class Jobseekers::Profiles::AboutYouController < Jobseekers::ProfilesController
def edit; end

def update
if form.valid?
@profile.update(about_you: form.about_you)
@profile.assign_attributes(about_you_richtext: form_params.fetch(:about_you))
if @profile.save(context: :about_you)
redirect_to jobseekers_profile_about_you_path
else
render :edit
Expand All @@ -12,29 +12,14 @@ def update

private

helper_method :form

def form
@form ||= form_class.new(form_attributes)
end

def form_attributes
case action_name
when "edit"
@profile.slice(:about_you)
when "update"
form_params
end
end

def form_class
Jobseekers::Profile::AboutYouForm
end
# def form_class
# Jobseekers::Profile::AboutYouForm
# end

# the new version doesn't allow empty submissions
# rubocop:disable Rails/StrongParametersExpect
def form_params
params.permit(jobseekers_profile_about_you_form: form_class.fields).require(:jobseekers_profile_about_you_form)
params.permit(jobseeker_profile: :about_you).require(:jobseeker_profile)
end
# rubocop:enable Rails/StrongParametersExpect
end
2 changes: 1 addition & 1 deletion app/controllers/jobseekers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Jobseekers::ProfilesController < Jobseekers::BaseController
page_path: -> { new_jobseekers_profile_work_history_path },
},
{
title: "About you",
title: "Your personal statement",
display_summary: ->(profile) { profile.about_you.present? },
key: "about_you",
condition: -> { profile.about_you.present? },
Expand Down
13 changes: 0 additions & 13 deletions app/form_models/jobseekers/profile/about_you_form.rb

This file was deleted.

16 changes: 16 additions & 0 deletions app/models/jobseeker_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ class JobseekerProfile < ApplicationRecord

has_encrypted :teacher_reference_number

has_rich_text :about_you_richtext

validates :about_you_richtext, presence: true, on: :about_you
validates :about_you_words, length: { maximum: 1500 }, if: -> { about_you_richtext.present? }, on: :about_you

validates :jobseeker, uniqueness: true

def about_you
about_you_richtext.presence || self[:about_you]
end

before_save do |profile|
unless profile.qualified_teacher_status == "yes"
profile.qualified_teacher_status_year = nil
Expand Down Expand Up @@ -100,4 +109,11 @@ def unexplained_employment_gaps
def current_or_most_recent_employment
employments.job.find_by(is_current_role: true) || employments.job.order(started_on: :desc).first
end

private

def about_you_words
# '-' allows one-way street to be one word
about_you_richtext.to_plain_text.scan(/(\w|-)+/)
end
end
40 changes: 20 additions & 20 deletions app/views/jobseekers/profiles/_summary.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,28 @@ dl.govuk-summary-list
- if profile.professional_body_memberships.any?
h2.govuk-heading-m class="govuk-!-padding-bottom-3" = t(".professional_body_memberships")
- profile.professional_body_memberships.each do |professional_body_membership|
= govuk_summary_list classes: "govuk-!-margin-bottom-0" do |summary_list|
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.name")
- row.with_value text: professional_body_membership.name
= govuk_summary_list classes: "govuk-!-margin-bottom-0" do |summary_list|
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.name")
- row.with_value text: professional_body_membership.name

- if professional_body_membership.membership_type.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.membership_type")
- row.with_value text: professional_body_membership.membership_type
- if professional_body_membership.membership_type.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.membership_type")
- row.with_value text: professional_body_membership.membership_type

- if professional_body_membership.membership_number.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.membership_number")
- row.with_value text: professional_body_membership.membership_number
- if professional_body_membership.membership_number.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.membership_number")
- row.with_value text: professional_body_membership.membership_number

- if professional_body_membership.year_membership_obtained.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.year_membership_obtained")
- row.with_value text: professional_body_membership.year_membership_obtained
- if professional_body_membership.year_membership_obtained.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.year_membership_obtained")
- row.with_value text: professional_body_membership.year_membership_obtained

- if professional_body_membership.exam_taken.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.exam_taken")
- row.with_value text: t("helpers.label.jobseekers_professional_body_membership_form.exam_taken_options.#{professional_body_membership.exam_taken}")
- if professional_body_membership.exam_taken.present?
- summary_list.with_row do |row|
- row.with_key text: t("helpers.label.jobseekers_professional_body_membership_form.exam_taken")
- row.with_value text: t("helpers.label.jobseekers_professional_body_membership_form.exam_taken_options.#{professional_body_membership.exam_taken}")
br
33 changes: 19 additions & 14 deletions app/views/jobseekers/profiles/about_you/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
- content_for :breadcrumbs do
= govuk_back_link text: t("buttons.back"), href: jobseekers_profile_path

.govuk-grid-row
.govuk-grid-column-two-thirds
= form_for form, url: jobseekers_profile_about_you_path, method: "patch" do |f|
= f.govuk_error_summary
= form_for @profile, url: jobseekers_profile_about_you_path, method: "patch" do |f|
= f.govuk_error_summary

= f.govuk_fieldset legend: { text: t(".page_title"), tag: "h1", size: "l" } do
= f.govuk_fieldset legend: { text: t(".page_title"), tag: "h1", size: "l" } do

p = t(".page_description")
p = t(".items_explanation")
p = t(".page_description")
p = t(".items_explanation")

ul.govuk-list.govuk-list--bullet
- t(".page_description_items").each do |item|
li.govuk-list-item = item
ul.govuk-list.govuk-list--bullet
- t(".page_description_items").each do |item|
li.govuk-list-item = item

= f.govuk_text_area :about_you, label: { size: "s" }, max_words: 1000, rows: 11
= tag.div data: { controller: "word-counter", word_counter_max_words_value: "1500" }
.govuk-form-group
= f.rich_text_area :about_you, aria: { label: t("helpers.label.jobseekers_profile_about_you_form.about_you") }, data: { word_counter_target: "editor" }
noscript
= f.govuk_text_area :about_you, label: { size: "s" }, max_words: 1500, rows: 11

= f.govuk_submit t("buttons.save_and_continue")
div class="govuk-hint govuk-!-margin-bottom-6"
= tag.span data: { word_counter_target: "counter" }

.govuk-button-group
= govuk_link_to t("buttons.cancel"), jobseekers_profile_path
= f.govuk_submit t("buttons.save_and_continue")

.govuk-button-group
= govuk_link_to t("buttons.cancel"), jobseekers_profile_path
8 changes: 3 additions & 5 deletions app/views/jobseekers/profiles/about_you/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
- content_for :breadcrumbs do
= govuk_back_link text: t("buttons.back"), href: jobseekers_profile_path

.govuk-grid-row
.govuk-grid-column-two-thirds
h1.govuk-heading-l = t(".page_title")
h1.govuk-heading-l = t(".page_title")

== render(partial: "summary", locals: { profile: @profile, title: t(".summary_title") })
== render(partial: "summary", locals: { profile: @profile, title: t(".summary_title") })

= govuk_button_link_to t("buttons.return_to_profile"), jobseekers_profile_path
= govuk_button_link_to t("buttons.return_to_profile"), jobseekers_profile_path
5 changes: 3 additions & 2 deletions config/locales/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ en:
jobseekers/profile/about_you_form:
attributes:
about_you:
blank: Enter your about you details
length: About you must be 1000 words or less
blank: Enter your personal statement
about_you_words:
too_long: Personal statement must be %{count} words or less
jobseekers/training_and_cpd_form:
attributes:
name:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ en:
other: Some other reason

jobseekers_profile_about_you_form:
about_you: About you
about_you: Your personal statement
jobseekers_qualifications_category_form:
<<: *jobseekers_qualifications_shared_labels
category_options:
Expand Down
12 changes: 6 additions & 6 deletions config/locales/jobseekers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -872,23 +872,23 @@ en:
You must complete your personal details, job preferences, professional status, qualifications and work history before you turn on your profile
about_you:
edit:
page_title: About You
page_title: Your personal statement
page_description: Describe your relevant skills, knowledge and experience. This will help schools see if you'd be a good fit for their role.
items_explanation: "If you're a teacher, this may include information about:"
page_description_items:
- "working with pupils"
- "your teaching style and classroom management"
- "your knowledge of the curriculum"
- "your understanding of safeguarding and student wellbeing"
- "your understanding of safeguarding and pupil wellbeing"
- "any extra training you’ve done"
- "additional responsibilities you’ve taken on in school"
- "experience in special educational needs and disability (SEND)"
- "any relevant interests or extra-curricular activities"
show:
page_title: About You
summary_title: About You
page_title: Your personal statement
summary_title: Your personal statemwent
summary:
about_you_title: About You
about_you_title: Your personal statement
training_and_cpds:
new:
<<: *training_shared
Expand Down Expand Up @@ -963,7 +963,7 @@ en:
update:
success: One role has been changed
summary:
about: About
about: Your personal statement
contact_details: Contact details
job_preferences: Job preferences
key_stages:
Expand Down
7 changes: 0 additions & 7 deletions spec/form_models/jobseekers/profile/about_you_form_spec.rb

This file was deleted.

24 changes: 24 additions & 0 deletions spec/models/jobseeker_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
require "rails_helper"

RSpec.describe JobseekerProfile, type: :model do
context "with about_you context" do
describe "about_you" do
subject { build(:jobseeker_profile, about_you_richtext: about_you_content).save(context: :about_you) }

context "with 1500 words" do
let(:about_you_content) { Faker::Lorem.sentence(word_count: 1500) }

it { is_expected.to be(true) }
end

context "with 1501 words" do
let(:about_you_content) { Faker::Lorem.sentence(word_count: 1501) }

it { is_expected.to be(false) }
end

context "when blank" do
let(:about_you_content) { "" }

it { is_expected.to be(false) }
end
end
end

describe ".prepare_associations" do
context "when the record is already persisted" do
let(:profile) { create(:jobseeker_profile) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "rails_helper"

RSpec.describe "Jobseekers can add a personal statement to their profile" do
let(:jobseeker) { create(:jobseeker) }

context "with a jobseeker" do
before { login_as(jobseeker, scope: :jobseeker) }

after { logout }

describe "#about_you" do
let(:jobseeker_about_you) { Faker::Movie.quote }

before do
visit edit_jobseekers_profile_about_you_path
end

it "allows the jobseeker to add #about_you without JS" do
expect(page).to have_content("Your personal statement")
fill_in "jobseeker_profile[about_you]", with: jobseeker_about_you
click_on I18n.t("buttons.save_and_continue")

expect(page).to have_content(jobseeker_about_you)

click_link I18n.t("buttons.return_to_profile")
expect(page).to have_content(jobseeker_about_you)
end

it "allows the jobseeker to add #about_you", :js do
expect(page).to have_content("Your personal statement")
fill_in_trix_editor "jobseeker_profile_about_you", with: jobseeker_about_you
click_on I18n.t("buttons.save_and_continue")

expect(page).to have_content(jobseeker_about_you)

click_link I18n.t("buttons.return_to_profile")
expect(page).to have_content(jobseeker_about_you)
end
end
end
end
19 changes: 0 additions & 19 deletions spec/system/jobseekers/jobseekers_can_manage_a_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@

after { logout }

describe "#about_you" do
let(:jobseeker_about_you) { "I am an amazing teacher" }

before do
visit jobseekers_profile_path
click_link("Add details about you")
end

it "allows the jobseeker to add #about_you" do
fill_in "jobseekers_profile_about_you_form[about_you]", with: jobseeker_about_you
click_on I18n.t("buttons.save_and_continue")

expect(page).to have_content(jobseeker_about_you)

click_link I18n.t("buttons.return_to_profile")
expect(page).to have_content(jobseeker_about_you)
end
end

describe "changing the jobseekers's QTS status" do
before do
visit jobseekers_profile_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
let(:login_user) { trust_publisher }
let(:login_organisation) { trust }

it "passes a11y", :a11y do
it "passes a11y", :a11y, :retry do
expect(page).to have_content("Inbox (2)")
expect(page).to be_axe_clean
end
Expand Down
Loading