Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Render all flashes as primerized

Oliver Günther7e645a02c9b3
diff --git a/app/components/op_primer/flash_component.rb b/app/components/op_primer/flash_component.rb
index 2c50edc45ac..c93edcae9a7 100644
--- a/app/components/op_primer/flash_component.rb
+++ b/app/components/op_primer/flash_component.rb
@@ -35,7 +35,7 @@ module OpPrimer
def initialize(**system_arguments)
@unique_key = system_arguments.delete(:unique_key)
- system_arguments[:test_selector] ||= "primer-banner-message-component"
+ system_arguments[:test_selector] ||= "op-primer-flash-message"
system_arguments[:dismiss_scheme] ||= :remove
system_arguments[:dismiss_label] ||= I18n.t(:button_close)
diff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rb
index 8015199aaaf..cf047b012ae 100644
--- a/app/helpers/flash_messages_helper.rb
+++ b/app/helpers/flash_messages_helper.rb
@@ -67,7 +67,7 @@ module FlashMessagesHelper
:danger
when :warning
:warning
- when :notice
+ when :success, :notice
:success
else
:default
diff --git a/spec/support/primerized_flash/expectations.rb b/spec/support/primerized_flash/expectations.rb
new file mode 100644
index 00000000000..b431bf1bcb0
--- /dev/null
+++ b/spec/support/primerized_flash/expectations.rb
@@ -0,0 +1,40 @@
+module PrimerizedFlash
+ module Expectations
+ include FlashMessagesHelper
+
+ def expect_primerized_flash(message:, type: :success, wait: 20)
+ mapped_scheme = mapped_flash_type(type)
+ expect(page).to have_css(".Banner--#{mapped_scheme}", text: message, wait:)
+ end
+
+ def expect_and_dismiss_primerized_flash(message: nil, type: :success, wait: 20)
+ expect_primerized_flash(type:, message:, wait:)
+ dismiss_primerized_flash!
+ expect_no_primerized_flash(type:, message:, wait: 0.1)
+ end
+
+ def dismiss_primerized_flash!
+ page.find(".Banner-close button").click # rubocop:disable Capybara/SpecificActions
+ end
+
+ # Clears a toaster if there is one waiting 1 second max, but do not fail if there is none
+ def clear_primerized_flashes
+ if has_css?(".Banner-close button")
+ dismiss_primerized_flash!
+ end
+ end
+
+ def expect_no_primerized_flash(type: :success, message: nil, wait: 10)
+ if type.nil?
+ expect(page).not_to have_test_selector("op-primer-flash-message")
+ else
+ mapped_scheme = mapped_flash_type(type)
+ expect(page).to have_no_css(".Banner--#{mapped_scheme}", text: message, wait:)
+ end
+ end
+ end
+end
+
+RSpec.configure do |config|
+ config.include PrimerizedFlash::Expectations
+end