Skip to content

Commit

Permalink
Update offer deadline text
Browse files Browse the repository at this point in the history
Candidates will no longer be DBD'd so we need to update the copy
that we show to providers to reflect this.
  • Loading branch information
JR-G committed Oct 5, 2023
1 parent 571174f commit 49ad49c
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
Waiting for candidate’s response
</h2>
<p class="govuk-body">
Your offer will be automatically declined <%= decline_by_default_text %> if the candidate does not respond.
<% if application_choice.continuous_applications? %>
<%= continuous_applications_offer_text %>
<% else %>
Your offer will be automatically declined <%= decline_by_default_text %> if the candidate does not respond.
<% end %>
</p>
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
module ProviderInterface
module ApplicationHeaderComponents
class OfferWillBeDeclinedByDefaultComponent < ApplicationChoiceHeaderComponent
def continuous_applications_offer_text
time_since_offer = days_from_now.zero? ? 'today' : "#{pluralize(days_from_now, 'day')} ago"

"You made this offer #{time_since_offer}. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond."
end

def days_from_now
(Time.zone.now.beginning_of_day - application_choice.offered_at.beginning_of_day).to_i / 1.day
end

def decline_by_default_text
return unless offer_will_be_declined_by_default?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
end
end

context 'when the application has had an offer' do
context 'when the application has had an offer and it is not continuous applications', continuous_applications: false do
let(:dbd_date) { nil }
let(:application_choice) { build_stubbed(:application_choice, status: 'offer', decline_by_default_at: dbd_date) }

Expand All @@ -109,6 +109,28 @@
end
end

context 'when the application has had an offer and it is continuous applications', :continuous_applications do
let(:application_choice) { create(:application_choice, :offered) }

context 'when the offer was made today' do
it 'renders the correct text' do
expect(result.css('.govuk-inset-text > h2').text).to include('Waiting for candidate’s response')
expect(result.css('.govuk-inset-text > p').text).to include('You made this offer today. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond.')
end
end

context 'when the offer was made before today' do
before do
application_choice.update(offered_at: 3.days.ago)
end

it 'renders the correct text' do
expect(result.css('.govuk-inset-text > h2').text).to include('Waiting for candidate’s response')
expect(result.css('.govuk-inset-text > p').text).to include('You made this offer 3 days ago. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond.')
end
end
end

context 'when the application is awaiting provider decision, reject by default is tomorrow and user cannot make decisions' do
let(:provider_can_respond) { false }
let(:provider_can_set_up_interviews) { false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,89 @@
require 'rails_helper'

RSpec.describe ProviderInterface::ApplicationHeaderComponents::OfferWillBeDeclinedByDefaultComponent do
describe 'rendered component' do
describe 'rendered component', :continuous_applications do
it 'renders offer will be declined content' do
application_choice = build_stubbed(:application_choice, :offered)
result = render_inline(described_class.new(application_choice:, provider_can_respond: true))

expect(result.css('h2').text.strip).to eq('Waiting for candidate’s response')
expect(result.css('.govuk-body').text).to match(/Your offer will be automatically declined in \d+ days .*? if the candidate does not respond/)
expect(result.css('.govuk-body').text).to match('You made this offer today. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond.')
end
end

describe '#decline_by_default_text' do
it 'returns nil if the application is not in the offer state' do
application_choice = build_stubbed(:application_choice, status: 'awaiting_provider_decision')
describe 'rendered component', continuous_applications: false do
it 'renders offer will be declined content' do
application_choice = build_stubbed(:application_choice, :offered)
result = render_inline(described_class.new(application_choice:, provider_can_respond: true))

expect(described_class.new(application_choice:).decline_by_default_text).to be_nil
expect(result.css('h2').text.strip).to eq('Waiting for candidate’s response')
expect(result.css('.govuk-body').text).to match(/Your offer will be automatically declined in \d+ days .*? if the candidate does not respond/)
end
end

context 'when not continuous applications', continuous_applications: false do
describe '#decline_by_default_text' do
it 'returns nil if the application is not in the offer state' do
application_choice = build_stubbed(:application_choice, status: 'awaiting_provider_decision')

describe 'returns the correct text when' do
it 'the dbd is today' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: Time.zone.now.end_of_day,
)
expect(described_class.new(application_choice:).decline_by_default_text).to be_nil
end

describe 'returns the correct text when' do
it 'the dbd is today' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: Time.zone.now.end_of_day,
)

expected_text = "at the end of today (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
end

it 'the dbd is tomorrow' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: 1.day.from_now.end_of_day,
)

expected_text = "at the end of today (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
expected_text = "at the end of tomorrow (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
end

it 'the dbd is after tomorrow' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: 3.days.from_now.end_of_day,
)

expected_text = "in 3 days (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
end
end
end
end

it 'the dbd is tomorrow' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: 1.day.from_now.end_of_day,
)
context 'when continuous applications', :continuous_applications do
describe '#continuous_applications_offer_text' do
context 'when the offer was made today' do
it 'renders the correct text' do
application_choice = build_stubbed(:application_choice, :continuous_applications, :offered)

expected_text = "at the end of tomorrow (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
expected_text = 'You made this offer today. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond.'
expect(described_class.new(application_choice:).continuous_applications_offer_text).to eq(expected_text)
end
end

it 'the dbd is after tomorrow' do
application_choice = build_stubbed(
:application_choice,
status: 'offer',
decline_by_default_at: 3.days.from_now.end_of_day,
)
context 'when the offer was made before today' do
it 'renders the correct text' do
application_choice = build_stubbed(:application_choice, :continuous_applications, :offered, offered_at: 3.days.ago)

expected_text = "in 3 days (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})"
expect(described_class.new(application_choice:).decline_by_default_text).to eq(expected_text)
expected_text = 'You made this offer 3 days ago. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond.'
expect(described_class.new(application_choice:).continuous_applications_offer_text).to eq(expected_text)
end
end
end
end
Expand Down

0 comments on commit 49ad49c

Please sign in to comment.