diff --git a/spec/fabricators/topic_fabricator.rb b/spec/fabricators/topic_fabricator.rb index f6d737cf092..18c37bd6c3e 100644 --- a/spec/fabricators/topic_fabricator.rb +++ b/spec/fabricators/topic_fabricator.rb @@ -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 diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index 17045a88374..050ce2e0ed4 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -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) diff --git a/spec/system/new_topic_list_spec.rb b/spec/system/new_topic_list_spec.rb index a80f3bdf029..c52e716ebbd 100644 --- a/spec/system/new_topic_list_spec.rb +++ b/spec/system/new_topic_list_spec.rb @@ -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 } diff --git a/spec/system/topic_list/glimmer_spec.rb b/spec/system/topic_list/glimmer_spec.rb index e3db3e7e518..f838b026908 100644 --- a/spec/system/topic_list/glimmer_spec.rb +++ b/spec/system/topic_list/glimmer_spec.rb @@ -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)