From 084e9c81fcebd034f3792999234f9f2c262338ed Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 8 Oct 2024 09:06:20 +0100 Subject: [PATCH] Update upload new mandatory resource page --- .../_collection_resource_summary_list.erb | 2 +- app/views/collection_resources/edit.html.erb | 5 +- .../collection_resources_controller_spec.rb | 52 +++++++++++++++---- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/app/views/collection_resources/_collection_resource_summary_list.erb b/app/views/collection_resources/_collection_resource_summary_list.erb index 61c29865d..8ef588fd5 100644 --- a/app/views/collection_resources/_collection_resource_summary_list.erb +++ b/app/views/collection_resources/_collection_resource_summary_list.erb @@ -18,7 +18,7 @@ <% end %> <% row.with_action( text: "Upload", - href: "/", + href: edit_mandatory_collection_resource_path(year: resource.year, log_type: resource.log_type, resource_type: resource.resource_type), ) %> <% end %> <% end %> diff --git a/app/views/collection_resources/edit.html.erb b/app/views/collection_resources/edit.html.erb index d9bfe5be9..e5b2a6d33 100644 --- a/app/views/collection_resources/edit.html.erb +++ b/app/views/collection_resources/edit.html.erb @@ -4,6 +4,7 @@
+ <% resource_exists = file_exists_on_s3?(@collection_resource.download_filename) %> <%= form_with model: @collection_resource, url: update_mandatory_collection_resource_path, method: :patch do |f| %> <%= f.hidden_field :year %> <%= f.hidden_field :log_type %> @@ -12,7 +13,7 @@ <%= f.govuk_error_summary %> <%= "#{@collection_resource.log_type.humanize} #{text_year_range_format(@collection_resource.year)}" %> -

Change the <%= @collection_resource.resource_type.humanize.downcase %>

+

<%= resource_exists ? "Change" : "Upload" %> the <%= @collection_resource.resource_type.humanize.downcase %>

This file will be available for all users to download. @@ -21,7 +22,7 @@ <%= f.govuk_file_field :file, label: { text: "Upload file", size: "m" } %> - <%= f.govuk_submit "Save changes" %> + <%= f.govuk_submit resource_exists ? "Save changes" : "Upload" %> <%= govuk_button_link_to "Cancel", collection_resources_path, secondary: true %> <% end %>

diff --git a/spec/requests/collection_resources_controller_spec.rb b/spec/requests/collection_resources_controller_spec.rb index 597f70a83..48a94ee7f 100644 --- a/spec/requests/collection_resources_controller_spec.rb +++ b/spec/requests/collection_resources_controller_spec.rb @@ -122,6 +122,19 @@ RSpec.describe CollectionResourcesController, type: :request do it "displays upload links" do expect(page).to have_selector(:link_or_button, "Upload", count: 12) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification")) + + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form")) + 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")) end end end @@ -243,16 +256,37 @@ RSpec.describe CollectionResourcesController, type: :request do sign_in user end - it "displays update collection resources page content" do - get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") + context "and the file exists on S3" do + it "displays update collection resources page content" do + get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") + + expect(page).to have_content("Sales 2024 to 2025") + expect(page).to have_content("Change the bulk upload template") + expect(page).to have_content("This file will be available for all users to download.") + expect(page).to have_content("Upload file") + expect(page).to have_button("Save changes") + expect(page).to have_link("Back", href: collection_resources_path) + expect(page).to have_link("Cancel", href: collection_resources_path) + end + end - expect(page).to have_content("Sales 2024 to 2025") - expect(page).to have_content("Change the bulk upload template") - expect(page).to have_content("This file will be available for all users to download.") - expect(page).to have_content("Upload file") - expect(page).to have_button("Save changes") - expect(page).to have_link("Back", href: collection_resources_path) - expect(page).to have_link("Cancel", href: collection_resources_path) + context "and the file does not exist on S3" do + before do + WebMock.stub_request(:head, /https:\/\/core-test-collection-resources\.s3\.amazonaws\.com/) + .to_return(status: 404, body: "", headers: {}) + end + + it "displays upload collection resources page content" do + get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") + + expect(page).to have_content("Sales 2024 to 2025") + expect(page).to have_content("Upload the bulk upload template") + expect(page).to have_content("This file will be available for all users to download.") + expect(page).to have_content("Upload file") + expect(page).to have_button("Upload") + expect(page).to have_link("Back", href: collection_resources_path) + expect(page).to have_link("Cancel", href: collection_resources_path) + end end end end