diff --git a/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.html.erb b/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.html.erb index 01493bf7f23..67505b05222 100644 --- a/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.html.erb +++ b/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.html.erb @@ -2,5 +2,9 @@ Waiting for candidate’s response
- <%= offer_text %> + <% 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 %>
diff --git a/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.rb b/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.rb index 05e8129cca0..d5b25524c42 100644 --- a/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.rb +++ b/app/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component.rb @@ -1,11 +1,22 @@ module ProviderInterface module ApplicationHeaderComponents class OfferWillBeDeclinedByDefaultComponent < ApplicationChoiceHeaderComponent - def offer_text + def continuous_applications_offer_text days = application_choice.days_since_offered "You made this offer #{days_since(days)}. Most candidates respond to offers within 15 working days. The candidate will receive reminders to respond." end + + def decline_by_default_text + return unless offer_will_be_declined_by_default? + + if time_is_today_or_tomorrow?(application_choice.decline_by_default_at) + "at the end of #{date_and_time_today_or_tomorrow(application_choice.decline_by_default_at)}" + else + days_remaining = days_until(application_choice.decline_by_default_at.to_date) + "in #{days_remaining} (#{application_choice.decline_by_default_at.to_fs(:govuk_date_and_time)})" + end + end end end end diff --git a/spec/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component_spec.rb b/spec/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component_spec.rb index 26c79bbd68c..aa7574a0b95 100644 --- a/spec/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component_spec.rb +++ b/spec/components/provider_interface/application_header_components/offer_will_be_declined_by_default_component_spec.rb @@ -11,13 +11,68 @@ end end - describe '#offer_text' do + 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(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') + + 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 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 + + 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 = '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:).offer_text).to eq(expected_text) + expect(described_class.new(application_choice:).continuous_applications_offer_text).to eq(expected_text) end end @@ -26,7 +81,7 @@ application_choice = build_stubbed(:application_choice, :continuous_applications, :offered, offered_at: 3.days.ago) 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:).offer_text).to eq(expected_text) + expect(described_class.new(application_choice:).continuous_applications_offer_text).to eq(expected_text) end end end