Skip to content

Commit

Permalink
Update end-of-cycle banner content and conditions for rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Jun 24, 2024
1 parent f6dddb7 commit 878f9e6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= govuk_notification_banner(title_text: t('notification_banner.important')) do |notification_banner| %>
<% notification_banner.with_heading(text: "The deadline for applying to courses starting in the #{academic_year} academic year is #{deadline[:time]} on #{deadline[:date]}") %>
<p class="govuk-body">Courses may fill up before then. Check course availability with your provider.</p>
<% notification_banner.with_heading(text: t('heading', academic_year:, deadline_time: deadline[:time], deadline_date: deadline[:date])) %>
<p class="govuk-body"><%= t('text') %></p>
<% end %>
29 changes: 5 additions & 24 deletions app/components/candidate_interface/deadline_banner_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ def initialize(application_form:, flash_empty:)
end

def render?
flash_empty && render_deadline_banner?
flash_empty && CycleTimetable.show_apply_deadline_banner?(@application_form)
end

def deadline
if CycleTimetable.show_apply_2_deadline_banner?(@application_form)
apply_2_deadline
else
apply_1_deadline
end
{
date: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_date),
time: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_time),
}
end

def academic_year
Expand All @@ -24,24 +23,6 @@ def academic_year

private

def render_deadline_banner?
CycleTimetable.show_apply_1_deadline_banner?(@application_form) || CycleTimetable.show_apply_2_deadline_banner?(@application_form)
end

def apply_1_deadline
{
date: CycleTimetable.date(:apply_1_deadline).to_fs(:govuk_date),
time: CycleTimetable.date(:apply_1_deadline).to_fs(:govuk_time),
}
end

def apply_2_deadline
{
date: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_date),
time: CycleTimetable.date(:apply_2_deadline).to_fs(:govuk_time),
}
end

def application_form_recruitment_cycle_year
@application_form.recruitment_cycle_year
end
Expand Down
10 changes: 2 additions & 8 deletions app/services/cycle_timetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def self.current_date
now
end

def self.show_apply_1_deadline_banner?(application_form)
current_date.between?(date(:show_deadline_banner), date(:apply_1_deadline)) &&
application_form.phase == 'apply_1' &&
def self.show_apply_deadline_banner?(application_form)
current_date.between?(date(:show_deadline_banner), date(:apply_2_deadline)) &&
!application_form.successful?
end

Expand All @@ -157,11 +156,6 @@ def self.between_reject_by_default_and_find_reopens?
current_date.between?(CycleTimetable.reject_by_default, CycleTimetable.find_reopens)
end

def self.show_apply_2_deadline_banner?(application_form)
current_date.between?(date(:show_deadline_banner), date(:apply_2_deadline)) &&
(application_form.phase == 'apply_2' || (application_form.phase == 'apply_1' && application_form.ended_without_success?))
end

def self.show_non_working_days_banner?
show_christmas_non_working_days_banner? || show_easter_non_working_days_banner?
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
en:
heading: The deadline for applying to courses starting in %{academic_year} is %{deadline_time} on %{deadline_date}
text: Courses may fill up before then. Check course availability with the provider.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

it 'does not render when flash is not empty' do
allow(flash).to receive(:empty?).and_return(false)
allow(CycleTimetable).to receive_messages(show_apply_1_deadline_banner?: true, show_apply_2_deadline_banner?: true)
allow(CycleTimetable).to receive_messages(show_apply_deadline_banner?: true)

result = render_inline(described_class.new(application_form:, flash_empty: flash.empty?))

Expand All @@ -16,32 +16,21 @@

it 'does not render when a deadline banner should not be shown' do
allow(flash).to receive(:empty?).and_return(true)
allow(CycleTimetable).to receive_messages(show_apply_1_deadline_banner?: false, show_apply_2_deadline_banner?: false)
allow(CycleTimetable).to receive_messages(show_apply_deadline_banner?: false)

result = render_inline(described_class.new(application_form:, flash_empty: flash.empty?))

expect(result.text).to eq('')
end

it 'renders the Apply 1 banner when the right conditions are met' do
it 'renders the banner when the right conditions are met' do
allow(flash).to receive(:empty?).and_return(true)
allow(CycleTimetable).to receive_messages(show_apply_1_deadline_banner?: true, show_apply_2_deadline_banner?: false)
allow(CycleTimetable).to receive_messages(show_apply_deadline_banner?: true)

