From 1052ed9c3ba4daf8fb4e9fe3f5f2eb8200e697c9 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 18 Jul 2023 07:35:47 +0800 Subject: [PATCH] DEV: Fix flaky system test in `system/category_topics_spec.rb` (#22652) Why was the test flaky? The test relied on the fact that visiting a topic would marked its post as unread. However, we did not actually stay on the topic long enough in some cases for it to be considered read based on the logic in our client side code. This commit fixes the flakiness by ensuring that the post has actually been read before navigating away. --- spec/system/category_topics_spec.rb | 5 +++++ spec/system/page_objects/components/topic_view.rb | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 spec/system/page_objects/components/topic_view.rb diff --git a/spec/system/category_topics_spec.rb b/spec/system/category_topics_spec.rb index d058ffcb272..6186b57ad79 100644 --- a/spec/system/category_topics_spec.rb +++ b/spec/system/category_topics_spec.rb @@ -3,8 +3,10 @@ describe "Viewing top topics on categories page", type: :system, js: true do fab!(:user) { Fabricate(:user) } let(:category_list) { PageObjects::Components::CategoryList.new } + let(:topic_view) { PageObjects::Components::TopicView.new } fab!(:category) { Fabricate(:category) } fab!(:topic) { Fabricate(:topic, category: category) } + fab!(:post) { Fabricate(:post, topic: topic) } it "displays and updates new counter" do skip(<<~TEXT) @@ -20,6 +22,9 @@ describe "Viewing top topics on categories page", type: :system, js: true do category_list.click_new_posts_badge(count: 1) category_list.click_topic(topic) + + expect(topic_view).to have_read_post(post) + category_list.click_logo category_list.click_category_navigation diff --git a/spec/system/page_objects/components/topic_view.rb b/spec/system/page_objects/components/topic_view.rb new file mode 100644 index 00000000000..6fef55c2362 --- /dev/null +++ b/spec/system/page_objects/components/topic_view.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module PageObjects + module Components + class TopicView < PageObjects::Components::Base + def has_read_post?(post) + page.has_css?( + "#post_#{post.post_number} .read-state.read", + visible: false, + wait: Capybara.default_max_wait_time * 2, + ) + end + end + end +end