2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/spec/system/new_category_spec.rb
Alan Guo Xiang Tan 55b05c921b
DEV: Add client settled checks for system tests (#35230)
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.
2025-10-10 11:03:18 +08:00

24 lines
642 B
Ruby

# frozen_string_literal: true
describe "New Category", type: :system do
fab!(:admin)
let(:category_page) { PageObjects::Pages::Category.new }
before { sign_in(admin) }
it "should create category with 0 in minimum_required_tags column when not defined" do
category_page.visit_new_category
category_page.find(".edit-category-tab-general input.category-name").fill_in(
with: "New Category",
)
category_page.save_settings
expect(page).to have_current_path("/c/new-category/edit/general")
category = Category.find_by(name: "New Category")
expect(category.minimum_required_tags).to eq(0)
end
end