result = render_inline(described_class.new(application_form:, flash_empty: flash.empty?))

expect(result.text).to include(
"The deadline for applying to courses starting in the #{academic_year} academic year is #{deadline_time(:apply_1_deadline)} on #{deadline_date(:apply_1_deadline)}",
)
end

it 'renders the Apply 2 banner when the right conditions are met' do
allow(flash).to receive(:empty?).and_return(true)
allow(CycleTimetable).to receive_messages(show_apply_1_deadline_banner?: false, show_apply_2_deadline_banner?: true)

result = render_inline(described_class.new(application_form:, flash_empty: flash.empty?))

expect(result.text).to include(
"The deadline for applying to courses starting in the #{academic_year} academic year is #{deadline_time(:apply_2_deadline)} on #{deadline_date(:apply_2_deadline)}",
"The deadline for applying to courses starting in #{academic_year} is #{deadline_time(:apply_2_deadline)} on #{deadline_date(:apply_2_deadline)}",
)
end
end
Expand Down
48 changes: 11 additions & 37 deletions spec/services/cycle_timetable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@
end
end

describe '.show_apply_1_deadline_banner?' do
it 'returns true before the configured date and it is an unsuccessful apply_1 application' do
application_form = build(:application_form, phase: 'apply_1')
describe '.show_apply_deadline_banner?' do
it 'returns true before the deadline and the choices have not ben successful' do
application_choices = [build(:application_choice, :withdrawn)]
application_form = build(:application_form, application_choices:)

travel_temporarily_to(one_hour_before_apply1_deadline) do
expect(described_class.show_apply_1_deadline_banner?(application_form)).to be true
expect(described_class.show_apply_deadline_banner?(application_form)).to be true
end
end

it 'returns false if it is a apply_2 application' do
application_form = build(:application_form, phase: 'apply_2')
it 'returns true if there are no application choices' do
application_form = build(:application_form)

travel_temporarily_to(one_hour_before_apply1_deadline) do
expect(described_class.show_apply_1_deadline_banner?(application_form)).to be false
expect(described_class.show_apply_deadline_banner?(application_form)).to be true
end
end

Expand All @@ -77,15 +78,15 @@
application_form = build(:application_form, phase: 'apply_1', application_choices: [application_choice])

travel_temporarily_to(one_hour_before_apply1_deadline) do
expect(described_class.show_apply_1_deadline_banner?(application_form)).to be false
expect(described_class.show_apply_deadline_banner?(application_form)).to be false
end
end

it 'returns false after the configured date' do
application_form = build(:application_form, phase: 'apply_1')

travel_temporarily_to(one_hour_after_apply1_deadline) do
expect(described_class.show_apply_1_deadline_banner?(application_form)).to be false
travel_temporarily_to(one_hour_after_apply2_deadline) do
expect(described_class.show_apply_deadline_banner?(application_form)).to be false
end
end
end
Expand Down Expand Up @@ -117,33 +118,6 @@
end
end

describe '.show_apply_2_deadline_banner?' do
it 'returns true before the configured date and it is a phase 2 application' do
application_form = build(:application_form, phase: 'apply_2')

travel_temporarily_to(one_hour_before_apply2_deadline) do
expect(described_class.show_apply_2_deadline_banner?(application_form)).to be true
end
end

it 'returns false if it is a successful apply_1 application' do
application_choice = build(:application_choice, :offered)
application_form = build(:application_form, phase: 'apply_1', application_choices: [application_choice])

travel_temporarily_to(one_hour_before_apply2_deadline) do
expect(described_class.show_apply_2_deadline_banner?(application_form)).to be false
end
end

it 'returns false after the configured date' do
unsuccessful_application_form = build(:application_form, phase: 'apply_2', application_choices: [build(:application_choice, :rejected)])

travel_temporarily_to(one_hour_after_apply2_deadline) do
expect(described_class.show_apply_2_deadline_banner?(unsuccessful_application_form)).to be false
end
end
end

describe '.show_non_working_days_banner?' do
context 'when within the Christmas period' do
let(:one_hour_after_christmas_period) { described_class.holidays[:christmas].last.end_of_day + 1.hour }
Expand Down

0 comments on commit 878f9e6

Please sign in to comment.