Skip to content

A platform for community discussion. Free, open, simple.

DEV: Merge "wait for app boot" and "wait for settled" logic (#39769)

Jarek Radosz564ee3b63487
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 53d13e285bd..2af96476fd0 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -612,10 +612,21 @@ RSpec.configure do |config|
METHODS_TO_PATCH.each do |method_name|
define_method(method_name) do |*args, **options|
result = super(*args, **options)
+ wait_for_ember_boot
wait_for_client_settled(method_name)
result
end
end
+
+ private
+
+ # `<discourse-assets>` is only present on Ember pages; `ember-application`
+ # is added to the root element (`#main`) once Ember mounts.
+ def wait_for_ember_boot
+ session = @driver.send(:session)
+ return if session.has_no_css?("discourse-assets", wait: 0, visible: :all)
+ session.assert_selector("#main.ember-application", visible: :all)
+ end
end
Capybara::Playwright::Node.prepend(CapybaraPlaywrightNodePatch)
diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb
index db4efc7cd04..cbeed423fdf 100644
--- a/spec/support/system_helpers.rb
+++ b/spec/support/system_helpers.rb
@@ -434,28 +434,3 @@ module SystemHelpers
read.call
end
end
-
-module CapybaraSessionEmberWaiter
- def visit(...)
- super
- wait_for_ember_boot
- end
-
- def refresh
- super
- wait_for_ember_boot
- end
-
- private
-
- def wait_for_ember_boot
- return unless RSpec.current_example&.metadata&.[](:type) == :system
-
- # `<discourse-assets>` is only present on Ember pages;
- return if has_no_css?("discourse-assets", wait: 0, visible: :all)
- # `ember-application` is added to `#main` when the app boots.
- assert_selector("#main.ember-application", visible: :all)
- end
-end
-
-Capybara::Session.prepend(CapybaraSessionEmberWaiter)
diff --git a/spec/system/category_localizations_spec.rb b/spec/system/category_localizations_spec.rb
index 48333363a7f..0191f2a98cd 100644
--- a/spec/system/category_localizations_spec.rb
+++ b/spec/system/category_localizations_spec.rb
@@ -168,7 +168,11 @@ describe "Category Localizations" do
category_page.save_settings
page.refresh
- expect(category_page).to_not have_css("#control-localizations-0-locale option.--selected")
+ expect(CategoryLocalization.where(category_id: category.id).count).to eq(1)
+ expect(category_page).to have_selector(
+ ".edit-category-tab-localizations .form-kit__collection .form-kit__row",
+ count: 1,
+ )
end
end
end