mirror of
https://github.com/discourse/discourse.git
synced 2026-03-05 15:27:34 +08:00
This change seeks to improve the reliability of our system tests by resolving the lack of consistency in the state of the client side application between steps in a system test. This is achieved by patching various action methods in `Capybara::Playwright::Node` and `Capybara::Playwright::Browser` so that the methods execute an async JavaScript function on the client side that waits for the client side application to reach a settled state. A settled state is currently defined as: 1. No inflight ajax requests. (_messageBus and presence requests are excluded_) 2. 2 event cycles of the Javascript event loop has happened for for all "click", "input", "mousedown", "keydown", "focusin", "focusout", "touchstart", "change", "resize", "scroll" DOM events that fired. For debugging purposes, a `--debug-client-settled` CLI flag has been added to `bin/rspec`. When used, detailed debugging information will be printed to the browser's console as well as to `stdout` of the `bin/rspec` process. This change was inspired by https://evilmartians.com/chronicles/flaky-tests-be-gone-long-lasting-relief-chronic-ci-retry-irritation and the https://github.com/makandra/capybara-lockstep rubygem.
42 lines
1.2 KiB
Ruby
42 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Ember route-scroll-manager service", type: :system do
|
|
before do
|
|
Fabricate(:admin)
|
|
Fabricate.times(50, :post)
|
|
end
|
|
|
|
let(:discovery) { PageObjects::Pages::Discovery.new }
|
|
|
|
def current_scroll_y
|
|
page.evaluate_script("window.scrollY")
|
|
end
|
|
|
|
it "scrolls to top when navigating to new routes, and remembers scroll position when going back" do
|
|
visit("/")
|
|
expect(page).to have_css("body.navigation-topics")
|
|
expect(discovery.topic_list).to have_topics
|
|
|
|
page.execute_script <<~JS
|
|
document.querySelectorAll('.topic-list-item')[10].scrollIntoView(true);
|
|
JS
|
|
|
|
topic_list_scroll_y = current_scroll_y
|
|
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")
|
|
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
|
|
expect(current_scroll_y).to eq(topic_list_scroll_y)
|
|
|
|
# Clicking site logo triggers refresh and scrolls to top
|
|
click_logo
|
|
expect(current_scroll_y).to eq(0)
|
|
end
|
|
end
|