Browse Source

Add next year resources banner

pull/2683/head
Kat 2 years ago
parent
commit
6ce6faedba
  1. 14
      app/helpers/collection_resources_helper.rb
  2. 8
      app/views/collection_resources/index.html.erb
  3. 1
      config/routes.rb
  4. 50
      spec/helpers/collection_resources_helper_spec.rb
  5. 10
      spec/requests/collection_resources_controller_spec.rb

14
app/helpers/collection_resources_helper.rb

@ -1,5 +1,7 @@
module CollectionResourcesHelper module CollectionResourcesHelper
include CollectionTimeHelper include CollectionTimeHelper
include GovukLinkHelper
include GovukVisuallyHiddenHelper
HUMAN_READABLE_CONTENT_TYPE = { "application/pdf": "PDF", HUMAN_READABLE_CONTENT_TYPE = { "application/pdf": "PDF",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "Microsoft Excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "Microsoft Excel",
@ -66,4 +68,16 @@ module CollectionResourcesHelper
def file_exists_on_s3?(file) def file_exists_on_s3?(file)
CollectionResourcesService.new.file_exists_on_s3?(file) CollectionResourcesService.new.file_exists_on_s3?(file)
end end
def display_next_year_banner?
editable_collection_resource_years.include?(next_collection_start_year)
end
def next_year_banner_text(lettings_resources, sales_resources)
if lettings_resources[next_collection_start_year].map(&:download_filename).all? { |file| file_exists_on_s3?(file) } && sales_resources[next_collection_start_year].map(&:download_filename).all? { |file| file_exists_on_s3?(file) }
govuk_link_to "Release the #{text_year_range_format(next_collection_start_year)} collection resources to users", release_mandatory_collection_resources_path(year: next_collection_start_year), class: "govuk-link"
else
"Once you have uploaded all the required #{text_year_range_format(next_collection_start_year)} collection resources, you will be able to release them to users."
end
end
end end

8
app/views/collection_resources/index.html.erb

@ -4,6 +4,14 @@
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<% if display_next_year_banner? %>
<%= govuk_notification_banner(title_text: "Important") do %>
<p class="govuk-notification-banner__heading govuk-!-width-full" style="max-width: fit-content">
The <%= text_year_range_format(next_collection_start_year) %> collection resources are not yet available to users.
<p>
<%= next_year_banner_text(@mandatory_lettings_collection_resources_per_year, @mandatory_sales_collection_resources_per_year) %>
<% end %>
<% end %>
<h1 class="govuk-heading-l"><%= title %></h1> <h1 class="govuk-heading-l"><%= title %></h1>
<% @mandatory_lettings_collection_resources_per_year.each do |year, mandatory_resources| %> <% @mandatory_lettings_collection_resources_per_year.each do |year, mandatory_resources| %>

1
config/routes.rb

@ -44,6 +44,7 @@ Rails.application.routes.draw do
get "/collection-resources/:log_type/:year/:resource_type/download", to: "collection_resources#download_mandatory_collection_resource", as: :download_mandatory_collection_resource get "/collection-resources/:log_type/:year/:resource_type/download", to: "collection_resources#download_mandatory_collection_resource", as: :download_mandatory_collection_resource
get "/collection-resources/:log_type/:year/:resource_type/edit", to: "collection_resources#edit", as: :edit_mandatory_collection_resource get "/collection-resources/:log_type/:year/:resource_type/edit", to: "collection_resources#edit", as: :edit_mandatory_collection_resource
patch "/collection-resources", to: "collection_resources#update", as: :update_mandatory_collection_resource patch "/collection-resources", to: "collection_resources#update", as: :update_mandatory_collection_resource
get "/collection-resources/:year/release", to: "collection_resources#release_mandatory_resources", as: :release_mandatory_collection_resources
resources :collection_resources, path: "/collection-resources" do resources :collection_resources, path: "/collection-resources" do
get "/download", to: "collection_resources#download_additional_collection_resource" # when we get to adding them get "/download", to: "collection_resources#download_additional_collection_resource" # when we get to adding them

50
spec/helpers/collection_resources_helper_spec.rb

@ -163,4 +163,54 @@ RSpec.describe CollectionResourcesHelper do
]) ])
end end
end end
describe "#display_next_year_banner?" do
context "when next year is not editable" do
before do
allow(FormHandler.instance).to receive(:in_edit_crossover_period?).and_return(true)
end
it "returns false" do
expect(display_next_year_banner?).to be_falsey
end
end
context "when next year is editable" do
before do
allow(FormHandler.instance).to receive(:in_edit_crossover_period?).and_return(false)
allow(Time.zone).to receive(:today).and_return(Time.zone.local(2025, 1, 1))
end
it "returns true" do
expect(display_next_year_banner?).to be_truthy
end
end
end
describe "#next_year_banner_text" do
let(:lettings_resources) { MandatoryCollectionResourcesService.generate_resources("lettings", [next_collection_start_year]) }
let(:sales_resources) { MandatoryCollectionResourcesService.generate_resources("sales", [next_collection_start_year]) }
context "when all the mandatory resources for next year are uploaded" do
before do
WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/)
.to_return(status: 200, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" })
end
it "returns correct text" do
expect(next_year_banner_text(lettings_resources, sales_resources)).to match(/Release the 2025 to 2026 collection resources to users/)
end
end
context "when some of the mandatory resources for next year are not uploaded" do
before do
WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/)
.to_return(status: 404, body: "", headers: { "Content-Length" => 292_864, "Content-Type" => "application/pdf" })
end
it "returns correct text" do
expect(next_year_banner_text(lettings_resources, sales_resources)).to eq("Once you have uploaded all the required 2025 to 2026 collection resources, you will be able to release them to users.")
end
end
end
end end

10
spec/requests/collection_resources_controller_spec.rb

@ -108,6 +108,11 @@ RSpec.describe CollectionResourcesController, type: :request do
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template")) expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification")) expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification"))
end end
it "displays next year banner" do
expect(page).to have_content("The 2025 to 2026 collection resources are not yet available to users.")
expect(page).to have_link("Release the 2025 to 2026 collection resources to users", href: release_mandatory_collection_resources_path(year: 2025))
end
end end
context "when files are not on S3" do context "when files are not on S3" do
@ -136,6 +141,11 @@ RSpec.describe CollectionResourcesController, type: :request do
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template")) expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template"))
expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification")) expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification"))
end end
it "displays next year banner" do
expect(page).to have_content("The 2025 to 2026 collection resources are not yet available to users.")
expect(page).to have_content("Once you have uploaded all the required 2025 to 2026 collection resources, you will be able to release them to users.")
end
end end
end end
end end

Loading…
Cancel
Save