Skip to content

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.js
new file mode 100644
index 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.rb
index 432ccbcda8a..cde43666efb 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -832,6 +832,10 @@ module ApplicationHelper
setup_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_mode
end
diff --git a/bin/rspec b/bin/rspec
index fc4af083fb6..6cb4281c6e1 100755
--- a/bin/rspec
+++ b/bin/rspec
@@ -20,5 +20,6 @@ if ENV["LOAD_PLUGINS"].nil? && ARGV.any? { |pattern| pattern.include?("plugins/"
end
ENV["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.rb
index 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 do
expect(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)
end
end
diff --git a/plugins/chat/spec/system/chat_message_interaction_spec.rb b/plugins/chat/spec/system/chat_message_interaction_spec.rb
index 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 do
DiscourseEvent.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") do
expect(action_id).to_not be_nil
expect(chat_channel_page.messages).to have_text(action_id)
end
diff --git a/plugins/chat/spec/system/chat_new_message_spec.rb b/plugins/chat/spec/system/chat_new_message_spec.rb
index 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 do
chat_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.rb
index 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.rb
index 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 do
drawer_page.visit_index
drawer_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)
end
context "with unread threads" do
diff --git a/plugins/chat/spec/system/message_thread_indicator_spec.rb b/plugins/chat/spec/system/message_thread_indicator_spec.rb
index 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 do
expect(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.thread
expect(page).not_to have_css(channel_page.message_by_id_selector(new_thread.replies.first))
end
diff --git a/plugins/chat/spec/system/send_message_spec.rb b/plugins/chat/spec/system/send_message_spec.rb
index 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 do
drawer_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)
ensure
DiscourseEvent.off(:chat_message_created, &blk)
end
diff --git a/plugins/chat/spec/system/update_last_read_spec.rb b/plugins/chat/spec/system/update_last_read_spec.rb
index 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 do
last_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) }
end
end
@@ -32,7 +34,9 @@ RSpec.describe "Update last read", type: :system do
last_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) }
end
end
@@ -43,7 +47,9 @@ RSpec.describe "Update last read", type: :system do
last_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) }
end
end
end
diff --git a/plugins/chat/spec/system/uploads_spec.rb b/plugins/chat/spec/system/uploads_spec.rb
index 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 do
message = Chat::Message.last
- try_until_success(timeout: 5) { expect(message.uploads.first.thumbnail).to be_present }
+ expect(message.uploads.first.thumbnail).to be_present
upload = message.uploads.first
@@ -169,7 +169,7 @@ describe "Uploading files in chat messages", type: :system do
expect(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_empty
end
it "allows adding more uploads" do
@@ -184,8 +184,7 @@ describe "Uploading files in chat messages", type: :system do
expect(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)
end
end
diff --git a/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_persona_spec.rb
index 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 do
form.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 do
form.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 do
form.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)
end
diff --git a/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/homepage_spec.rb
index 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}']")
end
end
diff --git a/plugins/discourse-ai/spec/system/ai_bot/share_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/share_spec.rb
index 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 do
find("#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 do
find("#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 do
find(".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.rb
index 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 do
toggle = 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").click
diff --git a/plugins/discourse-assign/spec/system/assign_topic_spec.rb b/plugins/discourse-assign/spec/system/assign_topic_spec.rb
index 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 do
I18n.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") do
expect(find("#topic .assigned-to")).to have_content(admin2.username)
end
end
diff --git a/plugins/discourse-calendar/spec/system/post_event_spec.rb b/plugins/discourse-calendar/spec/system/post_event_spec.rb
index 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 do
expect(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" do
visit "/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 do
find(".d-modal .add-invitee").click
topic_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)
end
it "does not show participants button when event is standalone" do
diff --git a/plugins/discourse-rss-polling/spec/system/admin_spec.rb b/plugins/discourse-rss-polling/spec/system/admin_spec.rb
index 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 do
tag.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,
+ )
end
end
diff --git a/plugins/discourse-topic-voting/spec/system/voting_spec.rb b/plugins/discourse-topic-voting/spec/system/voting_spec.rb
index 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 vote
category_page.visit(category1)
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 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.
+
begin
super
rescue StandardError => e
@@ -475,6 +476,81 @@ RSpec.configure do |config|
end
end
+ 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 now
if example.exception.nil? &&
diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb
index 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.now
backoff ||= frequency
yield
diff --git a/spec/system/about_page_spec.rb b/spec/system/about_page_spec.rb
index 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 do
sign_in(admin)
about_page.visit
+
expect(about_page).to have_edit_link
about_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")
end
it "doesn't appear for moderators" do
diff --git a/spec/system/admin_about_config_area_spec.rb b/spec/system/admin_about_config_area_spec.rb
index 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 do
config_area.general_settings_section.submit
expect(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)
end
it "can upload an image using keyboard nav" do
@@ -149,7 +149,7 @@ describe "Admin About Config Area Page", type: :system do
expect(config_area.general_settings_section.banner_image_uploader).to have_uploaded_image
end
- xit "can remove the uploaded image using keyboard nav" do
+ it "can remove the uploaded image using keyboard nav" do
SiteSetting.about_banner_image = image_upload
config_area.visit
@@ -159,7 +159,7 @@ describe "Admin About Config Area Page", type: :system do
config_area.general_settings_section.submit
expect(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)
end
context "when login_required is true" do
diff --git a/spec/system/admin_badges_grouping_modal_spec.rb b/spec/system/admin_badges_grouping_modal_spec.rb
index 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 do
badges_page.visit_page(Badge::Autobiographer).edit_groupings
badges_groupings_page.add_grouping("a new grouping")
- try_until_success { BadgeGrouping.exists?(name: "a new grouping") }
+ BadgeGrouping.exists?(name: "a new grouping")
end
end
end
diff --git a/spec/system/admin_badges_spec.rb b/spec/system/admin_badges_spec.rb
index 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 do
expect(badges_page).to have_saved_form
badge = 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_blank
end
it "can change to an icon for the badge" do
diff --git a/spec/system/admin_customize_themes_spec.rb b/spec/system/admin_customize_themes_spec.rb
index 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 do
find(".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 correctly
theme
diff --git a/spec/system/admin_editing_objects_typed_theme_setting_spec.rb b/spec/system/admin_editing_objects_typed_theme_setting_spec.rb
index 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 do
theme_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",
+ },
+ ],
+ )
end
end
end
diff --git a/spec/system/admin_logo_spec.rb b/spec/system/admin_logo_spec.rb
index 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 do
logo_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) }
end
end
diff --git a/spec/system/bookmarks_spec.rb b/spec/system/bookmarks_spec.rb
index 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 do
expect(bookmark_menu).to be_open
expect(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_truthy
end
it "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 do
expect(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_blank
end
it "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 do
bookmark_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_blank
end
it "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 do
bookmark_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")
end
it "allows to set a relative time" do
diff --git a/spec/system/capabilities_service_spec.rb b/spec/system/capabilities_service_spec.rb
index 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 do
expect(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)
end
end
end
diff --git a/spec/system/category_localizations_spec.rb b/spec/system/category_localizations_spec.rb
index 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 do
category_page.save_settings
page.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.rb
index 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 do
composer.close
expect(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)
end
context "when only a title and category is specified" do
@@ -37,8 +37,7 @@ describe "Composer - Drafts", type: :system do
composer.close
expect(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)
end
end
@@ -78,7 +77,9 @@ describe "Composer - Drafts", type: :system do
composer.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)
+ end
composer.discard
@@ -87,8 +88,7 @@ describe "Composer - Drafts", type: :system do
expect(discard_draft_modal).to be_closed
expect(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)
end
context "when only a title and category is specified" do
@@ -108,8 +108,7 @@ describe "Composer - Drafts", type: :system do
expect(discard_draft_modal).to be_closed
expect(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)
end
end
end
diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rb
index 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 do
composer.toggle_rich_editor
expect(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") do
expect(current_user.user_option.reload.composition_mode).to eq(
UserOption.composition_mode_types[:markdown],
)
@@ -93,7 +93,7 @@ describe "Composer - ProseMirror editor", type: :system do
expect(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") do
expect(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.rb
index cd79e2999bd..65927939f88 100644
--- a/spec/system/content_localization_spec.rb
+++ b/spec/system/content_localization_spec.rb
@@ -98,18 +98,17 @@ describe "Content Localization" do
composer.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.rb
index 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 do
create_invite_modal.save_button.click
create_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.click
end
diff --git a/spec/system/custom_sidebar_sections_spec.rb b/spec/system/custom_sidebar_sections_spec.rb
index 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 do
sidebar.click_add_section_button
sidebar.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 true
end
it "accessibility - when customization modal is closed, trigger is refocused" do
@@ -180,11 +178,9 @@ describe "Custom sidebar sections", type: :system do
expect(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 true
end
it "allows the user to edit custom section" do
diff --git a/spec/system/edit_category_form_templates_spec.rb b/spec/system/edit_category_form_templates_spec.rb
index 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 do
category_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])
end
it "should allow you to select and save multiple form templates" do
@@ -43,11 +42,10 @@ describe "Edit Category Form Templates", type: :system do
category_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],
+ )
end
end
diff --git a/spec/system/email_change_spec.rb b/spec/system/email_change_spec.rb
index 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 do
expect(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)
end
it "works when user has totp 2fa", dump_threads_on_failure: true do
@@ -65,9 +63,7 @@ describe "Changing email", type: :system do
find(".second-factor-token-input").fill_in with: second_factor.totp_object.now
find("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)
end
it "works when user has webauthn 2fa" do
@@ -78,9 +74,9 @@ describe "Changing email", type: :system do
find(".confirm-new-email .btn-primary").click
find("#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) }
end
end
@@ -98,9 +94,7 @@ describe "Changing email", type: :system do
find(".second-factor-token-input").fill_in with: second_factor.totp_object.now
find("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)
end
it "makes admins verify old email" do
@@ -132,9 +126,7 @@ describe "Changing email", type: :system do
expect(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)
end
it "allows admin to verify old email while logged out" do
@@ -168,8 +160,6 @@ describe "Changing email", type: :system do
expect(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)
end
end
diff --git a/spec/system/header_spec.rb b/spec/system/header_spec.rb
index 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 do
current_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")
+ end
current_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.rb
index 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 do
with: "New Category",
)
- category_page.find(".edit-category-nav .edit-category-tags a").click
- category_page.find(".edit-category-tab-tags #category-minimum-tags").click
category_page.save_settings
expect(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)
end
end
diff --git a/spec/system/page_objects/cdp.rb b/spec/system/page_objects/cdp.rb
index cb895ef40fa..b8108eaa463 100644
--- a/spec/system/page_objects/cdp.rb
+++ b/spec/system/page_objects/cdp.rb
@@ -51,10 +51,8 @@ module PageObjects
end
def 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)
end
def 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.rb
index 23f195598ab..d22a166eee0 100644
--- a/spec/system/page_objects/components/composer.rb
+++ b/spec/system/page_objects/components/composer.rb
@@ -97,7 +97,7 @@ module PageObjects
end
def has_value?(value)
- try_until_success { expect(composer_input.value).to eq(value) }
+ expect(composer_input.value).to eq(value)
end
def 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.rb
index 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 PageObjects
end
def 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)
end
def edit_body(text)
diff --git a/spec/system/post_menu_spec.rb b/spec/system/post_menu_spec.rb
index 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 do
topic_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") do
like_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 do
topic_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") do
like_button = topic_page.find_post_action_button(unliked_post, :like)
expect(like_button[:class].split("\s")).to include("like")
end
diff --git a/spec/system/post_translation_spec.rb b/spec/system/post_translation_spec.rb
index 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 do
find("#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",
+ )
end
end
@@ -82,17 +76,13 @@ describe "Post translations", type: :system do
find("#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",
+ )
end
it "allows a user to see locales translated" do
@@ -119,19 +109,13 @@ describe "Post translations", type: :system do
find("#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.",
+ )
end
it "allows a user in content_localization_allowed_groups to delete a translation" do
@@ -144,12 +128,7 @@ describe "Post translations", type: :system do
expect(confirmation_dialog).to be_open
confirmation_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 false
end
end
@@ -176,10 +155,8 @@ describe "Post translations", type: :system do
composer.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")
end
it "should not have a locale set by default" do
diff --git a/spec/system/s3_secure_uploads_spec.rb b/spec/system/s3_secure_uploads_spec.rb
index 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 do
img = first_post_img
expect(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)
end
it "marks uploads inside of private message posts as secure" do
diff --git a/spec/system/scroll_manager_service_spec.rb b/spec/system/scroll_manager_service_spec.rb
index 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 do
JS
topic_list_scroll_y = current_scroll_y
- try_until_success { expect(topic_list_scroll_y).to be > 0 }
+ expect(topic_list_scroll_y).to be > 0
find(".sidebar-section-link[data-link-name='all-categories']").click
expect(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_back
expect(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 top
click_logo
- try_until_success { expect(current_scroll_y).to eq(0) }
+ expect(current_scroll_y).to eq(0)
end
end
diff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rb
index 01983896420..09b24c389db 100644
--- a/spec/system/search_spec.rb
+++ b/spec/system/search_spec.rb
@@ -143,8 +143,8 @@ describe "Search", type: :system do
expect(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.last
expect(log.term).to eq("test")
diff --git a/spec/system/table_builder_spec.rb b/spec/system/table_builder_spec.rb
index 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),
+ )
end
context "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))
end
it "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))
end
context "when adding an edit reason" do
diff --git a/spec/system/topic_page_spec.rb b/spec/system/topic_page_spec.rb
index 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 do
find("#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")
end
context "with a subfolder setup" do
@@ -30,9 +28,7 @@ describe "Topic page", type: :system do
find("#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")
end
end
diff --git a/spec/system/user_page/user_preferences_interface_spec.rb b/spec/system/user_page/user_preferences_interface_spec.rb
index 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 do
dropdown.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_truthy
end
end
diff --git a/spec/system/viewing_sidebar_spec.rb b/spec/system/viewing_sidebar_spec.rb
index 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 do
user_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
+ end
end
end
end