Browse Source

check for duplicates and display notification banner on the index page where appropriate

tests to cover the desired behaviour
pull/1776/head
Arthur Campbell 3 years ago committed by Kat
parent
commit
c31a5e7063
  1. 28
      app/controllers/lettings_logs_controller.rb
  2. 6
      app/views/logs/index.html.erb
  3. 3
      config/locales/en.yml
  4. 47
      spec/requests/lettings_logs_controller_spec.rb

28
app/controllers/lettings_logs_controller.rb

@ -1,4 +1,6 @@
class LettingsLogsController < LogsController
include DuplicateLogsHelper
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
before_action :find_resource, only: %i[update show]
@ -11,20 +13,20 @@ class LettingsLogsController < LogsController
before_action :redirect_if_bulk_upload_resolved, only: [:index]
def index
respond_to do |format|
format.html do
all_logs = current_user.lettings_logs.visible
unpaginated_filtered_logs = filter_manager.filtered_logs(all_logs, search_term, session_filters)
@delete_logs_path = delete_logs_lettings_logs_path(search: search_term)
@pagy, @logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
@unresolved_count = all_logs.unresolved.created_by(current_user).count
@filter_type = "lettings_logs"
render "logs/index"
end
if current_user.data_provider? && (@duplicates = duplicates_for_user(current_user))
@duplicate_sets_count = @duplicates[:lettings].count + @duplicates[:sales].count
end
all_logs = current_user.lettings_logs.visible
unpaginated_filtered_logs = filter_manager.filtered_logs(all_logs, search_term, session_filters)
@delete_logs_path = delete_logs_lettings_logs_path(search: search_term)
@pagy, @logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
@unresolved_count = all_logs.unresolved.created_by(current_user).count
@filter_type = "lettings_logs"
render "logs/index"
end
def create

6
app/views/logs/index.html.erb

@ -8,6 +8,12 @@
organisation: @organisation,
) %>
<% if @duplicates %>
<%= govuk_notification_banner(title_text: "Important", text: govuk_link_to("Review logs", href: "#")) do |banner|
banner.with_heading(text: I18n.t("notification.duplicate_sets", count: @duplicate_sets_count))
end %>
<% end %>
<% if current_page?(controller: 'lettings_logs', action: 'index') %>
<% if @unresolved_count > 0 %>
<%= govuk_notification_banner(

3
config/locales/en.yml

@ -189,6 +189,9 @@ en:
other: "%{log_ids} have been deleted."
duplicate_logs:
deduplication_success_banner: "%{log_link} is no longer a duplicate and has been removed from the list.<p class=\"govuk-body govuk-!-margin-top-4\">You changed the %{changed_question_label}.</p>"
duplicate_sets:
one: "There is %{count} set of duplicate logs"
other: "There are %{count} sets of duplicate logs"
validations:
organisation:

47
spec/requests/lettings_logs_controller_spec.rb

@ -238,8 +238,6 @@ RSpec.describe LettingsLogsController, type: :request do
let(:headers) { { "Accept" => "text/html" } }
context "when you visit the index page" do
let(:user) { FactoryBot.create(:user, :support) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
@ -308,6 +306,13 @@ RSpec.describe LettingsLogsController, type: :request do
expect(page).to have_link("Download (CSV, codes only)", href: "/lettings-logs/csv-download?codes_only=true")
end
it "does not show a notification banner even if there are duplicate logs for this user" do
allow_any_instance_of(DuplicateLogsHelper).to receive(:duplicates_for_user).and_return({ lettings: [[1, 2]], sales: [] }) # rubocop:disable RSpec/AnyInstance
get lettings_logs_path
expect(page).not_to have_content "duplicate logs"
expect(page).not_to have_link "Review logs"
end
context "when there are no logs in the database" do
before do
LettingsLog.destroy_all
@ -615,6 +620,12 @@ RSpec.describe LettingsLogsController, type: :request do
expect(page).not_to have_link("Download (CSV, codes only)")
end
it "does not show a notification banner even if there are duplicate logs for this user" do
get lettings_logs_path
expect(page).not_to have_content "duplicate logs"
expect(page).not_to have_link "Review logs"
end
context "when using a search query" do
let(:logs) { FactoryBot.create_list(:lettings_log, 3, :completed, owning_organisation: user.organisation, created_by: user) }
let(:log_to_search) { FactoryBot.create(:lettings_log, :completed, owning_organisation: user.organisation, created_by: user) }
@ -871,6 +882,38 @@ RSpec.describe LettingsLogsController, type: :request do
end
end
end
context "and there are duplicate logs for this user" do
let(:duplicates) { { lettings:, sales: } }
let(:lettings) { [[1, 2]] }
let(:sales) { [] }
before do
allow_any_instance_of(DuplicateLogsHelper).to receive(:duplicates_for_user).and_return duplicates # rubocop:disable RSpec/AnyInstance
end
it "displays a notification banner with a link to review logs" do
get lettings_logs_path
expect(page).to have_content "duplicate logs"
expect(page).to have_link "Review logs" # add an href when routing done
end
context "when there is one set of duplicates" do
it "displays the correct copy in the banner" do
get lettings_logs_path
expect(page).to have_content "There is 1 set of duplicate logs"
end
end
context "when there are multiple sets of duplicates" do
let(:sales) { [[3, 4]] }
it "displays the correct copy in the banner" do
get lettings_logs_path
expect(page).to have_content "There are 2 sets of duplicate logs"
end
end
end
end
end

Loading…
Cancel
Save