Skip to content

Commit

Permalink
CLDC-3829 Add guidance link and deadlines to log pages (#2940)
Browse files Browse the repository at this point in the history
* Add guidance link

* Add deadline text

* Add quarter to non overdue deadline

* Move styling

* Add test and fix cases when no quarters are returned

* Remove days of the week from copy

* Change some copy
  • Loading branch information
kosiakkatrina authored Feb 27, 2025
1 parent f268357 commit 7630b49
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/frontend/styles/_task-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@
margin-bottom: 0;
}
}

.app-red-text {
color: govuk-colour("red");
}
5 changes: 4 additions & 1 deletion app/helpers/collection_deadline_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ def quarter_dates(year)
first_quarter(year).merge(quarter: "Q1"),
second_quarter(year).merge(quarter: "Q2"),
third_quarter(year).merge(quarter: "Q3"),
fourth_quarter(year).merge(quarter: "Q4"),
]
end

def quarter_for_date(date: Time.zone.now)
quarters = quarter_dates(current_collection_start_year)
collection_start_year = collection_start_year_for_date(date)
return unless QUARTERLY_DEADLINES.key?(collection_start_year)

quarters = quarter_dates(collection_start_year)
quarter = quarters.find { |q| date.between?(q[:start_date], q[:cutoff_date] + 1.day) }

return unless quarter
Expand Down
17 changes: 17 additions & 0 deletions app/helpers/tasklist_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module TasklistHelper
include GovukLinkHelper
include GovukVisuallyHiddenHelper
include CollectionTimeHelper
include CollectionDeadlineHelper

def breadcrumb_logs_title(log, current_user)
log_type = log.lettings? ? "Lettings" : "Sales"
Expand Down Expand Up @@ -70,6 +71,22 @@ def tasklist_link_class(status)
status == :cannot_start_yet ? "" : "govuk-task-list__item--with-link"
end

def deadline_text(log)
return if log.completed?
return if log.startdate.nil?

log_quarter = quarter_for_date(date: log.startdate)
return if log_quarter.nil?

deadline_for_log = log_quarter.cutoff_date

if deadline_for_log.beginning_of_day >= Time.zone.today.beginning_of_day
"<p class=\"govuk-body\">Upcoming #{log_quarter.quarter} deadline: #{log_quarter.cutoff_date.strftime('%-d %B %Y')}.<p>".html_safe
else
"<p class=\"govuk-body app-red-text\"><strong>Overdue: #{log_quarter.quarter} deadline #{log_quarter.cutoff_date.strftime('%-d %B %Y')}.</strong></p>".html_safe
end
end

private

def breadcrumb_organisation(log)
Expand Down
2 changes: 2 additions & 0 deletions app/views/logs/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<% end %>
</p>
<% elsif @log.status == "not_started" %>
<p class="govuk-body"><%= govuk_link_to "Guidance for submitting social housing lettings and sales data (opens in a new tab)", guidance_path, target: "#" %></p>
<p class="govuk-body">This log has not been started.</p>
<% elsif @log.status == "completed" %>
<p class="govuk-body">
Expand All @@ -36,6 +37,7 @@
</p>
<% end %>

<%= deadline_text(@log) %>
<%= render "tasklist" %>

<%= edit_actions_for_log(@log, bulk_upload_filter_applied) %>
Expand Down
45 changes: 45 additions & 0 deletions spec/helpers/tasklist_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,49 @@
end
end
end

describe "deadline text" do
context "when log does not have a sale/start date" do
let(:log) { build(:sales_log, saledate: nil) }

it "returns nil" do
expect(deadline_text(log)).to be_nil
end
end

context "when log is completed" do
let(:log) { build(:sales_log, :completed, status: "completed") }

it "returns nil" do
expect(deadline_text(log)).to be_nil
end
end

context "when today is before the deadline for log with sale/start date" do
let(:log) { build(:sales_log, saledate: Time.zone.local(2025, 6, 1)) }

it "returns the deadline text" do
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 5, 7))
expect(deadline_text(log)).to include("Upcoming Q1 deadline: 11 July 2025.")
end
end

context "when today is the deadline for log with sale/start date" do
let(:log) { build(:sales_log, saledate: Time.zone.local(2025, 2, 1)) }

it "returns the overdue text" do
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 6, 6))
expect(deadline_text(log)).to include("Upcoming Q4 deadline: 6 June 2025.")
end
end

context "when today is after the deadline for log with sale/start date" do
let(:log) { build(:sales_log, saledate: Time.zone.local(2025, 2, 1)) }

it "returns the overdue text" do
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 6, 7))
expect(deadline_text(log)).to include("Overdue: Q4 deadline 6 June 2025.")
end
end
end
end
15 changes: 15 additions & 0 deletions spec/requests/lettings_logs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,21 @@
expect(lettings_log.status).to eq("completed")
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{lettings_log.id}/review")
end

it "does not show guidance link" do
expect(page).not_to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)")
end
end

context "and the log is not started" do
let(:lettings_log) { create(:lettings_log, status: "not_started", assigned_to: user) }

it "shows guidance link" do
allow(Time.zone).to receive(:now).and_return(lettings_log.form.edit_end_date - 1.day)
get lettings_log_path(lettings_log)
expect(lettings_log.status).to eq("not_started")
expect(page).to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)")
end
end

context "with bulk_upload_id filter" do
Expand Down
11 changes: 11 additions & 0 deletions spec/requests/sales_logs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@
context "when viewing a sales log" do
let(:headers) { { "Accept" => "text/html" } }
let(:completed_sales_log) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, assigned_to: user) }
let(:not_started_sales_log) { FactoryBot.create(:sales_log, owning_organisation: user.organisation, assigned_to: user) }

before do
sign_in user
Expand Down Expand Up @@ -956,6 +957,16 @@
expect(page).to have_content("This log is from the 2021 to 2022 collection window, which is now closed.")
end
end

it "does not show guidance link" do
get "/sales-logs/#{completed_sales_log.id}", headers:, params: {}
expect(page).not_to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)")
end

it "shows guidance link for not_started log" do
get "/sales-logs/#{not_started_sales_log.id}", headers:, params: {}
expect(page).to have_content("Guidance for submitting social housing lettings and sales data (opens in a new tab)")
end
end

context "when requesting CSV download" do
Expand Down

0 comments on commit 7630b49

Please sign in to comment.