From 740f4cbdd429ee2a955510bbcdd4a256c319e200 Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Fri, 27 Jan 2023 08:09:08 +0000
Subject: [PATCH] CLDC-1843 Hide download csv link for sales logs (#1230)
* Hide download csv link for sales logs
* refactor
---
app/views/logs/_log_list.html.erb | 4 +++-
spec/requests/lettings_logs_controller_spec.rb | 1 +
spec/requests/organisations_controller_spec.rb | 5 +++--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/app/views/logs/_log_list.html.erb b/app/views/logs/_log_list.html.erb
index 702cd7d1f..1aeaa03f2 100644
--- a/app/views/logs/_log_list.html.erb
+++ b/app/views/logs/_log_list.html.erb
@@ -1,6 +1,8 @@
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", path: request.path)) %>
- <%= govuk_link_to "Download (CSV)", csv_download_url, type: "text/csv" %>
+ <% if logs&.first&.lettings? %>
+ <%= govuk_link_to "Download (CSV)", csv_download_url, type: "text/csv" %>
+ <% end %>
<% logs.map do |log| %>
<%= render(LogSummaryComponent.new(current_user:, log:)) %>
diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb
index dc009a16d..9565f08ec 100644
--- a/spec/requests/lettings_logs_controller_spec.rb
+++ b/spec/requests/lettings_logs_controller_spec.rb
@@ -458,6 +458,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "includes the search on the CSV link" do
search_term = "foo"
+ FactoryBot.create(:lettings_log, created_by: user, owning_organisation: user.organisation, tenancycode: "foo")
get "/lettings-logs?search=#{search_term}", headers: headers, params: {}
expect(page).to have_link("Download (CSV)", href: "/lettings-logs/csv-download?search=#{search_term}")
end
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb
index f63dcf54e..004ea538a 100644
--- a/spec/requests/organisations_controller_spec.rb
+++ b/spec/requests/organisations_controller_spec.rb
@@ -1141,10 +1141,11 @@ RSpec.describe OrganisationsController, type: :request do
context "when they view the logs tab" do
before do
+ FactoryBot.create(:lettings_log, owning_organisation: organisation)
get "/organisations/#{organisation.id}/lettings-logs"
end
- it "has a CSV download button with the correct path" do
+ it "has a CSV download button with the correct path if at least 1 log exists" do
expect(page).to have_link("Download (CSV)", href: "/organisations/#{organisation.id}/logs/csv-download")
end
@@ -1152,7 +1153,7 @@ RSpec.describe OrganisationsController, type: :request do
let(:other_organisation) { FactoryBot.create(:organisation) }
before do
- FactoryBot.create_list(:lettings_log, 3, owning_organisation: organisation)
+ FactoryBot.create_list(:lettings_log, 2, owning_organisation: organisation)
FactoryBot.create_list(:lettings_log, 2, owning_organisation: other_organisation)
end