Skip to content

Commit

Permalink
Merge pull request #9781 from DFE-Digital/cv/allow-work-history-edits
Browse files Browse the repository at this point in the history
Allow candidate to edit work histories
  • Loading branch information
CatalinVoineag authored Sep 26, 2024
2 parents 4b8e131 + b7ca3bc commit cc43927
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 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.not_included_in_submitted_personal_statement') %>
<% elsif @section_policy.work_history? %>
<%= t('editable_section_warning.not_included_in_submitted') %>
<% else %>
Any changes you make will be included in applications you have already submitted.
<%= t('editable_section_warning.included_in_submitted') %>
<% 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:
not_included_in_submitted_personal_statement: Any changes you make to your personal statement will not be included in applications you have already submitted.
not_included_in_submitted: Any changes you make will not be included in applications you have already submitted.
included_in_submitted: Any changes you make will be included in applications you have already submitted.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let(:current_application) { create(:application_form, :completed, submitted_application_choices_count: 1) }

context 'when candidate can edit the section' do
let(:section_policy) { instance_double(CandidateInterface::SectionPolicy, can_edit?: true, personal_statement?: false) }
let(:section_policy) { instance_double(CandidateInterface::SectionPolicy, can_edit?: true, personal_statement?: false, work_history?: false) }

it 'renders message' do
expect(result.text).to include(
Expand All @@ -28,6 +28,16 @@
)
end
end

context 'when the canidate can edit the section and it is the work_history' do
let(:section_policy) { instance_double(CandidateInterface::SectionPolicy, can_edit?: true, personal_statement?: false, work_history?: true) }

it 'renders message' do
expect(result.text).to include(
'Any changes you make will not be included in applications you have already submitted.',
)
end
end
end

context 'when candidate can not edit the section' do
Expand Down
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 All @@ -52,7 +61,18 @@ def then_i_can_see_that_is_editable
end

def and_i_can_edit_the_section
expect(page).to have_content('Any changes you make will be included in applications you have already submitted.') unless @section.identifier == :personal_statement
work_experiences = %i[unpaid_experience work_history]

expected_content = if @section.identifier == :personal_statement
'Any changes you make to your personal statement will not be included in applications you have already submitted.'
elsif work_experiences.include?(@section.identifier)
'Any changes you make will not be included in applications you have already submitted.'
else
'Any changes you make will be included in applications you have already submitted.'
end

expect(page).to have_content(expected_content)

method_name = "and_i_can_edit_the_section_#{@section.identifier}"

if respond_to?(method_name)
Expand Down Expand Up @@ -132,6 +152,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 cc43927

Please sign in to comment.