From aa4a5add70173c7de7af3d1d64b67fcb27bcc69b Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 16 Oct 2023 10:51:59 +0100
Subject: [PATCH] DEV: Add system specs for dismiss new on tag routes (#23936)

---
 spec/system/dismissing_new_spec.rb          | 43 +++++++++++++++++++++
 spec/system/page_objects/pages/discovery.rb |  4 ++
 2 files changed, 47 insertions(+)

diff --git a/spec/system/dismissing_new_spec.rb b/spec/system/dismissing_new_spec.rb
index 5dd80a6590b..ccf493d6dc7 100644
--- a/spec/system/dismissing_new_spec.rb
+++ b/spec/system/dismissing_new_spec.rb
@@ -3,6 +3,7 @@
 RSpec.describe "Dismissing New", type: :system do
   fab!(:user) { Fabricate(:user) }
 
+  let(:discovery) { PageObjects::Pages::Discovery.new }
   let(:topic_list_controls) { PageObjects::Components::TopicListControls.new }
   let(:topic_list) { PageObjects::Components::TopicList.new }
   let(:dismiss_new_modal) { PageObjects::Modals::DismissNew.new }
@@ -129,5 +130,47 @@ RSpec.describe "Dismissing New", type: :system do
 
       expect(topic_list).to have_no_topics
     end
+
+    context "with a tagged topic" do
+      fab!(:tag) { Fabricate(:tag) }
+      fab!(:tagged_topic) { Fabricate(:topic, tags: [tag]) }
+      fab!(:tagged_first_post) { Fabricate(:post, topic: tagged_topic) }
+
+      it "works on tag routes" do
+        sign_in(user)
+
+        visit("/tag/#{tag.name}/l/new")
+
+        expect(topic_list).to have_topics(count: 1)
+        expect(topic_list).to have_topic(tagged_first_post.topic)
+
+        topic_list_controls.dismiss_new
+        dismiss_new_modal.click_dismiss
+
+        expect(topic_list).to have_no_topics
+
+        visit("/new")
+        expect(topic_list).to have_topic(post1.topic)
+      end
+
+      it "works on regular routes after visiting tagged route" do
+        sign_in(user)
+
+        visit("/tag/#{tag.name}/l/new")
+
+        expect(topic_list).to have_topics(count: 1)
+
+        discovery.tag_drop.select_row_by_value("all-tags")
+
+        expect(topic_list).to have_topics(count: 3)
+
+        discovery.nav_item("new").click
+
+        topic_list_controls.dismiss_new
+        dismiss_new_modal.click_dismiss
+
+        expect(topic_list).to have_no_topics
+      end
+    end
   end
 end
diff --git a/spec/system/page_objects/pages/discovery.rb b/spec/system/page_objects/pages/discovery.rb
index e0715e52947..6dcec8f1b35 100644
--- a/spec/system/page_objects/pages/discovery.rb
+++ b/spec/system/page_objects/pages/discovery.rb
@@ -18,6 +18,10 @@ module PageObjects
       def tag_drop
         Components::SelectKit.new(".category-breadcrumb .tag-drop")
       end
+
+      def nav_item(name)
+        find("#navigation-bar .nav-item_#{name}")
+      end
     end
   end
 end