Skip to content

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

DEV: Make `visit()` wait for the app to boot (#39659)

Jarek Radoszc29c566dc2cf
diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rb
index 40fd0fcdc24..04269ef23dd 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat.rb
@@ -52,7 +52,6 @@ module PageObjects
end
def open_new_message(ensure_open: true)
- expect(self).to have_css("#site-logo")
send_keys([PLATFORM_KEY_MODIFIER, "k"])
find(".chat-modal-new-message") if ensure_open
end
diff --git a/plugins/chat/spec/system/shortcuts/drawer_spec.rb b/plugins/chat/spec/system/shortcuts/drawer_spec.rb
index 9215675ad40..25e6aa33758 100644
--- a/plugins/chat/spec/system/shortcuts/drawer_spec.rb
+++ b/plugins/chat/spec/system/shortcuts/drawer_spec.rb
@@ -20,7 +20,6 @@ RSpec.describe "Shortcuts | drawer" do
context "when pressing dash" do
it "opens the drawer" do
- expect(chat_page).to have_css("#site-logo")
page.send_keys("-")
expect(chat_page).to have_drawer
diff --git a/plugins/discourse-adplugin/spec/system/ad_impression_spec.rb b/plugins/discourse-adplugin/spec/system/ad_impression_spec.rb
index 7c217d56f69..b190fc22d1a 100644
--- a/plugins/discourse-adplugin/spec/system/ad_impression_spec.rb
+++ b/plugins/discourse-adplugin/spec/system/ad_impression_spec.rb
@@ -52,7 +52,6 @@ describe "AdPlugin::AdImpression" do
it "does not record impression before scrolling into view" do
visit "/latest"
- expect(page).to have_css("#site-logo")
expect(AdPlugin::AdImpression.count).to eq(0)
page.execute_script("window.scrollTo(0, document.body.scrollHeight);")
diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
index 5ecbde76d88..56c3b631002 100644
--- a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb
@@ -37,7 +37,6 @@ RSpec.describe "AI Post helper" do
def select_post_text(selected_post)
topic_page.visit_topic(topic)
- expect(page).to have_css("#site-logo")
page.execute_script(
"var element = document.querySelector('#{topic_page.post_by_number_selector(selected_post.post_number)} .cooked p'); " +
"var range = document.createRange(); " + "range.selectNodeContents(element); " +
diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb
index c1a5fa552b1..b3c7a30cdbc 100644
--- a/spec/support/system_helpers.rb
+++ b/spec/support/system_helpers.rb
@@ -54,6 +54,14 @@ module SystemHelpers
self
end
+ # Waits for the Ember app to boot before continuing.
+ def visit(...)
+ super
+ return if page.has_no_css?("discourse-assets", wait: 0, visible: :all)
+
+ page.assert_selector("#main.ember-application", visible: :all)
+ end
+
def sign_in(user)
visit File.join(
GlobalSetting.relative_url_root || "",
@@ -407,3 +415,16 @@ module SystemHelpers
Nokogiri.HTML5(html_translation).at("body").inner_text
end
end
+
+module CapybaraSessionEmberWaiter
+ # Waits for the Ember app to boot before continuing.
+ def refresh
+ super
+ return unless RSpec.current_example&.metadata&.[](:type) == :system
+ return if has_no_css?("discourse-assets", wait: 0, visible: :all)
+
+ assert_selector("#main.ember-application", visible: :all)
+ end
+end
+
+Capybara::Session.prepend(CapybaraSessionEmberWaiter)
diff --git a/spec/system/bootstrap_error_pages_spec.rb b/spec/system/bootstrap_error_pages_spec.rb
index f48269794fc..a3cdb285db6 100644
--- a/spec/system/bootstrap_error_pages_spec.rb
+++ b/spec/system/bootstrap_error_pages_spec.rb
@@ -5,15 +5,15 @@ describe "bootstrap_error_pages" do
it "boots ember for non-existent route" do
visit "/foobar"
- expect(page).not_to have_css("body.no-ember")
expect(page).to have_css("#site-logo")
expect(page).to have_css("div.page-not-found")
+ expect(page).not_to have_css("body.no-ember")
end
it "boots ember for non-existent topic" do
visit "/t/999999999999"
- expect(page).not_to have_css("body.no-ember")
expect(page).to have_css("#site-logo")
expect(page).to have_css("div.page-not-found")
+ expect(page).not_to have_css("body.no-ember")
end
end
diff --git a/spec/system/capabilities_service_spec.rb b/spec/system/capabilities_service_spec.rb
index d00718dc44c..4f65ff54184 100644
--- a/spec/system/capabilities_service_spec.rb
+++ b/spec/system/capabilities_service_spec.rb
@@ -8,7 +8,6 @@ describe "capabilities service" do
end
visit "/"
- expect(page).to have_css("#site-logo")
expect(matches("sm")).to eq(true)
expect(matches("lg")).to eq(true)
diff --git a/spec/system/content_security_policy_spec.rb b/spec/system/content_security_policy_spec.rb
index 8f8ae3ba4c2..2d8738d6020 100644
--- a/spec/system/content_security_policy_spec.rb
+++ b/spec/system/content_security_policy_spec.rb
@@ -41,8 +41,8 @@ describe "Content security policy" do
expect(response.headers["Content-Security-Policy"]).to include("'strict-dynamic'")
visit "/nonexistent"
- expect(page).not_to have_css("body.no-ember")
expect(page).to have_css("#site-logo")
+ expect(page).not_to have_css("body.no-ember")
end
it "can boot logster in strict_dynamic mode" do
diff --git a/spec/system/dev_tools_spec.rb b/spec/system/dev_tools_spec.rb
index 5c63699d368..bcefbbdf4c7 100644
--- a/spec/system/dev_tools_spec.rb
+++ b/spec/system/dev_tools_spec.rb
@@ -8,7 +8,6 @@ describe "Discourse dev tools" do
describe "toolbar" do
it "can be enabled and disabled" do
visit("/latest")
- expect(page).to have_css("#site-logo")
expect(toolbar).to have_no_toolbar
toolbar.enable
@@ -16,7 +15,6 @@ describe "Discourse dev tools" do
toolbar.disable
expect(toolbar).to have_no_toolbar
- expect(page).to have_css("#site-logo")
end
end
diff --git a/spec/system/i18n_override_spec.rb b/spec/system/i18n_override_spec.rb
index 33141c554b7..7c0960104ef 100644
--- a/spec/system/i18n_override_spec.rb
+++ b/spec/system/i18n_override_spec.rb
@@ -41,7 +41,6 @@ describe "I18n translation overrides" do
it "applies overrides to js and admin_js keys" do
visit("/latest")
- expect(page).to have_css("#site-logo")
js_result = page.evaluate_script("I18n.t('dates.tiny.half_a_minute')")
expect(js_result).to eq("override for js key")
@@ -63,7 +62,6 @@ describe "I18n translation overrides" do
it "applies override from user locale and prefers user locale translation over fallback override" do
sign_in(user)
visit("/latest")
- expect(page).to have_css("#site-logo")
# Override in user's locale is applied
de_override = page.evaluate_script("I18n.t('dates.tiny.half_a_minute')")
diff --git a/spec/system/locale_spec.rb b/spec/system/locale_spec.rb
index 23bb3cd5145..79f09fc6999 100644
--- a/spec/system/locale_spec.rb
+++ b/spec/system/locale_spec.rb
@@ -81,7 +81,6 @@ RSpec.describe "Locale choice" do
SiteSetting.default_locale = "uk"
visit "/"
- expect(page).to have_css("#site-logo")
expect(page.evaluate_script("I18n.locale")).to eq("uk")
expect(page.evaluate_script("Object.keys(I18n.translations)")).to contain_exactly("uk", "en")
@@ -128,7 +127,6 @@ RSpec.describe "Locale choice" do
it "works for english" do
SiteSetting.default_locale = "en"
visit "/"
- expect(page).to have_css("#site-logo")
expect(page.evaluate_script("Object.keys(I18n._mfMessages._data)")).to eq(["en"])
expect(
@@ -145,7 +143,6 @@ RSpec.describe "Locale choice" do
it "works for other locales" do
SiteSetting.default_locale = "fr"
visit "/"
- expect(page).to have_css("#site-logo")
expect(page.evaluate_script("Object.keys(I18n._mfMessages._data)")).to contain_exactly(
"en",
@@ -184,7 +181,6 @@ RSpec.describe "Locale choice" do
it "does not throw error for invalid plural keys" do
SiteSetting.default_locale = "ja"
visit "/"
- expect(page).to have_css("#site-logo")
expect(page.evaluate_script("Object.keys(I18n._mfMessages._data)")).to contain_exactly(
"ja",
@@ -201,8 +197,6 @@ RSpec.describe "Locale choice" do
# Suppress the expected error from the intentionally malformed zh_TW MF string
silence_stdout { visit "/" }
- expect(page).to have_css("#site-logo")
-
expect(page.evaluate_script("Object.keys(I18n._mfMessages._data)").length).to eq(0)
expect(
page.evaluate_script("I18n._mfMessages.get('posts_likes_MF', {count: 3, ratio: 'med'})"),
diff --git a/spec/system/script_encoding_spec.rb b/spec/system/script_encoding_spec.rb
index b675e74da50..7e451cdddf1 100644
--- a/spec/system/script_encoding_spec.rb
+++ b/spec/system/script_encoding_spec.rb
@@ -38,8 +38,6 @@ describe "script encoding" do
visit "/latest"
- expect(page).to have_css("#site-logo")
-
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.any? { |r| r.end_with?(".br.js") }).to eq(false)
expect(js_cdn_requests.all? { |r| r.end_with?(".js") }).to eq(true)
@@ -72,8 +70,6 @@ describe "script encoding" do
visit "/latest"
- expect(page).to have_css("#site-logo")
-
expect(js_cdn_requests.length).to be > 1
expect(js_cdn_requests.all? { |r| r.end_with?(".br.js") }).to eq(true)