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.rbindex 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 PageObjectsenddef 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_openenddiff --git a/plugins/chat/spec/system/shortcuts/drawer_spec.rb b/plugins/chat/spec/system/shortcuts/drawer_spec.rbindex 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" docontext "when pressing dash" doit "opens the drawer" do- expect(chat_page).to have_css("#site-logo")page.send_keys("-")expect(chat_page).to have_drawerdiff --git a/plugins/discourse-adplugin/spec/system/ad_impression_spec.rb b/plugins/discourse-adplugin/spec/system/ad_impression_spec.rbindex 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" doit "does not record impression before scrolling into view" dovisit "/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.rbindex 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" dodef 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.rbindex c1a5fa552b1..b3c7a30cdbc 100644--- a/spec/support/system_helpers.rb+++ b/spec/support/system_helpers.rb@@ -54,6 +54,14 @@ module SystemHelpersselfend+ # 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 SystemHelpersNokogiri.HTML5(html_translation).at("body").inner_textendend++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.rbindex 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" doit "boots ember for non-existent route" dovisit "/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")endit "boots ember for non-existent topic" dovisit "/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")endenddiff --git a/spec/system/capabilities_service_spec.rb b/spec/system/capabilities_service_spec.rbindex d00718dc44c..4f65ff54184 100644--- a/spec/system/capabilities_service_spec.rb+++ b/spec/system/capabilities_service_spec.rb@@ -8,7 +8,6 @@ describe "capabilities service" doendvisit "/"- 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.rbindex 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" doexpect(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")endit "can boot logster in strict_dynamic mode" dodiff --git a/spec/system/dev_tools_spec.rb b/spec/system/dev_tools_spec.rbindex 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" dodescribe "toolbar" doit "can be enabled and disabled" dovisit("/latest")- expect(page).to have_css("#site-logo")expect(toolbar).to have_no_toolbartoolbar.enable@@ -16,7 +15,6 @@ describe "Discourse dev tools" dotoolbar.disableexpect(toolbar).to have_no_toolbar- expect(page).to have_css("#site-logo")endenddiff --git a/spec/system/i18n_override_spec.rb b/spec/system/i18n_override_spec.rbindex 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" doit "applies overrides to js and admin_js keys" dovisit("/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" doit "applies override from user locale and prefers user locale translation over fallback override" dosign_in(user)visit("/latest")- expect(page).to have_css("#site-logo")# Override in user's locale is appliedde_override = page.evaluate_script("I18n.t('dates.tiny.half_a_minute')")diff --git a/spec/system/locale_spec.rb b/spec/system/locale_spec.rbindex 23bb3cd5145..79f09fc6999 100644--- a/spec/system/locale_spec.rb+++ b/spec/system/locale_spec.rb@@ -81,7 +81,6 @@ RSpec.describe "Locale choice" doSiteSetting.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" doit "works for english" doSiteSetting.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" doit "works for other locales" doSiteSetting.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" doit "does not throw error for invalid plural keys" doSiteSetting.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 stringsilence_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.rbindex b675e74da50..7e451cdddf1 100644--- a/spec/system/script_encoding_spec.rb+++ b/spec/system/script_encoding_spec.rb@@ -38,8 +38,6 @@ describe "script encoding" dovisit "/latest"- expect(page).to have_css("#site-logo")-expect(js_cdn_requests.length).to be > 1expect(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" dovisit "/latest"- expect(page).to have_css("#site-logo")-expect(js_cdn_requests.length).to be > 1expect(js_cdn_requests.all? { |r| r.end_with?(".br.js") }).to eq(true)