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
4 changed files with 32 additions and 94 deletions

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)