From b91a47cee51680e5479bac8fbd0a4ea1a210f9dc Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 20 Jul 2023 09:21:28 +0100 Subject: [PATCH] Add banner --- app/controllers/form_controller.rb | 30 ++++++++++++++++++------------ spec/features/lettings_log_spec.rb | 4 ++++ spec/features/sales_log_spec.rb | 4 ++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index f77ae23a9..dd30a6b86 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -161,18 +161,6 @@ private params[@log.model_name.param_key]["interruption_page_referrer_type"].presence end - def correcting_duplicate_logs_redirect_path - class_name = @log.class.name.underscore - - original_log = current_user.send(class_name.pluralize).find_by(id: from_referrer_query("original_log_id")) - - if current_user.send(class_name.pluralize).duplicate_logs(original_log).count.positive? - send("#{class_name}_duplicate_logs_path", original_log, original_log_id: original_log.id) - else - send("#{class_name}_duplicate_logs_path", "#{class_name}_id".to_sym => from_referrer_query("remaining_duplicate_id"), original_log_id: from_referrer_query("original_log_id")) - end - end - def successful_redirect_path if FeatureToggle.deduplication_flow_enabled? if is_referrer_type?("duplicate_logs") @@ -253,4 +241,22 @@ private end CONFIRMATION_PAGE_IDS = %w[uprn_confirmation].freeze + + def correcting_duplicate_logs_redirect_path + class_name = @log.class.name.underscore + + original_log = current_user.send(class_name.pluralize).find_by(id: from_referrer_query("original_log_id")) + + if current_user.send(class_name.pluralize).duplicate_logs(original_log).count.positive? + flash[:notice] = deduplication_success_banner unless current_user.send(class_name.pluralize).duplicate_logs(@log).count.positive? + send("#{class_name}_duplicate_logs_path", original_log, original_log_id: original_log.id) + else + flash[:notice] = deduplication_success_banner + send("#{class_name}_duplicate_logs_path", "#{class_name}_id".to_sym => from_referrer_query("remaining_duplicate_id"), original_log_id: from_referrer_query("original_log_id")) + end + end + + def deduplication_success_banner + "Log #{@log.id} is no longer a duplicate and has been removed from the list".html_safe + end end diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index 968f1f290..4357b3c20 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -513,6 +513,8 @@ RSpec.describe "Lettings Log Features" do click_button("Save and continue") expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}") expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list") end it "allows deduplicating logs by changing the answers on the original log" do @@ -521,6 +523,8 @@ RSpec.describe "Lettings Log Features" do click_button("Save and continue") expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}") expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("Log #{lettings_log.id} is no longer a duplicate and has been removed from the list") end end end diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 3e36ec243..fae1d030b 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -252,6 +252,8 @@ RSpec.describe "Sales Log Features" do click_button("Save and continue") expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}") expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list") end it "allows deduplicating logs by changing the answers on the original log" do @@ -260,6 +262,8 @@ RSpec.describe "Sales Log Features" do click_button("Save and continue") expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}") expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("Log #{sales_log.id} is no longer a duplicate and has been removed from the list") end end end