Browse Source

CLDC-3829 Add guidance link and deadlines to log pages (#2940)

* 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
update-status-at
kosiakkatrina 4 days ago committed by GitHub
parent
commit
7630b49184
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/frontend/styles/_task-list.scss
  2. 5
      app/helpers/collection_deadline_helper.rb
  3. 17
      app/helpers/tasklist_helper.rb
  4. 2
      app/views/logs/edit.html.erb
  5. 45
      spec/helpers/tasklist_helper_spec.rb
  6. 15
      spec/requests/lettings_logs_controller_spec.rb
  7. 11
      spec/requests/sales_logs_controller_spec.rb

4
app/frontend/styles/_task-list.scss

@ -52,3 +52,7 @@
margin-bottom: 0;
}
}
.app-red-text {
color: govuk-colour("red");
}

5
app/helpers/collection_deadline_helper.rb

@ -61,12 +61,15 @@ module CollectionDeadlineHelper
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

17
app/helpers/tasklist_helper.rb

@ -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"
@ -70,6 +71,22 @@ module TasklistHelper
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)

2
app/views/logs/edit.html.erb

@ -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">
@ -36,6 +37,7 @@
</p>
<% end %>
<%= deadline_text(@log) %>
<%= render "tasklist" %>
<%= edit_actions_for_log(@log, bulk_upload_filter_applied) %>

45
spec/helpers/tasklist_helper_spec.rb

@ -204,4 +204,49 @@ RSpec.describe TasklistHelper do
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
spec/requests/lettings_logs_controller_spec.rb

@ -1155,6 +1155,21 @@ RSpec.describe LettingsLogsController, type: :request do
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

11
spec/requests/sales_logs_controller_spec.rb

@ -866,6 +866,7 @@ RSpec.describe SalesLogsController, type: :request do
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
@ -956,6 +957,16 @@ RSpec.describe SalesLogsController, type: :request do
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

Loading…
Cancel
Save