DEV: Fix flaky tests by specifying tag names in asc order (#22271)

Why is this change required?

Previously, the tests in `viewing_sidebar_as_anonymous_user_spec.rb` was
flaky because the ordering of the tags changes depending on what the
auto generated tag names are. If a tag name is generated with the name
`tag10`, it would then be sorted before `tag9` which messes up the
ordering specified in our tests. This commit fixes the problem by
specifying the tag names instead of relying on the auto generated ones
by fabricator.
This commit is contained in:
Alan Guo Xiang Tan 2023-06-26 10:09:26 +08:00 committed by GitHub
parent fb8ce7d76e
commit 0b5d5b0d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 6 deletions

View File

@ -1,12 +1,29 @@
# frozen_string_literal: true
describe "Viewing sidebar as anonymous user", type: :system do
fab!(:tag1) { Fabricate(:tag).tap { |tag| Fabricate.times(1, :topic, tags: [tag]) } }
fab!(:tag2) { Fabricate(:tag).tap { |tag| Fabricate.times(2, :topic, tags: [tag]) } }
fab!(:tag3) { Fabricate(:tag).tap { |tag| Fabricate.times(3, :topic, tags: [tag]) } }
fab!(:tag4) { Fabricate(:tag).tap { |tag| Fabricate.times(2, :topic, tags: [tag]) } }
fab!(:tag5) { Fabricate(:tag).tap { |tag| Fabricate.times(2, :topic, tags: [tag]) } }
fab!(:tag6) { Fabricate(:tag).tap { |tag| Fabricate.times(1, :topic, tags: [tag]) } }
fab!(:tag1) do
Fabricate(:tag, name: "tag 1").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }
end
fab!(:tag2) do
Fabricate(:tag, name: "tag 2").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }
end
fab!(:tag3) do
Fabricate(:tag, name: "tag 3").tap { |tag| Fabricate.times(3, :topic, tags: [tag]) }
end
fab!(:tag4) do
Fabricate(:tag, name: "tag 4").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }
end
fab!(:tag5) do
Fabricate(:tag, name: "tag 5").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }
end
fab!(:tag6) do
Fabricate(:tag, name: "tag 6").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }
end
let(:sidebar) { PageObjects::Components::Sidebar.new }