DEV: Allow system tests to assert on values at the correct time (#27988)

This adds some more assertions in system tests at certain instances during the test to minimise flakiness.
This commit is contained in:
Natalie Tay 2024-07-20 00:39:22 +08:00 committed by GitHub
parent 6e77107ccc
commit 346c9116b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 15 deletions

View File

@ -83,11 +83,10 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do
it "allows links to be filtered" do
visit("/admin")
sidebar.toggle_all_sections
all_links_count = page.all(".sidebar-section-link-content-text").count
links = page.all(".sidebar-section-link-content-text")
expect(links.count).to eq(all_links_count)
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
expect(page).to have_no_css(".sidebar-no-results")
all_links_count = page.all(".sidebar-section-link-content-text").count
filter.filter("ie")
links = page.all(".sidebar-section-link-content-text")
@ -218,16 +217,16 @@ describe "Admin Revamp | Sidebar Navigation", type: :system do
it "allows sections to be expanded" do
visit("/admin")
sidebar.toggle_all_sections
all_links_count = page.all(".sidebar-section-link-content-text").count
sidebar.toggle_all_sections
links = page.all(".sidebar-section-link-content-text")
expect(links.count).to eq(3)
expect(links.map(&:text)).to eq(["Dashboard", "Users", "All Site Settings"])
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
sidebar.toggle_all_sections
links = page.all(".sidebar-section-link-content-text")
expect(links.count).to eq(all_links_count)
expect(page).to have_selector(".sidebar-section-link-content-text", count: 3)
expect(all(".sidebar-section-link-content-text").map(&:text)).to eq(
["Dashboard", "Users", "All Site Settings"],
)
sidebar.toggle_all_sections
expect(page).to have_selector(".sidebar-section-link-content-text", minimum: 50)
end
it "accepts hidden keywords like installed plugin names for filter" do

View File

@ -78,6 +78,9 @@ describe "Homepage", type: :system do
sign_in user
visit ""
expect(page).to have_css(".new-home", text: "Hi friends!")
visit "/u/#{user.username}/preferences/interface"
homepage_picker = PageObjects::Components::SelectKit.new("#home-selector")
@ -88,9 +91,9 @@ describe "Homepage", type: :system do
# Wait for the save to complete
find(".btn-primary.save-changes:not([disabled])", wait: 5)
expect(user.user_option.homepage_id).to eq(UserOption::HOMEPAGES.key("top"))
find("#site-logo").click
expect(page).to have_css(".navigation-container .top.active", text: "Top")
expect(page).to have_css(".top-lists")
@ -104,9 +107,11 @@ describe "Homepage", type: :system do
# Wait for the save to complete
find(".btn-primary.save-changes:not([disabled])", wait: 5)
expect(user.reload.user_option.homepage_id).to_not eq(UserOption::HOMEPAGES.key("top"))
find("#site-logo").click
expect(page).not_to have_css(".list-container")
expect(page).to have_current_path("/")
expect(page).to have_css(".new-home", text: "Hi friends!")
end
end

View File

@ -27,7 +27,7 @@ module PageObjects
def expanded_component
expand_if_needed
find(@context + ".is-expanded")
find(@context + ".is-expanded", wait: 5)
end
def collapsed_component

View File

@ -95,6 +95,8 @@ shared_examples "signup scenarios" do
expect(signup_modal).to have_valid_fields
signup_modal.click_create_account
wait_for(timeout: 5) { User.find_by(username: "john") != nil }
visit "/"
login_modal.open
login_modal.fill_username("john")
@ -102,7 +104,6 @@ shared_examples "signup scenarios" do
login_modal.click_login
expect(login_modal).to have_content(I18n.t("login.not_approved"))
wait_for(timeout: 5) { User.find_by(username: "john") != nil }
user = User.find_by(username: "john")
user.update!(approved: true)
EmailToken.confirm(Fabricate(:email_token, user: user).token)