-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4844 from DFE-Digital/7851-performance-banner-2
[7851] Show the performance banner
- Loading branch information
Showing
9 changed files
with
171 additions
and
35 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,39 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class DetermineSignOffPeriod | ||
include ServicePattern | ||
|
||
VALID_PERIODS = %i[census_period performance_period outside_period].freeze | ||
|
||
def self.call | ||
def initialize(previous_academic_cycle: AcademicCycle.previous) | ||
@previous_academic_cycle = previous_academic_cycle | ||
end | ||
|
||
def call | ||
return Settings.sign_off_period.to_sym if valid_sign_off_period? | ||
|
||
current_date = Time.zone.today | ||
|
||
return :census_period if census_range.cover?(current_date) | ||
|
||
return :performance_period if in_performance_range?(current_date) | ||
return :performance_period if in_performance_profile_range?(current_date) | ||
|
||
:outside_period | ||
end | ||
|
||
def self.valid_sign_off_period? | ||
private | ||
|
||
attr_reader :previous_academic_cycle | ||
|
||
def valid_sign_off_period? | ||
return false if Settings.sign_off_period.blank? | ||
return true if VALID_PERIODS.include?(Settings.sign_off_period.to_sym) | ||
|
||
Sentry.capture_exception(StandardError.new("Invalid sign_off_period value: #{Settings.sign_off_period}")) | ||
false | ||
end | ||
|
||
def self.census_range | ||
def census_range | ||
start_date = Date.new(Time.zone.today.year, 9, 1) # 1st September | ||
end_date = Date.new(Time.zone.today.year, 11, 7) # 7th November | ||
|
||
start_date..end_date | ||
end | ||
|
||
def self.in_performance_range?(date) | ||
jan_to_feb_range = Date.new(Time.zone.today.year, 1, 1)..Date.new(Time.zone.today.year, 2, 7) | ||
december_range = Date.new(Time.zone.today.year, 12, 1)..Date.new(Time.zone.today.year, 12, 31) | ||
|
||
jan_to_feb_range.cover?(date) || december_range.cover?(date) | ||
end | ||
delegate :in_performance_profile_range?, to: :previous_academic_cycle | ||
end |
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
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
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
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,73 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
feature "performance profile banner" do | ||
context "within the performance profile date range" do | ||
background do | ||
Timecop.freeze(AcademicCycle.previous.performance_profile_date_range.to_a.sample) | ||
end | ||
|
||
context "not logged in" do | ||
scenario "performance profile banner is not shown" do | ||
given_i_am_not_logged_in | ||
when_i_am_on_the_root_page | ||
then_i_do_not_see_the_performance_profile_banner | ||
end | ||
end | ||
|
||
context "logged in as system admin" do | ||
scenario "performance profile banner is not shown" do | ||
given_i_am_authenticated_as_system_admin | ||
when_i_am_on_the_root_page | ||
then_i_do_not_see_the_performance_profile_banner | ||
end | ||
end | ||
|
||
context "accredited provider user" do | ||
scenario "performance profile banner is shown" do | ||
given_i_am_authenticated | ||
when_i_am_on_the_root_page | ||
then_i_can_see_the_performance_profile_banner | ||
and_i_click_on("Sign off your performance profile") | ||
and_i_am_on_the_sign_off_your_performance_profile_page | ||
end | ||
end | ||
|
||
context "lead provider user" do | ||
scenario "performance profile banner is not shown" do | ||
given_i_am_authenticated_as_a_lead_partner_user | ||
when_i_am_on_the_root_page | ||
then_i_do_not_see_the_performance_profile_banner | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def when_i_am_on_the_root_page | ||
visit "/" | ||
end | ||
|
||
def given_i_am_not_logged_in; end | ||
|
||
def then_i_do_not_see_the_performance_profile_banner | ||
expect(page).not_to have_css("#govuk-notification-banner-title", text: "Important") | ||
expect(page).not_to have_css(".govuk-notification-banner__heading", text: "The #{previous_academic_cycle_label} ITT performance profile sign off is due") | ||
end | ||
|
||
def then_i_can_see_the_performance_profile_banner | ||
expect(page).to have_css("#govuk-notification-banner-title", text: "Important") | ||
expect(page).to have_css(".govuk-notification-banner__heading", text: "The #{previous_academic_cycle_label} ITT performance profile sign off is due") | ||
end | ||
|
||
def previous_academic_cycle_label | ||
AcademicCycle.previous.label | ||
end | ||
|
||
def and_i_am_on_the_sign_off_your_performance_profile_page | ||
expect(page).to have_current_path("/") | ||
end | ||
|
||
alias_method :and_i_click_on, :click_on | ||
end |
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
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