From 346c9116b564ccc8b3f3e9e3d9d6f9a71f09293c Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Sat, 20 Jul 2024 00:39:22 +0800 Subject: [PATCH] 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. --- spec/system/admin_sidebar_navigation_spec.rb | 21 +++++++++---------- spec/system/homepage_spec.rb | 9 ++++++-- .../page_objects/components/select_kit.rb | 2 +- spec/system/signup_spec.rb | 3 ++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/spec/system/admin_sidebar_navigation_spec.rb b/spec/system/admin_sidebar_navigation_spec.rb index 0014b925fc2..84ebdac0d99 100644 --- a/spec/system/admin_sidebar_navigation_spec.rb +++ b/spec/system/admin_sidebar_navigation_spec.rb @@ -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 diff --git a/spec/system/homepage_spec.rb b/spec/system/homepage_spec.rb index 2be3c5d8033..29546fdda78 100644 --- a/spec/system/homepage_spec.rb +++ b/spec/system/homepage_spec.rb @@ -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 diff --git a/spec/system/page_objects/components/select_kit.rb b/spec/system/page_objects/components/select_kit.rb index 10ca8d9f73b..254fc78b187 100644 --- a/spec/system/page_objects/components/select_kit.rb +++ b/spec/system/page_objects/components/select_kit.rb @@ -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 diff --git a/spec/system/signup_spec.rb b/spec/system/signup_spec.rb index 92e789b7079..2746aff5f99 100644 --- a/spec/system/signup_spec.rb +++ b/spec/system/signup_spec.rb @@ -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)