Skip to content

Commit

Permalink
Allow candidate to edit work histories
Browse files Browse the repository at this point in the history
We want to allow the candidate to edit their work histories, this will
only edit work experiences, volunteering_experiences and work history
breaks on the application form.

The application choices that are submitted will still have the old work
histories. This is because each submitted application choice has its own
work history.

So the user will be able to edit their work histories but only for new
application choices.
  • Loading branch information
CatalinVoineag committed Sep 24, 2024
1 parent 02de77c commit 7d5be4e
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="govuk-inset-text">
<% if @section_policy.personal_statement? %>
Any changes you make to your personal statement will not be included in applications you have already submitted.
<%= t('editable_section_warning.personal_statement') %>
<% elsif @section_policy.work_history? %>
<%= t('editable_section_warning.work_history') %>
<% else %>
Any changes you make will be included in applications you have already submitted.
<%= t('editable_section_warning.default') %>
<% end %>
</div>
9 changes: 9 additions & 0 deletions app/services/candidate_interface/section_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ def personal_statement?
@controller_path.classify.eql?('CandidateInterface::PersonalStatement')
end

def work_history?
controllers = [
'CandidateInterface::RestructuredWorkHistory::Review',
'CandidateInterface::Volunteering::Review',
]

controllers.include?(@controller_path.classify)
end

private

delegate :any_offer_accepted?, to: :current_application
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class Application < Rails::Application
becoming_a_teacher
science_gcse
efl
work_history
volunteering
]
config.x.sections.editable_window_days = 5
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
en:
editable_section_warning:
personal_statement: Any changes you make to your personal statement will not be included in applications you have already submitted.
default: Any changes you make will be included in applications you have already submitted.
work_history: Any changes you make will not be included in applications you have already submitted.
1 change: 1 addition & 0 deletions spec/factories/application_volunteering_experience.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :application_volunteering_experience do
role { ['Teacher', 'Teaching Assistant'].sample }
currently_working { true }
organisation { Faker::Educator.secondary_school }
details { Faker::Lorem.paragraph_by_chars(number: 300) }
working_with_children { [true, true, true, false].sample }
Expand Down
42 changes: 42 additions & 0 deletions spec/services/candidate_interface/section_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@
expect(section_policy.can_edit?).to be false
end
end

context 'when accessing work history' do
let(:controller_path) { 'candidate_interface/restructured_work_history/review' }

it 'returns true' do
expect(section_policy.can_edit?).to be true
end
end

context 'when accessing volunteering experiences' do
let(:controller_path) { 'candidate_interface/volunteering/review' }

it 'returns true' do
expect(section_policy.can_edit?).to be true
end
end
end

context 'when candidates already submitted and adds a primary course choice and visits science GCSE' do
Expand Down Expand Up @@ -258,4 +274,30 @@
end
end
end

describe '#work_history?' do
context 'with work_history controller' do
let(:controller_path) { 'candidate_interface/restructured_work_history/review' }

it 'returns true' do
expect(section_policy.work_history?).to be true
end
end

context 'with volinteering experiences controller' do
let(:controller_path) { 'candidate_interface/volunteering/review' }

it 'returns true' do
expect(section_policy.work_history?).to be true
end
end

context 'without work history controllers' do
let(:controller_path) { 'candidate_interface/personal_details/review' }

it 'returns true' do
expect(section_policy.work_history?).to be false
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
TestSection.new(:interview_availability, 'Interview availability'),
TestSection.new(:equality_and_diversity_information, 'Equality and diversity questions'),
TestSection.new(:personal_statement, 'Your personal statement'),
TestSection.new(:work_history, 'Work history'),
TestSection.new(:unpaid_experience, 'Unpaid experience'),
].each do |section|
scenario "candidate can edit section '#{section.title}' after submission" do
@section = section
Expand All @@ -35,7 +37,14 @@
end

def given_i_already_have_one_submitted_application
application_form = create(:application_form, :completed, candidate: current_candidate)
application_form = create(
:application_form,
:completed,
candidate: current_candidate,
volunteering_experiences_count: 1,
full_work_history: true,
work_history_status: :can_complete,
)
create(:application_choice, :awaiting_provider_decision, application_form:)
end

Expand Down Expand Up @@ -132,6 +141,34 @@ def and_i_can_edit_the_section_personal_statement
expect(current_candidate.current_application.reload.becoming_a_teacher).to eq('Repellat qui et')
end

def and_i_can_edit_the_section_work_history
work_experience = current_candidate.current_application.application_work_experiences.first
work_break = current_candidate.current_application.application_work_history_breaks.first
click_link_or_button "Change job #{work_experience.role} for #{work_experience.organisation}"
fill_in 'Name of employer', with: 'New employer'
when_i_save_and_continue

click_link_or_button(
'Change entry for break between ' \
"#{work_break.start_date.to_fs(:short_month_and_year)} and " \
"#{work_break.end_date.to_fs(:short_month_and_year)}",
)
fill_in 'Enter reasons for break in work history', with: 'New reason'
when_i_click_continue

expect(work_experience.reload.organisation).to eq('New employer')
expect(work_break.reload.reason).to eq('New reason')
end

def and_i_can_edit_the_section_unpaid_experience
volunteering = current_candidate.current_application.application_volunteering_experiences.first
click_link_or_button "Change role for #{volunteering.role}, #{volunteering.organisation}"
fill_in 'Your role', with: 'New role'
when_i_save_and_continue

expect(volunteering.reload.role).to eq('New role')
end

def section_status
page.find(:xpath, "//a[contains(text(),'#{@section.title}')]/..").text
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
NonEditableSection.new(:degree, 'Degree'),
NonEditableSection.new(:references, 'References to be requested if you accept an offer'),
NonEditableSection.new(:safeguarding, 'Declare any safeguarding issues'),
NonEditableSection.new(:work_history, 'Work history'),
NonEditableSection.new(:unpaid_experience, 'Unpaid experience'),
].each do |section|
scenario "candidate can not edit section '#{section.title}' after submission" do
@section = section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
RSpec.describe 'Trying to enter work history' do
include CandidateHelper

scenario 'Candidate does not see Add job or Add another job buttons' do
scenario 'Candidate does see Add job or Add another job buttons' do
given_i_am_signed_in
and_i_have_completed_work_history
and_i_have_a_submitted_application
when_i_view_work_history
then_i_do_not_see_an_option_to_add_another_job
then_i_do_see_an_option_to_add_another_job
end

def given_i_am_signed_in
Expand All @@ -31,9 +31,8 @@ def and_i_have_a_submitted_application
create(:application_choice, :awaiting_provider_decision, application_form: @application_form_can_complete_work_history)
end

def then_i_do_not_see_an_option_to_add_another_job
def then_i_do_see_an_option_to_add_another_job
expect(page).to have_content 'Work history'
expect(page).to have_no_content 'Add another job'
expect(page).to have_no_content 'Add job'
expect(page).to have_content 'Add another job'
end
end

0 comments on commit 7d5be4e

Please sign in to comment.