A platform for community discussion. Free, open, simple.
DEV: Add client settled checks for system tests (#35230)
Alan Guo Xiang Tan55b05c921bde
diff --git a/app/assets/javascripts/discourse/app/initializers/rails-testing.js b/app/assets/javascripts/discourse/app/initializers/rails-testing.jsnew file mode 100644index 00000000000..aee57d0752f--- /dev/null+++ b/app/assets/javascripts/discourse/app/initializers/rails-testing.js@@ -0,0 +1,180 @@+import { DEBUG } from "@glimmer/env";+import $ from "jquery";+import { isRailsTesting } from "discourse/lib/environment";++export default {+ after: ["discourse-bootstrap"],++ initialize() {+ if (DEBUG && isRailsTesting()) {+ const setupDataElement = document.getElementById("data-discourse-setup");+ const isSettledDebugEnabled =+ setupDataElement?.dataset.capybaraPlaywrightDebugClientSettled ===+ "true";++ const logSettledDebug = (...args) => {+ if (!isSettledDebugEnabled) {+ return;+ }++ // eslint-disable-next-line no-console+ console.log(`[${Date.now() / 1000}]`, ...args);+ };++ const deferEventCycles = ({ callback, numberOfEventCycles = 1 }) => {+ if (numberOfEventCycles > 0) {+ return setTimeout(() => {+ deferEventCycles({+ callback,+ numberOfEventCycles: numberOfEventCycles - 1,+ });+ }, 0);+ } else {+ return callback();+ }+ };++ const pendingRequests = [];+ const pendingDomEvents = [];++ const incrementAjaxPendingRequests = (_event, xhr, settings) => {+ if (+ // Ignore MessageBus and Presence requests as they are long-running and continuous respectively+ settings.url.includes("/message-bus") ||+ settings.url.includes("/presence/")+ ) {+ return;+ }++ logSettledDebug("AJAX request initiated", settings.url);+ pendingRequests.push({ xhr, url: settings.url });+ };++ const decrementAjaxPendingRequests = (_event, xhr, settings) => {+ for (let i = 0; i < pendingRequests.length; i++) {+ if (xhr === pendingRequests[i].xhr) {+ logSettledDebug("AJAX request completed", settings.url);+ pendingRequests.splice(i, 1);+ break;+ }+ }+ };++ const trackJQueryAjax = () => {+ $(document)+ .on("ajaxSend", incrementAjaxPendingRequests)+ .on("ajaxComplete ajaxError", decrementAjaxPendingRequests);+ };++ const trackDomEvents = ({ eventNames, numberOfEventCyclesToDefer }) => {+ eventNames.forEach((eventName) => {+ document.addEventListener(+ eventName,+ (event) => {+ logSettledDebug(`${eventName} event detected`, event);+ pendingDomEvents.push(event);++ deferEventCycles({+ callback: () => {+ const index = pendingDomEvents.indexOf(event);++ if (index !== -1) {+ pendingDomEvents.splice(index, 1);+ }++ logSettledDebug(`${eventName} event settled`, event);+ },+ numberOfEventCycles: numberOfEventCyclesToDefer,+ });+ },+ true+ );+ });+ };++ // Tracking jQuery AJAX requests and DOM events for now. Can be expanded in the future if needed.+ const track = () => {+ trackJQueryAjax();++ trackDomEvents({+ eventNames: [+ "click",+ "input",+ "mousedown",+ "keydown",+ "focusin",+ "focusout",+ "touchstart",+ "change",+ "resize",+ "scroll",+ ],+ numberOfEventCyclesToDefer: 2,+ });+ };++ track();++ const settled = () => {+ return pendingRequests.length === 0 && pendingDomEvents.length === 0;+ };++ const timeoutErrorMessage = (timeoutMs) => {+ let errorMessage = `Timeout waiting for client to settle after ${timeoutMs}ms.`;+ const pendingRequestURLs = pendingRequests.map((req) => req.url);++ if (pendingRequestURLs.length > 0) {+ errorMessage += `\n Pending requests: ${pendingRequestURLs.join(", ")}`;+ }++ const pendingDOMEventsText = pendingDomEvents.map((event) => {+ let message = event.type;+ const element = event.target;+ const tagName = element?.tagName?.toLowerCase();++ if (tagName) {+ message += ` on ${tagName}`;++ // can't I print something like `div.some-class.other-class`?+ const classes = Array.from(element.classList).join(".");++ if (classes.length > 0) {+ message += `.${classes}`;+ }+ }++ return message;+ });++ if (pendingDOMEventsText.length > 0) {+ errorMessage += `\n Pending DOM events: ${pendingDOMEventsText.join(", ")}`;+ }++ return errorMessage;+ };++ window.clientSettled = async (timeoutMs) => {+ const startTime = Date.now();++ while (!settled()) {+ if (Date.now() - startTime > timeoutMs) {+ throw new Error(timeoutErrorMessage(timeoutMs));+ }++ logSettledDebug("Waiting for client to settle...", {+ pendingRequests,+ pendingDomEvents,+ });++ await new Promise((resolve) =>+ deferEventCycles({ callback: resolve, numberOfEventCycles: 1 })+ );+ }++ logSettledDebug("Client Settled!");++ return true;+ };+ }+ },+};diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 432ccbcda8a..cde43666efb 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -832,6 +832,10 @@ module ApplicationHelpersetup_data[:mb_last_file_change_id] = MessageBus.last_id("/file-change")end+ if Rails.env.test? && ENV["CAPYBARA_PLAYWRIGHT_DEBUG_CLIENT_SETTLED"].present?+ setup_data[:capybara_playwright_debug_client_settled] = true+ end+if guardian.can_enable_safe_mode? && params["safe_mode"]setup_data[:safe_mode] = normalized_safe_modeenddiff --git a/bin/rspec b/bin/rspecindex fc4af083fb6..6cb4281c6e1 100755--- a/bin/rspec+++ b/bin/rspec@@ -20,5 +20,6 @@ if ENV["LOAD_PLUGINS"].nil? && ARGV.any? { |pattern| pattern.include?("plugins/"endENV["PLAYWRIGHT_HEADLESS"] = "0" if ARGV.delete("--headful")+ENV["CAPYBARA_PLAYWRIGHT_DEBUG_CLIENT_SETTLED"] = "1" if ARGV.delete("--debug-client-settled")load Gem.bin_path("rspec-core", "rspec")diff --git a/plugins/automation/spec/system/smoke_test_spec.rb b/plugins/automation/spec/system/smoke_test_spec.rbindex 6a5bbd361f1..5b69b058678 100644--- a/plugins/automation/spec/system/smoke_test_spec.rb+++ b/plugins/automation/spec/system/smoke_test_spec.rb@@ -49,9 +49,7 @@ describe "DiscourseAutomation | smoke test", type: :system doexpect(page).not_to have_css(".automations__name", text: "automation-test")- try_until_success do- expect(DiscourseAutomation::Automation.exists?(id: automation.id)).to be(false)- end+ expect(DiscourseAutomation::Automation.exists?(id: automation.id)).to be(false)endenddiff --git a/plugins/chat/spec/system/chat_message_interaction_spec.rb b/plugins/chat/spec/system/chat_message_interaction_spec.rbindex c2ecb18f921..08296347ae4 100644--- a/plugins/chat/spec/system/chat_message_interaction_spec.rb+++ b/plugins/chat/spec/system/chat_message_interaction_spec.rb@@ -48,7 +48,7 @@ RSpec.describe "Interacting with a message", type: :system doDiscourseEvent.on(:chat_message_interaction, &blk)find(".block__button").click- try_until_success do+ try_until_success(reason: "Relies on an Ember timer causing a delay") doexpect(action_id).to_not be_nilexpect(chat_channel_page.messages).to have_text(action_id)enddiff --git a/plugins/chat/spec/system/chat_new_message_spec.rb b/plugins/chat/spec/system/chat_new_message_spec.rbindex 8a16c381aa4..07c9b565a70 100644--- a/plugins/chat/spec/system/chat_new_message_spec.rb+++ b/plugins/chat/spec/system/chat_new_message_spec.rb@@ -58,7 +58,7 @@ RSpec.describe "Chat New Message from params", type: :system dochat_page.visit_new_message([user_1, user_3])- try_until_success { expect(Chat::Channel.count - original_channel_count).to eq(1) }+ expect(Chat::Channel.count - original_channel_count).to eq(1)expect(page).to have_current_path(%r{/chat/c/#{group_slug([user_1, user_3])}/#{Chat::Channel.last.id}},diff --git a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb b/plugins/chat/spec/system/hashtag_autocomplete_spec.rbindex 76da492b69c..d30f0d30595 100644--- a/plugins/chat/spec/system/hashtag_autocomplete_spec.rb+++ b/plugins/chat/spec/system/hashtag_autocomplete_spec.rb@@ -53,15 +53,12 @@ describe "Using #hashtag autocompletion to search for and lookup channels", type)chat_channel_page.click_send_message- message = nil- try_until_success do- message =- Chat::Message.find_by(- user: user,- message: "this is #random and this is #raspberry-beret and this is #razed which is cool",- )- expect(message).not_to eq(nil)- end+ message =+ Chat::Message.find_by(+ user: user,+ message: "this is #random and this is #raspberry-beret and this is #razed which is cool",+ )+expect(chat_channel_page.messages).to have_message(id: message.id)expect(page).to have_css(".hashtag-cooked[aria-label]", count: 3)diff --git a/plugins/chat/spec/system/list_channels/drawer_spec.rb b/plugins/chat/spec/system/list_channels/drawer_spec.rbindex 3fa1ef3f7c7..a804e556deb 100644--- a/plugins/chat/spec/system/list_channels/drawer_spec.rb+++ b/plugins/chat/spec/system/list_channels/drawer_spec.rb@@ -150,13 +150,11 @@ RSpec.describe "List channels | Drawer", type: :system dodrawer_page.visit_indexdrawer_page.click_direct_messages- try_until_success do- expect(drawer_page).to have_channel_at_position(dm_channel_2, 1)- expect(drawer_page).to have_urgent_channel(dm_channel_2)- expect(drawer_page).to have_channel_at_position(dm_channel_4, 2)- expect(drawer_page).to have_channel_at_position(dm_channel_1, 3)- expect(drawer_page).to have_channel_at_position(dm_channel_3, 4)- end+ expect(drawer_page).to have_channel_at_position(dm_channel_2, 1)+ expect(drawer_page).to have_urgent_channel(dm_channel_2)+ expect(drawer_page).to have_channel_at_position(dm_channel_4, 2)+ expect(drawer_page).to have_channel_at_position(dm_channel_1, 3)+ expect(drawer_page).to have_channel_at_position(dm_channel_3, 4)endcontext "with unread threads" dodiff --git a/plugins/chat/spec/system/message_thread_indicator_spec.rb b/plugins/chat/spec/system/message_thread_indicator_spec.rbindex 9d010770680..3a3bc064f31 100644--- a/plugins/chat/spec/system/message_thread_indicator_spec.rb+++ b/plugins/chat/spec/system/message_thread_indicator_spec.rb@@ -84,11 +84,7 @@ describe "Thread indicator for chat messages", type: :system doexpect(channel_page).to have_thread_indicator(message_without_thread)- new_thread = nil- try_until_success(timeout: 5) do- new_thread = message_without_thread.reload.thread- expect(new_thread).to be_present- end+ new_thread = message_without_thread.reload.threadexpect(page).not_to have_css(channel_page.message_by_id_selector(new_thread.replies.first))enddiff --git a/plugins/chat/spec/system/send_message_spec.rb b/plugins/chat/spec/system/send_message_spec.rbindex a07efe8dc85..4a74011ab3f 100644--- a/plugins/chat/spec/system/send_message_spec.rb+++ b/plugins/chat/spec/system/send_message_spec.rb@@ -118,10 +118,8 @@ RSpec.describe "Send message", type: :system dodrawer_page.open_channel(channel_1)channel_page.send_message- try_until_success do- expect(tested_context.dig(:context, :post_ids)).to eq([post_1.id, post_2.id])- expect(tested_context.dig(:context, :topic_id)).to eq(post_1.topic_id)- end+ expect(tested_context.dig(:context, :post_ids)).to eq([post_1.id, post_2.id])+ expect(tested_context.dig(:context, :topic_id)).to eq(post_1.topic_id)ensureDiscourseEvent.off(:chat_message_created, &blk)enddiff --git a/plugins/chat/spec/system/update_last_read_spec.rb b/plugins/chat/spec/system/update_last_read_spec.rbindex 9292fba851b..70b97b3bc83 100644--- a/plugins/chat/spec/system/update_last_read_spec.rb+++ b/plugins/chat/spec/system/update_last_read_spec.rb@@ -22,7 +22,9 @@ RSpec.describe "Update last read", type: :system dolast_message = Fabricate(:chat_message, chat_channel: channel_1)chat_page.visit_channel(channel_1)- try_until_success { expect(membership.reload.last_read_message_id).to eq(last_message.id) }+ try_until_success(+ reason: "Relies on Ember timer to fire off request to update last_read_message_id",+ ) { expect(membership.reload.last_read_message_id).to eq(last_message.id) }endend@@ -32,7 +34,9 @@ RSpec.describe "Update last read", type: :system dolast_message = Fabricate(:chat_message, chat_channel: channel_1, use_service: true)- try_until_success { expect(membership.reload.last_read_message_id).to eq(last_message.id) }+ try_until_success(+ reason: "Relies on Ember timer to fire off request to update last_read_message_id",+ ) { expect(membership.reload.last_read_message_id).to eq(last_message.id) }endend@@ -43,7 +47,9 @@ RSpec.describe "Update last read", type: :system dolast_message = Fabricate(:chat_message, chat_channel: channel_1)chat_page.visit_channel(channel_1)- try_until_success { expect(membership.reload.last_read_message_id).to eq(last_message.id) }+ try_until_success(+ reason: "Relies on Ember timer to fire off request to update last_read_message_id",+ ) { expect(membership.reload.last_read_message_id).to eq(last_message.id) }endendenddiff --git a/plugins/chat/spec/system/uploads_spec.rb b/plugins/chat/spec/system/uploads_spec.rbindex ce6da789182..e074630d6bc 100644--- a/plugins/chat/spec/system/uploads_spec.rb+++ b/plugins/chat/spec/system/uploads_spec.rb@@ -75,7 +75,7 @@ describe "Uploading files in chat messages", type: :system domessage = Chat::Message.last- try_until_success(timeout: 5) { expect(message.uploads.first.thumbnail).to be_present }+ expect(message.uploads.first.thumbnail).to be_presentupload = message.uploads.first@@ -169,7 +169,7 @@ describe "Uploading files in chat messages", type: :system doexpect(channel_page.message_by_id(message_2.id)).to have_no_css(".chat-uploads")channel_page.click_send_message- try_until_success(timeout: 5) { expect(message_2.reload.upload_ids).to be_empty }+ expect(message_2.reload.upload_ids).to be_emptyendit "allows adding more uploads" do@@ -184,8 +184,7 @@ describe "Uploading files in chat messages", type: :system doexpect(page).to have_no_css(".chat-composer-upload")expect(page).to have_css(".chat-img-upload", count: 2)-- try_until_success(timeout: 5) { expect(message_2.reload.uploads.count).to eq(2) }+ expect(message_2.reload.uploads.count).to eq(2)endenddiff --git a/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rbindex 20fb43ac61f..77e90ceec50 100644--- a/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rb+++ b/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rb@@ -77,10 +77,7 @@ RSpec.describe "Admin AI persona configuration", type: :system doform.field("name").fill_in("Test Persona 1")form.field("enabled").toggle- try_until_success { expect(persona.reload.enabled).to eq(true) }-- persona.reload- expect(persona.enabled).to eq(true)+ expect(persona.reload.enabled).to eq(true)expect(persona.name).not_to eq("Test Persona 1")end@@ -93,8 +90,7 @@ RSpec.describe "Admin AI persona configuration", type: :system doform.field("name").fill_in(updated_name)form.field("enabled").toggle- try_until_success { expect(persona.reload.enabled).to eq(true) }-+ expect(persona.reload.enabled).to eq(true)expect(form.field("name").value).to eq(updated_name)end@@ -107,8 +103,7 @@ RSpec.describe "Admin AI persona configuration", type: :system doform.field("name").fill_in(updated_name)form.field("priority").toggle- try_until_success { expect(persona.reload.priority).to eq(true) }-+ expect(persona.reload.priority).to eq(true)expect(form.field("name").value).to eq(updated_name)enddiff --git a/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rbindex b2af0feec2d..5f9e4df1d5d 100644--- a/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb@@ -132,10 +132,8 @@ RSpec.describe "AI Bot - Homepage", type: :system do"article[data-post-id='#{post_with_link.id}'] .cooked a[href='#{post_url}']",).click- try_until_success do- expect(topic_page.current_topic).to eq(regular_topic)- expect(page).to have_css("article[data-post-id='#{regular_post.id}']")- end+ expect(topic_page.current_topic).to eq(regular_topic)+ expect(page).to have_css("article[data-post-id='#{regular_post.id}']")endenddiff --git a/plugins/discourse-ai/spec/system/ai_bot/share_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/share_spec.rbindex 8a3852fddba..56ac9353cc9 100644--- a/plugins/discourse-ai/spec/system/ai_bot/share_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_bot/share_spec.rb@@ -57,10 +57,8 @@ RSpec.describe "Share conversation", type: :system dofind("#post_2 .post-action-menu__share-ai").click- try_until_success do- clip_text = cdp.read_clipboard- expect(clip_text).not_to eq("")- end+ clip_text = cdp.read_clipboard+ expect(clip_text).not_to eq("")conversation = (<<~TEXT).strip<details class='ai-quote'>@@ -92,10 +90,8 @@ RSpec.describe "Share conversation", type: :system dofind("#post_2 .post-action-menu__share-ai").click- try_until_success do- clip_text = cdp.read_clipboard- expect(clip_text).not_to eq("")- end+ clip_text = cdp.read_clipboard+ expect(clip_text).not_to eq("")conversation = (<<~TEXT).strip<details class='ai-quote'>@@ -122,10 +118,8 @@ RSpec.describe "Share conversation", type: :system dofind(".ai-share-modal__slider input").set("2")find(".ai-share-modal button.btn-primary").click- try_until_success do- clip_text = cdp.read_clipboard- expect(clip_text).not_to eq("")- end+ clip_text = cdp.read_clipboard+ expect(clip_text).not_to eq("")conversation = (<<~TEXT).strip<details class='ai-quote'>diff --git a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rbindex 4e19572f29d..5431b3598e0 100644--- a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb@@ -32,7 +32,7 @@ RSpec.describe "AI Spam Configuration", type: :system dotoggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")toggle.toggle- try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }+ expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id)find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")find(".ai-spam__instructions-save").clickdiff --git a/plugins/discourse-assign/spec/system/assign_topic_spec.rb b/plugins/discourse-assign/spec/system/assign_topic_spec.rbindex 7a96b74fe2c..e7bc7fcb992 100644--- a/plugins/discourse-assign/spec/system/assign_topic_spec.rb+++ b/plugins/discourse-assign/spec/system/assign_topic_spec.rb@@ -180,7 +180,8 @@ describe "Assign | Assigning topics", type: :system doI18n.t("js.action_codes.closed.disabled", when: "just now"),)expect(page).to have_no_css("#post_5")- try_until_success do++ try_until_success(reason: "Relies on MessageBus updates") doexpect(find("#topic .assigned-to")).to have_content(admin2.username)endenddiff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rbindex 613db800ce1..d2a6d207c5c 100644--- a/plugins/discourse-calendar/spec/system/post_event_spec.rb+++ b/plugins/discourse-calendar/spec/system/post_event_spec.rb@@ -176,14 +176,7 @@ describe "Post event", type: :system doexpect(page).to have_css(".event-info .name", text: "<script>alert(1);</script>")end- xit "can create, close, and open an event" do- # failing on:- # Playwright::Error:- # Element is not attached to the DOM- # Call log:- # - attempting click action- # - - waiting for element to be visible, enabled and stable- # - - element is visible, enabled and stable+ it "can create, close, and open an event" dovisit "/new-topic"title = "My upcoming l33t event"tomorrow = (1.day.from_now).strftime("%Y-%m-%d")@@ -204,12 +197,10 @@ describe "Post event", type: :system dofind(".d-modal .add-invitee").clicktopic_page = PageObjects::Pages::Topic.new- try_until_success do- topic = Topic.find(topic_page.current_topic_id)- event = topic.posts.first.event- expect(event.invitees.count).to eq(2)- end+ topic = Topic.find(topic_page.current_topic_id)+ event = topic.posts.first.event+ expect(event.invitees.count).to eq(2)endit "does not show participants button when event is standalone" dodiff --git a/plugins/discourse-rss-polling/spec/system/admin_spec.rb b/plugins/discourse-rss-polling/spec/system/admin_spec.rbindex 0d98c678ea4..a67ae16b08c 100644--- a/plugins/discourse-rss-polling/spec/system/admin_spec.rb+++ b/plugins/discourse-rss-polling/spec/system/admin_spec.rb@@ -29,14 +29,12 @@ RSpec.describe "Rss Polling - admin", type: :system dotag.select_row_by_value(tag_1.name)find(".save-rss-polling-feed").click- try_until_success do- expect(DiscourseRssPolling::RssFeed.last).to have_attributes(- url:,- author: current_user.username,- category_filter: "updates",- category_id: category_1.id,- tags: tag_1.name,- )- end+ expect(DiscourseRssPolling::RssFeed.last).to have_attributes(+ url:,+ author: current_user.username,+ category_filter: "updates",+ category_id: category_1.id,+ tags: tag_1.name,+ )endenddiff --git a/plugins/discourse-topic-voting/spec/system/voting_spec.rb b/plugins/discourse-topic-voting/spec/system/voting_spec.rbindex 106ee0f78c1..a8836bf7a81 100644--- a/plugins/discourse-topic-voting/spec/system/voting_spec.rb+++ b/plugins/discourse-topic-voting/spec/system/voting_spec.rb@@ -31,7 +31,7 @@ RSpec.describe "Topic voting", type: :system do.toggle_setting("enable-topic-voting", "Allow users to vote on topics in this category").save_settings- try_until_success { expect(Category.can_vote?(category1.id)).to eq(true) }+ expect(Category.can_vote?(category1.id)).to eq(true)# make a votecategory_page.visit(category1)diff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex 03bb26ac931..bb2b3234565 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -434,6 +434,7 @@ RSpec.configure do |config|def synchronize(seconds = nil, errors: nil)return super if session.synchronized # Nested synchronize. We only want our logic on the outermost call.+beginsuperrescue StandardError => e@@ -475,6 +476,81 @@ RSpec.configure do |config|endend+ module CapybaraPlaywrightBasePatch+ private++ def execute_async_client_settled_script(session)+ result = session.evaluate_async_script(<<~JS)+ const done = arguments[0];++ if (window.clientSettled) {+ window.clientSettled(#{Capybara.default_max_wait_time * 1000})+ .then(done)+ .catch((error) => { done(error.message) });+ } else {+ done();+ }+ JS++ raise result if result.is_a? String+ end++ def wait_for_client_settled(method_name)+ session = @driver.send(:session)++ if ENV["CAPYBARA_PLAYWRIGHT_DEBUG_CLIENT_SETTLED"].present?+ now = Time.now.to_f+ puts "[#{now}] #{method_name}: START"+ execute_async_client_settled_script(session)+ puts "[#{Time.now.to_f}] #{method_name}: END IN #{Time.now.to_f - now}"+ else+ execute_async_client_settled_script(session)+ end+ end+ end++ module CapybaraPlaywrightNodePatch+ include CapybaraPlaywrightBasePatch++ NODE_METHODS_TO_PATCH = %i[+ click+ right_click+ double_click+ send_keys+ hover+ drag_to+ scroll_by+ scroll_to+ trigger+ set+ ]++ NODE_METHODS_TO_PATCH.each do |method_name|+ define_method(method_name) do |*args, **options|+ result = super(*args, **options)+ wait_for_client_settled(method_name)+ result+ end+ end+ end++ module CapybaraPlaywrightBrowserPatch+ include CapybaraPlaywrightBasePatch++ METHODS_TO_PATCH = %i[visit go_back go_forward refresh resize_window_to]++ METHODS_TO_PATCH.each do |method_name|+ define_method(method_name) do |*args, **options|+ result = super(*args, **options)+ wait_for_client_settled(method_name)+ result+ end+ end+ end++ Capybara::Playwright::Node.prepend(CapybaraPlaywrightNodePatch)+ Capybara::Playwright::Browser.prepend(CapybaraPlaywrightBrowserPatch)+config.after(:each, type: :system) do |example|# If test passed, but we had a capybara finder timeout, raise it nowif example.exception.nil? &&diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rbindex 1d4cafc4f1a..9798ba6372c 100644--- a/spec/support/system_helpers.rb+++ b/spec/support/system_helpers.rb@@ -74,7 +74,7 @@ module SystemHelpers).join("|")end- def try_until_success(timeout: Capybara.default_max_wait_time, frequency: 0.01)+ def try_until_success(timeout: Capybara.default_max_wait_time, frequency: 0.01, reason: nil)start ||= Time.zone.nowbackoff ||= frequencyyielddiff --git a/spec/system/about_page_spec.rb b/spec/system/about_page_spec.rbindex fdc6dd0fceb..1f2fac82d57 100644--- a/spec/system/about_page_spec.rb+++ b/spec/system/about_page_spec.rb@@ -450,11 +450,12 @@ describe "About page", type: :system dosign_in(admin)about_page.visit+expect(about_page).to have_edit_linkabout_page.edit_link.click- try_until_success { expect(current_url).to end_with("/admin/config/about") }+ expect(current_url).to end_with("/admin/config/about")endit "doesn't appear for moderators" dodiff --git a/spec/system/admin_about_config_area_spec.rb b/spec/system/admin_about_config_area_spec.rbindex e6b023c0e18..6ac1fe06af9 100644--- a/spec/system/admin_about_config_area_spec.rb+++ b/spec/system/admin_about_config_area_spec.rb@@ -135,7 +135,7 @@ describe "Admin About Config Area Page", type: :system doconfig_area.general_settings_section.submitexpect(config_area.general_settings_section).to have_saved_successfully- try_until_success { expect(SiteSetting.about_banner_image).to eq(nil) }+ expect(SiteSetting.about_banner_image).to eq(nil)endit "can upload an image using keyboard nav" do@@ -149,7 +149,7 @@ describe "Admin About Config Area Page", type: :system doexpect(config_area.general_settings_section.banner_image_uploader).to have_uploaded_imageend- xit "can remove the uploaded image using keyboard nav" do+ it "can remove the uploaded image using keyboard nav" doSiteSetting.about_banner_image = image_uploadconfig_area.visit@@ -159,7 +159,7 @@ describe "Admin About Config Area Page", type: :system doconfig_area.general_settings_section.submitexpect(config_area.general_settings_section).to have_saved_successfully- try_until_success { expect(SiteSetting.about_banner_image).to eq(nil) }+ expect(SiteSetting.about_banner_image).to eq(nil)endcontext "when login_required is true" dodiff --git a/spec/system/admin_badges_grouping_modal_spec.rb b/spec/system/admin_badges_grouping_modal_spec.rbindex 89db88042b5..4d93127a026 100644--- a/spec/system/admin_badges_grouping_modal_spec.rb+++ b/spec/system/admin_badges_grouping_modal_spec.rb@@ -15,7 +15,7 @@ describe "Admin Badges Grouping Modal", type: :system dobadges_page.visit_page(Badge::Autobiographer).edit_groupingsbadges_groupings_page.add_grouping("a new grouping")- try_until_success { BadgeGrouping.exists?(name: "a new grouping") }+ BadgeGrouping.exists?(name: "a new grouping")endendenddiff --git a/spec/system/admin_badges_spec.rb b/spec/system/admin_badges_spec.rbindex f9449d88802..f911b721228 100644--- a/spec/system/admin_badges_spec.rb+++ b/spec/system/admin_badges_spec.rb@@ -64,10 +64,9 @@ describe "Admin Badges Page", type: :system doexpect(badges_page).to have_saved_formbadge = Badge.find(Badge::Autobiographer)- try_until_success do- expect(badge.image_upload_id).to be_present- expect(badge.icon).to be_blank- end++ expect(badge.image_upload_id).to be_present+ expect(badge.icon).to be_blankendit "can change to an icon for the badge" dodiff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rbindex d684dd726d4..726b91dd770 100644--- a/spec/system/admin_customize_themes_spec.rb+++ b/spec/system/admin_customize_themes_spec.rb@@ -87,11 +87,9 @@ describe "Admin Customize Themes", type: :system dofind(".ace_text-input", visible: false).fill_in(with: "console.log('test')\n")find(".save-theme").click- try_until_success do- expect(- theme.theme_fields.find_by(target_id: Theme.targets[:extra_js])&.value,- ).to start_with("console.log('test')\n")- end+ expect(theme.theme_fields.find_by(target_id: Theme.targets[:extra_js])&.value).to start_with(+ "console.log('test')\n",+ )# Check content is loaded from db correctlythemediff --git a/spec/system/admin_editing_objects_typed_theme_setting_spec.rb b/spec/system/admin_editing_objects_typed_theme_setting_spec.rbindex 56c36ffbd90..f8f71a4e2ae 100644--- a/spec/system/admin_editing_objects_typed_theme_setting_spec.rb+++ b/spec/system/admin_editing_objects_typed_theme_setting_spec.rb@@ -147,16 +147,14 @@ RSpec.describe "Admin editing objects type theme setting", type: :system dotheme_settings_editor.save- try_until_success do- expect(theme.reload.settings[:objects_setting].value).to eq(- [- {- "links" => [{ "name" => "new link", "url" => "https://example.com" }],- "name" => "new section",- },- ],- )- end+ expect(theme.reload.settings[:objects_setting].value).to eq(+ [+ {+ "links" => [{ "name" => "new link", "url" => "https://example.com" }],+ "name" => "new section",+ },+ ],+ )endendenddiff --git a/spec/system/admin_logo_spec.rb b/spec/system/admin_logo_spec.rbindex 15ff33832d7..8270665bfe8 100644--- a/spec/system/admin_logo_spec.rb+++ b/spec/system/admin_logo_spec.rb@@ -58,9 +58,7 @@ describe "Admin Logo Page", type: :system dologo_page.form.submit- try_until_success do- primary_section_logos.each { |image_type| expect(SiteSetting.send(image_type)).to eq(nil) }- end+ primary_section_logos.each { |image_type| expect(SiteSetting.send(image_type)).to eq(nil) }endenddiff --git a/spec/system/bookmarks_spec.rb b/spec/system/bookmarks_spec.rbindex 64221d70420..bb3a4b24afe 100644--- a/spec/system/bookmarks_spec.rb+++ b/spec/system/bookmarks_spec.rb@@ -33,9 +33,7 @@ describe "Bookmarking posts and topics", type: :system doexpect(bookmark_menu).to be_openexpect(page).to have_content(I18n.t("js.bookmarks.bookmarked_success"))expect(topic_page).to have_post_bookmarked(post, with_reminder: false)- try_until_success(frequency: 0.5) do- expect(Bookmark.find_by(bookmarkable: post, user: current_user)).to be_truthy- end+ expect(Bookmark.find_by(bookmarkable: post, user: current_user)).to be_truthyendit "updates the created bookmark with a selected reminder option from the bookmark menu" do@@ -48,9 +46,7 @@ describe "Bookmarking posts and topics", type: :system doexpect(topic_page).to have_post_bookmarked(post, with_reminder: true)expect(page).to have_no_css(".bookmark-menu-content.-expanded")- try_until_success(frequency: 0.5) do- expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blank- end+ expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blankendit "can set a reminder from the bookmark modal using the custom bookmark menu option" do@@ -58,9 +54,7 @@ describe "Bookmarking posts and topics", type: :system dobookmark_menu.click_menu_option("custom")bookmark_modal.select_preset_reminder(:tomorrow)expect(topic_page).to have_post_bookmarked(post, with_reminder: true)- try_until_success(frequency: 0.5) do- expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blank- end+ expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blankendit "allows choosing a different auto_delete_preference to the user preference and remembers it when reopening the modal" do@@ -107,9 +101,7 @@ describe "Bookmarking posts and topics", type: :system dobookmark_modal.fill_name("something important")bookmark_modal.click_primary_button- try_until_success(frequency: 0.5) do- expect(bookmark.reload.name).to eq("something important")- end+ expect(bookmark.reload.name).to eq("something important")endit "allows to set a relative time" dodiff --git a/spec/system/capabilities_service_spec.rb b/spec/system/capabilities_service_spec.rbindex 3f6c5544cc6..1e9b89cb23e 100644--- a/spec/system/capabilities_service_spec.rb+++ b/spec/system/capabilities_service_spec.rb@@ -14,10 +14,8 @@ describe "capabilities service", type: :system doexpect(matches("lg")).to eq(true)resize_window(width: 700) do- try_until_success do- expect(matches("sm")).to eq(true)- expect(matches("lg")).to eq(false)- end+ expect(matches("sm")).to eq(true)+ expect(matches("lg")).to eq(false)endendenddiff --git a/spec/system/category_localizations_spec.rb b/spec/system/category_localizations_spec.rbindex de952cf3818..5fba8af7096 100644--- a/spec/system/category_localizations_spec.rb+++ b/spec/system/category_localizations_spec.rb@@ -97,9 +97,7 @@ describe "Category Localizations", type: :system docategory_page.save_settingspage.refresh- try_until_success do- expect(CategoryLocalization.where(category_id: mono_category.id).count).to eq(2)- end+ expect(CategoryLocalization.where(category_id: mono_category.id).count).to eq(2)expect(CategoryLocalization.where(category_id: mono_category.id, locale: "es").count,).to eq(1)diff --git a/spec/system/composer/drafts_spec.rb b/spec/system/composer/drafts_spec.rbindex 1aa8e547147..70c60afa302 100644--- a/spec/system/composer/drafts_spec.rb+++ b/spec/system/composer/drafts_spec.rb@@ -21,7 +21,7 @@ describe "Composer - Drafts", type: :system docomposer.closeexpect(toasts).to have_success(I18n.t("js.composer.draft_saved"))- try_until_success { expect(Draft.where(user: current_user).count).to eq(1) }+ expect(Draft.where(user: current_user).count).to eq(1)endcontext "when only a title and category is specified" do@@ -37,8 +37,7 @@ describe "Composer - Drafts", type: :system docomposer.closeexpect(toasts).to have_success(I18n.t("js.composer.draft_saved"))-- try_until_success { expect(Draft.where(user: current_user).count).to eq(1) }+ expect(Draft.where(user: current_user).count).to eq(1)endend@@ -78,7 +77,9 @@ describe "Composer - Drafts", type: :system docomposer.fill_title("this is a test topic")composer.fill_content("a b c d e f g")- try_until_success { expect(Draft.where(user: current_user).count).to eq(1) }+ try_until_success(reason: "Relies on an Ember debounce to update the draft") do+ expect(Draft.where(user: current_user).count).to eq(1)+ endcomposer.discard@@ -87,8 +88,7 @@ describe "Composer - Drafts", type: :system doexpect(discard_draft_modal).to be_closedexpect(composer).to be_closed-- try_until_success { expect(Draft.where(user: current_user).count).to eq(0) }+ expect(Draft.where(user: current_user).count).to eq(0)endcontext "when only a title and category is specified" do@@ -108,8 +108,7 @@ describe "Composer - Drafts", type: :system doexpect(discard_draft_modal).to be_closedexpect(composer).to be_closed-- try_until_success { expect(Draft.where(user: current_user).count).to eq(1) }+ expect(Draft.where(user: current_user).count).to eq(1)endendenddiff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex 5f3cdf1eb14..f10431705c3 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -59,7 +59,7 @@ describe "Composer - ProseMirror editor", type: :system docomposer.toggle_rich_editorexpect(composer).to have_markdown_editor_active- try_until_success(frequency: 0.5) do+ try_until_success(reason: "Relies on an Ember timer to update the user option") doexpect(current_user.user_option.reload.composition_mode).to eq(UserOption.composition_mode_types[:markdown],)@@ -93,7 +93,7 @@ describe "Composer - ProseMirror editor", type: :system doexpect(composer).to have_rich_editor- try_until_success(frequency: 0.5) do+ try_until_success(reason: "Relies on an Ember timer to update the user option") doexpect(current_user.user_option.reload.composition_mode).to eq(UserOption.composition_mode_types[:rich],)diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rbindex cd79e2999bd..65927939f88 100644--- a/spec/system/content_localization_spec.rb+++ b/spec/system/content_localization_spec.rb@@ -98,18 +98,17 @@ describe "Content Localization" docomposer.set_locale("日本語")composer.fill_content("この小説は、名前のない猫の視点から明治時代の人間社会を風刺的に描いています。")composer.create- try_until_success do- new_post = Post.find_by(post_number: 4, topic_id: topic.id)- expect(new_post).to_not be_nil- # simulates a localization that would have been automatically created- Fabricate(- :post_localization,- post: new_post,- locale: "en",- cooked:- "This novel satirically depicts Meiji-era human society from the perspective of a nameless cat.",- )- end++ new_post = Post.find_by(post_number: 4, topic_id: topic.id)+ expect(new_post).to_not be_nil+ # simulates a localization that would have been automatically created+ Fabricate(+ :post_localization,+ post: new_post,+ locale: "en",+ cooked:+ "This novel satirically depicts Meiji-era human society from the perspective of a nameless cat.",+ )sign_in(site_local_user)diff --git a/spec/system/create_invite_spec.rb b/spec/system/create_invite_spec.rbindex 1aefc519616..610a886f06e 100644--- a/spec/system/create_invite_spec.rb+++ b/spec/system/create_invite_spec.rb@@ -74,7 +74,7 @@ describe "Creating Invites", type: :system docreate_invite_modal.save_button.clickcreate_invite_modal.close- try_until_success { expect(user_invited_pending_page.invites_list.size).to eq(2) }+ expect(user_invited_pending_page.invites_list.size).to eq(2)user_invited_pending_page.latest_invite.edit_button.clickenddiff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rbindex e41409da730..d3a2374e74f 100644--- a/spec/system/custom_sidebar_sections_spec.rb+++ b/spec/system/custom_sidebar_sections_spec.rb@@ -163,12 +163,10 @@ describe "Custom sidebar sections", type: :system dosidebar.click_add_section_buttonsidebar.click_add_link_button- try_until_success do- is_focused =- page.evaluate_script("document.activeElement.classList.contains('multi-select-header')")+ is_focused =+ page.evaluate_script("document.activeElement.classList.contains('multi-select-header')")- expect(is_focused).to be true- end+ expect(is_focused).to be trueendit "accessibility - when customization modal is closed, trigger is refocused" do@@ -180,11 +178,9 @@ describe "Custom sidebar sections", type: :system doexpect(section_modal).to be_closed- try_until_success do- is_focused = page.evaluate_script("document.activeElement.classList.contains('add-section')")+ is_focused = page.evaluate_script("document.activeElement.classList.contains('add-section')")- expect(is_focused).to be true- end+ expect(is_focused).to be trueendit "allows the user to edit custom section" dodiff --git a/spec/system/edit_category_form_templates_spec.rb b/spec/system/edit_category_form_templates_spec.rbindex c38b39575be..55a2b9df6af 100644--- a/spec/system/edit_category_form_templates_spec.rb+++ b/spec/system/edit_category_form_templates_spec.rb@@ -32,9 +32,8 @@ describe "Edit Category Form Templates", type: :system docategory_page.select_form_template(form_template.name)expect(category_page).to have_selected_template(form_template.name)category_page.save_settings- try_until_success do- expect(Category.find_by_id(category.id).form_template_ids).to eq([form_template.id])- end++ expect(Category.find_by_id(category.id).form_template_ids).to eq([form_template.id])endit "should allow you to select and save multiple form templates" do@@ -43,11 +42,10 @@ describe "Edit Category Form Templates", type: :system docategory_page.select_form_template(form_template.name)category_page.select_form_template(form_template_2.name)category_page.save_settings- try_until_success do- expect(Category.find_by_id(category.id).form_template_ids).to eq(- [form_template.id, form_template_2.id],- )- end++ expect(Category.find_by_id(category.id).form_template_ids).to eq(+ [form_template.id, form_template_2.id],+ )endenddiff --git a/spec/system/email_change_spec.rb b/spec/system/email_change_spec.rbindex f37e713e14e..ece53411510 100644--- a/spec/system/email_change_spec.rb+++ b/spec/system/email_change_spec.rb@@ -48,9 +48,7 @@ describe "Changing email", type: :system doexpect(page).to have_css(".dialog-body", text: I18n.t("js.user.change_email.confirm_success"))find(".dialog-footer .btn-primary").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ expect(user.reload.primary_email.email).to eq(new_email)endit "works when user has totp 2fa", dump_threads_on_failure: true do@@ -65,9 +63,7 @@ describe "Changing email", type: :system dofind(".second-factor-token-input").fill_in with: second_factor.totp_object.nowfind("button[type=submit]").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ expect(user.reload.primary_email.email).to eq(new_email)endit "works when user has webauthn 2fa" do@@ -78,9 +74,9 @@ describe "Changing email", type: :system dofind(".confirm-new-email .btn-primary").clickfind("#security-key-authenticate-button").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ try_until_success(+ reason: "Something about webauthn.js that we can't seem to track properly",+ ) { expect(user.reload.primary_email.email).to eq(new_email) }endend@@ -98,9 +94,7 @@ describe "Changing email", type: :system dofind(".second-factor-token-input").fill_in with: second_factor.totp_object.nowfind("button[type=submit]:not([disabled])").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ expect(user.reload.primary_email.email).to eq(new_email)endit "makes admins verify old email" do@@ -132,9 +126,7 @@ describe "Changing email", type: :system doexpect(page).to have_css(".dialog-body", text: I18n.t("js.user.change_email.confirm_success"))find(".dialog-footer .btn-primary").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ expect(user.reload.primary_email.email).to eq(new_email)endit "allows admin to verify old email while logged out" do@@ -168,8 +160,6 @@ describe "Changing email", type: :system doexpect(page).to have_css(".dialog-body", text: I18n.t("js.user.change_email.confirm_success"))find(".dialog-footer .btn-primary").click- try_until_success(timeout: Capybara.default_max_wait_time * 2) do- expect(user.reload.primary_email.email).to eq(new_email)- end+ expect(user.reload.primary_email.email).to eq(new_email)endenddiff --git a/spec/system/header_spec.rb b/spec/system/header_spec.rbindex 65cd36c1608..d70e31c5d8c 100644--- a/spec/system/header_spec.rb+++ b/spec/system/header_spec.rb@@ -288,7 +288,9 @@ RSpec.describe "Glimmer Header", type: :system docurrent_user.publish_do_not_disturb(ends_at: 1.hour.from_now)- try_until_success { expect(page).to have_css(".d-header .do-not-disturb-background") }+ try_until_success(reason: "Relies on messagebus updates") do+ expect(page).to have_css(".d-header .do-not-disturb-background")+ endcurrent_user.publish_do_not_disturb(ends_at: 1.second.from_now)diff --git a/spec/system/new_category_spec.rb b/spec/system/new_category_spec.rbindex b2a3e0a2e5b..9674c3860da 100644--- a/spec/system/new_category_spec.rb+++ b/spec/system/new_category_spec.rb@@ -13,13 +13,12 @@ describe "New Category", type: :system dowith: "New Category",)- category_page.find(".edit-category-nav .edit-category-tags a").click- category_page.find(".edit-category-tab-tags #category-minimum-tags").clickcategory_page.save_settingsexpect(page).to have_current_path("/c/new-category/edit/general")- category_page.find(".edit-category-nav .edit-category-tags a").click- expect(category_page.find(".edit-category-tab-tags #category-minimum-tags").value).to eq("0")+ category = Category.find_by(name: "New Category")++ expect(category.minimum_required_tags).to eq(0)endenddiff --git a/spec/system/page_objects/cdp.rb b/spec/system/page_objects/cdp.rbindex cb895ef40fa..b8108eaa463 100644--- a/spec/system/page_objects/cdp.rb+++ b/spec/system/page_objects/cdp.rb@@ -51,10 +51,8 @@ module PageObjectsenddef clipboard_has_text?(text, chomp: false, strict: true)- try_until_success do- clipboard_text = chomp ? read_clipboard.chomp : read_clipboard- expect(clipboard_text).to strict ? eq(text) : include(text)- end+ clipboard_text = chomp ? read_clipboard.chomp : read_clipboard+ expect(clipboard_text).to strict ? eq(text) : include(text)enddef copy_paste(text, html: false, css_selector: nil)diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rbindex 23f195598ab..d22a166eee0 100644--- a/spec/system/page_objects/components/composer.rb+++ b/spec/system/page_objects/components/composer.rb@@ -97,7 +97,7 @@ module PageObjectsenddef has_value?(value)- try_until_success { expect(composer_input.value).to eq(value) }+ expect(composer_input.value).to eq(value)enddef has_popup_content?(content)diff --git a/spec/system/page_objects/pages/admin_email_templates.rb b/spec/system/page_objects/pages/admin_email_templates.rbindex 7f348ead0fd..e5015159bab 100644--- a/spec/system/page_objects/pages/admin_email_templates.rb+++ b/spec/system/page_objects/pages/admin_email_templates.rb@@ -28,7 +28,7 @@ module PageObjectsenddef has_subject_value?(value)- try_until_success { expect(find("input.email-template__subject").value).to eq(value) }+ expect(find("input.email-template__subject").value).to eq(value)enddef edit_body(text)diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rbindex d510a827b24..12d49164c71 100644--- a/spec/system/post_menu_spec.rb+++ b/spec/system/post_menu_spec.rb@@ -441,7 +441,7 @@ describe "Post menu", type: :system dotopic_page.click_post_action_button(unliked_post, :like)# we need this because the find_post_action_button will target the like button on or off- try_until_success do+ try_until_success(reason: "Relies on Ember debounce") dolike_button = topic_page.find_post_action_button(unliked_post, :like)expect(like_button[:class].split("\s")).to include("has-like")end@@ -453,7 +453,7 @@ describe "Post menu", type: :system dotopic_page.click_post_action_button(unliked_post, :like)# we need this because the find_post_action_button will target the like button on or off- try_until_success do+ try_until_success(reason: "Relies on Ember debounce") dolike_button = topic_page.find_post_action_button(unliked_post, :like)expect(like_button[:class].split("\s")).to include("like")enddiff --git a/spec/system/post_translation_spec.rb b/spec/system/post_translation_spec.rbindex 249ea86250d..b01b4da1252 100644--- a/spec/system/post_translation_spec.rb+++ b/spec/system/post_translation_spec.rb@@ -50,19 +50,13 @@ describe "Post translations", type: :system dofind("#translated-topic-title").fill_in(with: "Ceci est un sujet de test 0")composer.fill_content("Bonjour le monde")composer.submit- post.reload- topic.reload-- try_until_success do- expect(TopicLocalization.exists?(topic_id: topic.id, locale: "fr")).to be true- expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be true- expect(PostLocalization.find_by(post_id: post.id, locale: "fr").raw).to eq(- "Bonjour le monde",- )- expect(TopicLocalization.find_by(topic_id: topic.id, locale: "fr").title).to eq(- "Ceci est un sujet de test 0",- )- end++ expect(TopicLocalization.exists?(topic_id: topic.id, locale: "fr")).to be true+ expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be true+ expect(PostLocalization.find_by(post_id: post.id, locale: "fr").raw).to eq("Bonjour le monde")+ expect(TopicLocalization.find_by(topic_id: topic.id, locale: "fr").title).to eq(+ "Ceci est un sujet de test 0",+ )endend@@ -82,17 +76,13 @@ describe "Post translations", type: :system dofind("#translated-topic-title").fill_in(with: "Este es un tema de prueba 0")composer.fill_content("Hola mundo")composer.submit- post.reload- topic.reload-- try_until_success do- expect(TopicLocalization.exists?(topic_id: topic.id, locale: "es")).to be true- expect(PostLocalization.exists?(post_id: post.id, locale: "es")).to be true- expect(PostLocalization.find_by(post_id: post.id, locale: "es").raw).to eq("Hola mundo")- expect(TopicLocalization.find_by(topic_id: topic.id, locale: "es").title).to eq(- "Este es un tema de prueba 0",- )- end++ expect(TopicLocalization.exists?(topic_id: topic.id, locale: "es")).to be true+ expect(PostLocalization.exists?(post_id: post.id, locale: "es")).to be true+ expect(PostLocalization.find_by(post_id: post.id, locale: "es").raw).to eq("Hola mundo")+ expect(TopicLocalization.find_by(topic_id: topic.id, locale: "es").title).to eq(+ "Este es un tema de prueba 0",+ )endit "allows a user to see locales translated" do@@ -119,19 +109,13 @@ describe "Post translations", type: :system dofind("#translated-topic-title").fill_in(with: "C'est un sujet de test 0.")composer.fill_content("Bonjour le monde")composer.submit- post.reload- topic.reload-- try_until_success do- expect(TopicLocalization.exists?(topic_id: topic.id, locale: "fr")).to be true- expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be true- expect(PostLocalization.find_by(post_id: post.id, locale: "fr").raw).to eq(- "Bonjour le monde",- )- expect(TopicLocalization.find_by(topic_id: topic.id, locale: "fr").title).to eq(- "C'est un sujet de test 0.",- )- end++ expect(TopicLocalization.exists?(topic_id: topic.id, locale: "fr")).to be true+ expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be true+ expect(PostLocalization.find_by(post_id: post.id, locale: "fr").raw).to eq("Bonjour le monde")+ expect(TopicLocalization.find_by(topic_id: topic.id, locale: "fr").title).to eq(+ "C'est un sujet de test 0.",+ )endit "allows a user in content_localization_allowed_groups to delete a translation" do@@ -144,12 +128,7 @@ describe "Post translations", type: :system doexpect(confirmation_dialog).to be_openconfirmation_dialog.click_yes- post.reload- topic.reload-- try_until_success do- expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be false- end+ expect(PostLocalization.exists?(post_id: post.id, locale: "fr")).to be falseendend@@ -176,10 +155,8 @@ describe "Post translations", type: :system docomposer.fill_content("Bonjour le monde")composer.submit- try_until_success do- updated_post = Topic.last.posts.first- expect(updated_post.locale).to eq("fr")- end+ updated_post = Topic.last.posts.first+ expect(updated_post.locale).to eq("fr")endit "should not have a locale set by default" dodiff --git a/spec/system/s3_secure_uploads_spec.rb b/spec/system/s3_secure_uploads_spec.rbindex dc2e0233d41..83464e9c674 100644--- a/spec/system/s3_secure_uploads_spec.rb+++ b/spec/system/s3_secure_uploads_spec.rb@@ -19,10 +19,8 @@ describe "Uploading files in the composer to S3", type: :system doimg = first_post_imgexpect(img["src"]).to include("/secure-uploads")- try_until_success do- topic = topic_page.current_topic- expect(topic.first_post.uploads.first.secure).to eq(true)- end+ topic = topic_page.current_topic+ expect(topic.first_post.uploads.first.secure).to eq(true)endit "marks uploads inside of private message posts as secure" dodiff --git a/spec/system/scroll_manager_service_spec.rb b/spec/system/scroll_manager_service_spec.rbindex 76442b69cce..2a5996e9416 100644--- a/spec/system/scroll_manager_service_spec.rb+++ b/spec/system/scroll_manager_service_spec.rb@@ -22,23 +22,21 @@ describe "Ember route-scroll-manager service", type: :system doJStopic_list_scroll_y = current_scroll_y- try_until_success { expect(topic_list_scroll_y).to be > 0 }+ expect(topic_list_scroll_y).to be > 0find(".sidebar-section-link[data-link-name='all-categories']").clickexpect(page).to have_css("body.navigation-categories")-- try_until_success { expect(current_scroll_y).to eq(0) }+ expect(current_scroll_y).to eq(0)page.go_backexpect(page).to have_css("body.navigation-topics")expect(discovery.topic_list).to have_topics-- try_until_success { expect(current_scroll_y).to eq(topic_list_scroll_y) }+ expect(current_scroll_y).to eq(topic_list_scroll_y)# Clicking site logo triggers refresh and scrolls to topclick_logo- try_until_success { expect(current_scroll_y).to eq(0) }+ expect(current_scroll_y).to eq(0)endenddiff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rbindex 01983896420..09b24c389db 100644--- a/spec/system/search_spec.rb+++ b/spec/system/search_spec.rb@@ -143,8 +143,8 @@ describe "Search", type: :system doexpect(search_page).to have_topic_title_for_first_search_result(topic.title)find(".search-menu-container .search-result-topic", text: topic.title).click- try_until_success { expect(SearchLog.count).to eq(1) }- try_until_success { expect(SearchLog.last.search_result_id).not_to eq(nil) }+ expect(SearchLog.count).to eq(1)+ expect(SearchLog.last.search_result_id).not_to eq(nil)log = SearchLog.lastexpect(log.term).to eq("test")diff --git a/spec/system/table_builder_spec.rb b/spec/system/table_builder_spec.rbindex a39871f7542..9d6de82120a 100644--- a/spec/system/table_builder_spec.rb+++ b/spec/system/table_builder_spec.rb@@ -55,11 +55,9 @@ describe "Table Builder", type: :system do| | | | |TABLE- try_until_success do- expect(normalize_value(composer.composer_input.value)).to eq(- normalize_value(created_table),- )- end+ expect(normalize_value(composer.composer_input.value)).to eq(+ normalize_value(created_table),+ )endcontext "when cancelling table creation" do@@ -118,9 +116,7 @@ describe "Table Builder", type: :system do|Honda | S2000 | 2001|RAW- try_until_success do- expect(normalize_value(post1.reload.raw)).to eq(normalize_value(updated_post))- end+ expect(normalize_value(post1.reload.raw)).to eq(normalize_value(updated_post))endit "should respect the original empty header" do@@ -137,9 +133,7 @@ describe "Table Builder", type: :system do|1 | 2 | 3|RAW- try_until_success do- expect(normalize_value(post2.reload.raw)).to eq(normalize_value(updated_post))- end+ expect(normalize_value(post2.reload.raw)).to eq(normalize_value(updated_post))endcontext "when adding an edit reason" dodiff --git a/spec/system/topic_page_spec.rb b/spec/system/topic_page_spec.rbindex 4c7b1ef7d4c..b61db7619bc 100644--- a/spec/system/topic_page_spec.rb+++ b/spec/system/topic_page_spec.rb@@ -17,9 +17,7 @@ describe "Topic page", type: :system dofind("#toc-h2-testing .anchor", visible: :all).click- try_until_success do- expect(current_url).to match("/t/#{topic.slug}/#{topic.id}#toc-h2-testing")- end+ expect(current_url).to match("/t/#{topic.slug}/#{topic.id}#toc-h2-testing")endcontext "with a subfolder setup" do@@ -30,9 +28,7 @@ describe "Topic page", type: :system dofind("#toc-h2-testing .anchor", visible: :all).click- try_until_success do- expect(current_url).to match("/forum/t/#{topic.slug}/#{topic.id}#toc-h2-testing")- end+ expect(current_url).to match("/forum/t/#{topic.slug}/#{topic.id}#toc-h2-testing")endenddiff --git a/spec/system/user_page/user_preferences_interface_spec.rb b/spec/system/user_page/user_preferences_interface_spec.rbindex 0411548472b..72b509c944b 100644--- a/spec/system/user_page/user_preferences_interface_spec.rb+++ b/spec/system/user_page/user_preferences_interface_spec.rb@@ -20,15 +20,12 @@ describe "User preferences | Interface", type: :system dodropdown.select_row_by_value(Bookmark.auto_delete_preferences[:when_reminder_sent])click_button(I18n.t("js.save"))- # the preference page reloads after saving, so we need to poll the db- try_until_success(timeout: 20) do- expect(- UserOption.exists?(- user_id: user.id,- bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:when_reminder_sent],- ),- ).to be_truthy- end+ expect(+ UserOption.exists?(+ user_id: user.id,+ bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:when_reminder_sent],+ ),+ ).to be_truthyendenddiff --git a/spec/system/viewing_sidebar_spec.rb b/spec/system/viewing_sidebar_spec.rbindex e87b5b8b321..65bdf943042 100644--- a/spec/system/viewing_sidebar_spec.rb+++ b/spec/system/viewing_sidebar_spec.rb@@ -221,7 +221,10 @@ describe "Viewing sidebar", type: :system douser_private_messages_page.visit(admin)user_private_messages_page.click_unseen_private_mesage(private_message.id)expect(sidebar).to have_my_messages_link_with_unread_icon- try_until_success { expect(sidebar).to have_my_messages_link_without_unread_icon }++ try_until_success(reason: "Liking relying on messagebus updates") do+ expect(sidebar).to have_my_messages_link_without_unread_icon+ endendendend