From f6491f7838e77813f7a1dd657246a7eaca1c69fc Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Wed, 27 Nov 2024 10:55:46 +0000 Subject: [PATCH 1/8] [7851] Amended review's sign off period to be in the performance period --- config/settings/review.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/settings/review.yml b/config/settings/review.yml index f6ac122780..9ad4bf662a 100644 --- a/config/settings/review.yml +++ b/config/settings/review.yml @@ -27,3 +27,5 @@ pagination: environment: name: review + +sign_off_period: performance_period # census_period, performance_period, outside_period. See app/services/determine_sign_off_period.rb From b917a1dae31534cb7803289947f8af3fd1a4772e Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:06:37 +0000 Subject: [PATCH 2/8] [7851] Amended performance banner to be shown on with correct deadline date --- app/components/performance_profile_banner/view.rb | 4 ++-- app/models/academic_cycle.rb | 6 ++++++ spec/models/academic_cycle_spec.rb | 12 +++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/components/performance_profile_banner/view.rb b/app/components/performance_profile_banner/view.rb index 186df48822..6f291ddf90 100644 --- a/app/components/performance_profile_banner/view.rb +++ b/app/components/performance_profile_banner/view.rb @@ -18,10 +18,10 @@ def banner_heading_text "The #{previous_academic_cycle_label} ITT performance profile sign off due" end - delegate :label, :end_year, to: :previous_academic_cycle, prefix: true + delegate :label, :end_date_of_performance_profile, to: :previous_academic_cycle, prefix: true def deadline_date - "28 February #{previous_academic_cycle_end_year + 1}" + previous_academic_cycle.end_date_of_performance_profile.strftime("%-d %B %Y") end private diff --git a/app/models/academic_cycle.rb b/app/models/academic_cycle.rb index 884fa6a839..8ee4ef625e 100644 --- a/app/models/academic_cycle.rb +++ b/app/models/academic_cycle.rb @@ -78,6 +78,12 @@ def current? (start_date.beginning_of_day..end_date.end_of_day).cover?(Time.zone.now) end + def last_day_of_february + Date.new(end_year + 1, 2, -1) + end + + alias_method :end_date_of_performance_profile, :last_day_of_february + private def start_date_before_end_date diff --git a/spec/models/academic_cycle_spec.rb b/spec/models/academic_cycle_spec.rb index e16ab40f1b..02532e1b3d 100644 --- a/spec/models/academic_cycle_spec.rb +++ b/spec/models/academic_cycle_spec.rb @@ -3,7 +3,9 @@ require "rails_helper" describe AcademicCycle do - subject { build(:academic_cycle) } + let(:academic_cycle) { build(:academic_cycle) } + + subject { academic_cycle } before do allow(Trainees::SetAcademicCycles).to receive(:call) # deactivate so it doesn't override factories @@ -179,4 +181,12 @@ it { expect(subject).to eq(past_academic_year) } end end + + describe "#last_day_of_february" do + subject { academic_cycle.last_day_of_february } + + it { expect(subject.month).to eq 2 } + it { expect(subject.day).to be_between(28, 29) } + it { expect(subject).to be_a(Date) } + end end From cd7b89568c3acd4e6dd30b15c1080abbfe6a6f4e Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:30:29 +0000 Subject: [PATCH 3/8] [7851] Fixed linter issues --- app/views/layouts/application.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 213f2c0070..cf996b2d35 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,14 +7,14 @@ <%= canonical_tag %> <%= tag.meta(name: "viewport", content: "width=device-width, initial-scale=1") %> - <%= tag.meta(property: "og:image", content: image_path('govuk-opengraph-image.png')) %> + <%= tag.meta(property: "og:image", content: image_path("govuk-opengraph-image.png")) %> <%= tag.meta(name: "theme-color", content: "#0b0c0c") %> <%= tag.meta(name: "format-detection", content: "telephone=no") %> - <%= favicon_link_tag image_path('favicon.ico'), type: nil, sizes: "48x48" %> - <%= favicon_link_tag image_path('favicon.svg'), type: 'image/svg+xml', sizes: "any" %> - <%= favicon_link_tag image_path('govuk-icon-mask.svg'), rel: 'mask-icon', color: "#0b0c0c", type: nil %> - <%= favicon_link_tag image_path('govuk-icon-180.png'), rel: 'apple-touch-icon', type: nil %> + <%= favicon_link_tag image_path("favicon.ico"), type: nil, sizes: "48x48" %> + <%= favicon_link_tag image_path("favicon.svg"), type: "image/svg+xml", sizes: "any" %> + <%= favicon_link_tag image_path("govuk-icon-mask.svg"), rel: "mask-icon", color: "#0b0c0c", type: nil %> + <%= favicon_link_tag image_path("govuk-icon-180.png"), rel: "apple-touch-icon", type: nil %> <%= stylesheet_link_tag "accessible-autocomplete/dist/accessible-autocomplete.min" %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> @@ -68,7 +68,7 @@ { name: "Home", url: root_path }, ({ name: "Draft trainees", url: drafts_path, current: active_link_for("drafts", @trainee) } if can_view_drafts?), { name: "Registered trainees", url: trainees_path, current: active_link_for("trainees", @trainee) }, - ({ name: "Bulk updates", url: bulk_update_path, current: active_link_for("bulk") } if can_bulk_update? ), + ({ name: "Bulk updates", url: bulk_update_path, current: active_link_for("bulk") } if can_bulk_update?), ({ name: "Reports", url: reports_path, current: active_link_for("reports") } if can_view_reports?), ({ name: "Funding", url: funding_payment_schedule_path, current: active_link_for("funding") } if can_view_funding?), ({ name: current_user.organisation.name, url: organisations_path, align_right: true } if show_organisation_link?), From e44e6b97abef9895ef01e67087364289ab543ea0 Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:02:27 +0000 Subject: [PATCH 4/8] [7851] Amended AcademicCycle to have the performance profile date range --- app/models/academic_cycle.rb | 12 ++++++++++++ spec/models/academic_cycle_spec.rb | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/academic_cycle.rb b/app/models/academic_cycle.rb index 8ee4ef625e..f6a8bf5406 100644 --- a/app/models/academic_cycle.rb +++ b/app/models/academic_cycle.rb @@ -78,6 +78,14 @@ def current? (start_date.beginning_of_day..end_date.end_of_day).cover?(Time.zone.now) end + def in_performance_profile_range?(date) + performance_profile_date_range.cover?(date) + end + + def second_monday_of_january + Date.new(end_year + 1, 1, 1).next_week(:monday) + 7 + end + def last_day_of_february Date.new(end_year + 1, 2, -1) end @@ -86,6 +94,10 @@ def last_day_of_february private + def performance_profile_date_range + @performance_profile_date_range ||= second_monday_of_january..last_day_of_february + end + def start_date_before_end_date return unless dates_available? diff --git a/spec/models/academic_cycle_spec.rb b/spec/models/academic_cycle_spec.rb index 02532e1b3d..1246fd2221 100644 --- a/spec/models/academic_cycle_spec.rb +++ b/spec/models/academic_cycle_spec.rb @@ -182,6 +182,24 @@ end end + describe "#second_monday_of_january" do + it "returns whether a date is in the performance profile range" do + expect(academic_cycle.in_performance_profile_range?(academic_cycle.second_monday_of_january)).to be true + expect(academic_cycle.in_performance_profile_range?(academic_cycle.last_day_of_february)).to be true + expect(academic_cycle.in_performance_profile_range?(academic_cycle.second_monday_of_january - 1.day)).to be false + expect(academic_cycle.in_performance_profile_range?(academic_cycle.last_day_of_february + 1.day)).to be false + end + end + + describe "#second_monday_of_january" do + subject { academic_cycle.second_monday_of_january } + + it { expect(subject.month).to eq 1 } + it { expect(subject.wday).to eq 1 } + it { expect(subject.day).to be_between(8, 14) } + it { expect(subject).to be_a(Date) } + end + describe "#last_day_of_february" do subject { academic_cycle.last_day_of_february } From e7d5d4aa606c195ec99c0da680c32639389b4dec Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:20:45 +0000 Subject: [PATCH 5/8] [7851] Amended DetermineSignOffPeriod to use previous cycle --- app/services/determine_sign_off_period.rb | 25 +++++++++------ spec/models/academic_cycle_spec.rb | 2 +- .../determine_sign_off_period_spec.rb | 31 ++++++++++++------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/services/determine_sign_off_period.rb b/app/services/determine_sign_off_period.rb index 5dc4692f82..8fe8f18832 100644 --- a/app/services/determine_sign_off_period.rb +++ b/app/services/determine_sign_off_period.rb @@ -1,21 +1,31 @@ # 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) @@ -23,17 +33,12 @@ def self.valid_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 diff --git a/spec/models/academic_cycle_spec.rb b/spec/models/academic_cycle_spec.rb index 1246fd2221..f6a854921b 100644 --- a/spec/models/academic_cycle_spec.rb +++ b/spec/models/academic_cycle_spec.rb @@ -182,7 +182,7 @@ end end - describe "#second_monday_of_january" do + describe "#in_performance_profile_range?" do it "returns whether a date is in the performance profile range" do expect(academic_cycle.in_performance_profile_range?(academic_cycle.second_monday_of_january)).to be true expect(academic_cycle.in_performance_profile_range?(academic_cycle.last_day_of_february)).to be true diff --git a/spec/services/determine_sign_off_period_spec.rb b/spec/services/determine_sign_off_period_spec.rb index 7030a7d1b5..8133d663a2 100644 --- a/spec/services/determine_sign_off_period_spec.rb +++ b/spec/services/determine_sign_off_period_spec.rb @@ -4,7 +4,9 @@ describe DetermineSignOffPeriod do describe ".call" do - subject { described_class.call } + subject { described_class.call(previous_academic_cycle: academic_cycle) } + + let(:academic_cycle) { create(:academic_cycle) } before do allow(Settings).to receive(:sign_off_period).and_return(nil) @@ -18,13 +20,15 @@ all_dates = [*Date.new(current_year, 1, 1)..Date.new(current_year, 12, 31)] outside_dates = all_dates - census_period_range - performance_period_range - context "with a valid manual override" do - before do - allow(Settings).to receive(:sign_off_period).and_return(:census_period) - end + %i[census_period performance_period outside_period].each do |sign_off_period| + context "with a valid manual override" do + before do + allow(Settings).to receive(:sign_off_period).and_return(sign_off_period) + end - it "returns the manual override value" do - expect(subject).to eq(:census_period) + it "returns the manual override value #{sign_off_period}" do + expect(subject).to eq(sign_off_period) + end end end @@ -38,10 +42,15 @@ subject expect(Sentry).to have_received(:capture_exception).with(instance_of(StandardError)) end + end + + census_period_range.each do |census_date| + context "on #{census_date} the census sign off period" do + before do + allow(Time.zone).to receive(:today).and_return(census_date) + end - census_period_range.each do |census_period| - it "for #{census_period} it defaults back to the calculated behaviour" do - allow(Time.zone).to receive(:today).and_return(census_period) + it "returns :census_period" do expect(subject).to eq(:census_period) end end @@ -51,6 +60,7 @@ context "on #{performance_date} the performance profiles sign off period" do before do allow(Time.zone).to receive(:today).and_return(performance_date) + allow(academic_cycle).to receive(:in_performance_profile_range?).with(performance_date).and_return(true) end it "returns :performance_period" do @@ -66,7 +76,6 @@ end it "returns :outside_period" do - pp subject if subject != :outside_period expect(subject).to eq(:outside_period) end end From 1d931e6b3e5c9ff2fe68ef4223a7a9d6894b7cb4 Mon Sep 17 00:00:00 2001 From: defong <470137+defong@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:13:55 +0000 Subject: [PATCH 6/8] [7851] Amended performance banner to be shown on the landing page --- app/models/academic_cycle.rb | 6 +- app/views/layouts/application.html.erb | 7 +- .../performance_profile_banner_spec.rb | 73 +++++++++++++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 spec/features/performance_profile_banner_spec.rb diff --git a/app/models/academic_cycle.rb b/app/models/academic_cycle.rb index f6a8bf5406..c6d1901d78 100644 --- a/app/models/academic_cycle.rb +++ b/app/models/academic_cycle.rb @@ -92,12 +92,12 @@ def last_day_of_february alias_method :end_date_of_performance_profile, :last_day_of_february -private - def performance_profile_date_range - @performance_profile_date_range ||= second_monday_of_january..last_day_of_february + @performance_profile_date_range ||= second_monday_of_january..end_date_of_performance_profile end +private + def start_date_before_end_date return unless dates_available? diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cf996b2d35..a676fa05ea 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -107,12 +107,13 @@