-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
spec/services/provider_interface/candidate_withdrawal_reasons_data_by_provider_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ProviderInterface::CandidateWithdrawalReasonsDataByProvider do | ||
let(:provider) { create(:provider) } | ||
|
||
describe '#all_rows' do | ||
context 'when there are fewer then 10 withdrawals from unique application forms' do | ||
it 'returns an empty array' do | ||
application_forms = create_list(:application_form, 9) | ||
application_forms.each do |application_form| | ||
application_choice = create(:application_choice, :withdrawn, application_form:, provider_ids: [provider.id]) | ||
create(:withdrawal_reason, status: 'published', application_choice:, reason: WithdrawalReason.all_reasons.sample) | ||
end | ||
|
||
expect(described_class.new(provider).all_rows).to eq [] | ||
end | ||
end | ||
|
||
context 'when there are at least 10 withdrawals from unique application forms' do | ||
it 'returns data for the report' do | ||
create_list(:application_form, 10).each do |application_form| | ||
application_choice = create(:application_choice, :withdrawn, application_form:, provider_ids: [provider.id]) | ||
create(:withdrawal_reason, status: 'published', application_choice:, reason: 'applying-to-another-provider.accepted-another-offer') | ||
end | ||
|
||
rows = described_class.new(provider).all_rows | ||
|
||
main_reason_row = rows.find { |row| row.reason[:text] == 'I am going to apply (or have applied) to a different training provider' } | ||
expect(main_reason_row.total[:text]).to eq 10 | ||
|
||
level_two_reason_row = rows.find { |row| row.reason[:text] == 'I have accepted another offer' } | ||
expect(level_two_reason_row.total[:text]).to eq 10 | ||
end | ||
end | ||
|
||
context 'where there is a mix of withdrawals before and after the candidate has accepted an offer' do | ||
it 'returns data for the report' do | ||
create_list(:application_form, 5).each do |application_form| | ||
application_choice = create(:application_choice, :accepted, application_form:, provider_ids: [provider.id]) | ||
create(:withdrawal_reason, status: 'published', application_choice:, reason: 'applying-to-another-provider.accepted-another-offer') | ||
end | ||
|
||
create_list(:application_form, 5).each do |application_form| | ||
application_choice = create(:application_choice, :withdrawn, application_form:, provider_ids: [provider.id]) | ||
create(:withdrawal_reason, status: 'published', application_choice:, reason: 'applying-to-another-provider.accepted-another-offer') | ||
end | ||
|
||
rows = described_class.new(provider).all_rows | ||
main_reason_row = rows.find { |row| row.reason[:text] == 'I am going to apply (or have applied) to a different training provider' } | ||
|
||
expect(main_reason_row.total[:text]).to eq 10 | ||
expect(main_reason_row.before_accepting[:text]).to eq 5 | ||
expect(main_reason_row.after_accepting[:text]).to eq 5 | ||
|
||
level_two_reason_row = rows.find { |row| row.reason[:text] == 'I have accepted another offer' } | ||
expect(level_two_reason_row.total[:text]).to eq 10 | ||
expect(level_two_reason_row.before_accepting[:text]).to eq 5 | ||
expect(level_two_reason_row.after_accepting[:text]).to eq 5 | ||
end | ||
end | ||
end | ||
end |
55 changes: 55 additions & 0 deletions
55
spec/system/provider_interface/reports/provider_views_withdrawal_reasons_report_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Provider views withdrawal reports' do | ||
include DfESignInHelpers | ||
|
||
before do | ||
FeatureFlag.activate(:new_candidate_withdrawal_reasons) | ||
end | ||
|
||
scenario 'Provider navigates to report where fewer than 10 candidates have provided withdrawal reasons' do | ||
given_some_candidates_have_withdrawn_applications(9) | ||
and_i_sign_in_as_a_provider_user | ||
when_i_navigate_to_the_withdrawal_reasons_report | ||
then_i_see_the_report_without_data | ||
end | ||
|
||
scenario 'Provider navigates to the report where at least 10 candidates have provided withdrawal reasons' do | ||
given_some_candidates_have_withdrawn_applications(10) | ||
and_i_sign_in_as_a_provider_user | ||
when_i_navigate_to_the_withdrawal_reasons_report | ||
then_i_see_the_report_with_data | ||
end | ||
|
||
private | ||
|
||
def given_some_candidates_have_withdrawn_applications(number_of_applications) | ||
provider_user = create(:provider_user, :with_dfe_sign_in, email_address: '[email protected]') | ||
provider = provider_user.providers.first | ||
application_forms = create_list(:application_form, number_of_applications) | ||
application_forms.each do |application_form| | ||
application_choice = create(:application_choice, :withdrawn, application_form: application_form, provider_ids: [provider.id]) | ||
create(:withdrawal_reason, status: 'published', application_choice:, reason: WithdrawalReason.all_reasons.sample) | ||
end | ||
end | ||
|
||
def and_i_sign_in_as_a_provider_user | ||
provider_exists_in_dfe_sign_in | ||
provider_signs_in_using_dfe_sign_in | ||
end | ||
|
||
|
||
def when_i_navigate_to_the_withdrawal_reasons_report | ||
click_on 'Reports' | ||
click_on 'Withdrawals' | ||
click_on 'Withdrawal reasons: from January 2025' | ||
end | ||
|
||
def then_i_see_the_report_without_data | ||
expect(page).to have_content 'You will be able to see this report when it contains data from at least 10 candidates.' | ||
end | ||
|
||
def then_i_see_the_report_with_data | ||
expect(page).to have_content 'This report shows the reasons for withdrawal selected by candidates from a set list. The question is mandatory and candidates can select more than one reason.' | ||
end | ||
end |