0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/plugins/chat/spec/system/page_objects/pages/chat_search.rb
Jarek Radosz 4168942494
DEV: Fix a chat search spec flake (#40068)
The loading spinner could disappear before
`has_selector?(".chat-search-loading .spinner")` assertion, which
resulted in awaiting for the full timeout duration.

`scroll_to_bottom` is only used in one place and the assertion after it
will wait for the correct state anyway.
2026-05-15 14:06:56 +02:00

68 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Pages
class ChatSearch < PageObjects::Pages::Base
SELECTOR = ".c-routes.--search"
def visit
page.visit("/chat/search")
self
end
def fill_in(query)
page_locator.locator(".filter-input").fill(query)
# Wait for search to complete - either results or no results message
page_locator.locator(".chat-message-search-entries, .alert.alert-info").wait_for(
state: "visible",
)
self
end
def has_x_results?(count)
has_selector?(".chat-message-container", count:)
end
def has_results?(*messages)
messages.each do |message|
expect(
page_locator.locator(".chat-message-container[data-id=\"#{message.id}\"]"),
).to be_visible
end
end
def has_no_results?
expect(page_locator.locator(".alert.alert-info")).to be_visible
end
def clear
page_locator.locator(".filter-input-clear-btn").click
self
end
def has_zero_results?
has_no_selector?(".chat-message-container")
end
def click_result(message)
page_locator.locator(
".chat-message-search-entry:has(.chat-message-container[data-id=\"#{message.id}\"])",
).click
self
end
def scroll_to_bottom
page.execute_script("window.scrollTo(0, document.body.scrollHeight)")
self
end
private
def page_locator
locator(SELECTOR)
end
end
end
end