DEV: Add/use two topic fabricators (#27603)

```rb
Fabricate(:new_reply_topic, count: 1, current_user:)
```

and

```rb
Fabricate(:read_topic, current_user:)
```
This commit is contained in:
Jarek Radosz 2024-06-25 13:47:53 +02:00 committed by GitHub
parent d63f1826fe
commit 24d0c3aadf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 94 deletions

View File

@ -37,6 +37,7 @@ Fabricator(:group_private_message_topic, from: :topic) do
end
Fabricator(:new_reply_topic, from: :topic) do
transient count: 1
transient :current_user
before_create do |topic, transient|
@ -46,7 +47,7 @@ Fabricator(:new_reply_topic, from: :topic) do
end
after_create do |topic, transient|
Fabricate.times(2, :post, topic: topic)
Fabricate.times(transient[:count] + 1, :post, topic: topic)
TopicUser.change(
transient[:current_user].id,
topic.id,
@ -55,3 +56,18 @@ Fabricator(:new_reply_topic, from: :topic) do
TopicUser.update_last_read(transient[:current_user], topic.id, 1, 1, 1)
end
end
Fabricator(:read_topic, from: :topic) do
transient :current_user
before_create do |topic, transient|
if !transient[:current_user]
raise "new_reply_topic fabricator requires the `current_user` param"
end
end
after_create do |topic, transient|
Fabricate(:post, topic: topic)
TopicUser.update_last_read(transient[:current_user], topic.id, 1, 1, 1)
end
end

View File

@ -381,7 +381,7 @@ RSpec.describe ListController do
it "should display moderator group private messages for a moderator" do
moderator = Fabricate(:moderator)
group = Group.find(Group::AUTO_GROUPS[:moderators])
topic = Fabricate(:private_message_topic, allowed_groups: [group])
Fabricate(:private_message_topic, allowed_groups: [group])
sign_in(moderator)
@ -1518,56 +1518,30 @@ RSpec.describe ListController do
response.parsed_body["topic_list"]["topics"].map { |topics| topics["id"] }
end
def make_topic_with_unread_replies(topic, user)
TopicUser.change(
user.id,
topic.id,
notification_level: TopicUser.notification_levels[:tracking],
)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
Fabricate(:post, topic: topic)
topic
end
def make_topic_read(topic, user)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
topic
end
context "when the user is part of the `experimental_new_new_view_groups` site setting group" do
fab!(:category)
fab!(:tag)
fab!(:new_reply) { make_topic_with_unread_replies(Fabricate(:post).topic, user) }
fab!(:new_reply) { Fabricate(:new_reply_topic, current_user: user) }
fab!(:new_topic) { Fabricate(:post).topic }
fab!(:old_topic) { make_topic_read(Fabricate(:post).topic, user) }
fab!(:old_topic) { Fabricate(:read_topic, current_user: user) }
fab!(:new_reply_in_category) do
make_topic_with_unread_replies(
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic,
user,
)
Fabricate(:new_reply_topic, category: category, current_user: user)
end
fab!(:new_topic_in_category) do
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic
end
fab!(:old_topic_in_category) do
make_topic_read(Fabricate(:post, topic: Fabricate(:topic, category: category)).topic, user)
Fabricate(:read_topic, category: category, current_user: user)
end
fab!(:new_reply_with_tag) do
make_topic_with_unread_replies(
Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic,
user,
)
end
fab!(:new_reply_with_tag) { Fabricate(:new_reply_topic, tags: [tag], current_user: user) }
fab!(:new_topic_with_tag) { Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic }
fab!(:old_topic_with_tag) do
make_topic_read(Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic, user)
end
fab!(:old_topic_with_tag) { Fabricate(:read_topic, tags: [tag], current_user: user) }
before do
make_topic_read(topic, user)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
SiteSetting.experimental_new_new_view_groups = group.name
group.add(user)

View File

@ -6,65 +6,23 @@ describe "New topic list", type: :system do
fab!(:category)
fab!(:tag)
fab!(:new_reply) do
Fabricate(:post).topic.tap do |topic|
TopicUser.change(
user.id,
topic.id,
notification_level: TopicUser.notification_levels[:tracking],
)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
Fabricate(:post, topic: topic)
end
end
fab!(:new_reply) { Fabricate(:new_reply_topic, current_user: user) }
fab!(:new_topic) { Fabricate(:post).topic }
fab!(:old_topic) do
Fabricate(:post).topic.tap { |topic| TopicUser.update_last_read(user, topic.id, 1, 1, 1) }
end
fab!(:old_topic) { Fabricate(:read_topic, current_user: user) }
fab!(:new_reply_in_category) do
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic.tap do |topic|
TopicUser.change(
user.id,
topic.id,
notification_level: TopicUser.notification_levels[:tracking],
)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
Fabricate(:post, topic: topic)
end
Fabricate(:new_reply_topic, category: category, current_user: user)
end
fab!(:new_topic_in_category) do
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic
end
fab!(:old_topic_in_category) do
Fabricate(:post, topic: Fabricate(:topic, category: category)).topic.tap do |topic|
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
end
end
fab!(:new_reply_with_tag) do
Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic.tap do |topic|
TopicUser.change(
user.id,
topic.id,
notification_level: TopicUser.notification_levels[:tracking],
)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
Fabricate(:post, topic: topic)
end
end
fab!(:old_topic_in_category) { Fabricate(:read_topic, category: category, current_user: user) }
fab!(:new_reply_with_tag) { Fabricate(:new_reply_topic, tags: [tag], current_user: user) }
fab!(:new_topic_with_tag) { Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic }
fab!(:old_topic_with_tag) do
Fabricate(:post, topic: Fabricate(:topic, tags: [tag])).topic.tap do |topic|
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
end
end
fab!(:old_topic_with_tag) { Fabricate(:read_topic, tags: [tag], current_user: user) }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:tabs_toggle) { PageObjects::Components::NewTopicListToggle.new }

View File

@ -60,17 +60,7 @@ describe "glimmer topic list", type: :system do
it "shows the list" do
topic1 = Fabricate(:post).topic
topic2 = Fabricate(:post).topic
new_reply =
Fabricate(:post).topic.tap do |topic|
TopicUser.change(
user.id,
topic.id,
notification_level: TopicUser.notification_levels[:tracking],
)
TopicUser.update_last_read(user, topic.id, 1, 1, 1)
Fabricate.times(3, :post, topic: topic)
end
new_reply = Fabricate(:new_reply_topic, current_user: user, count: 3)
visit(topic1.relative_url)