Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add system tests for discourse-solved tag-based functionality (#37304)

Alan Guo Xiang Tanecbe21683ce6
diff --git a/plugins/discourse-solved/spec/system/page_objects/components/post_solved_button.rb b/plugins/discourse-solved/spec/system/page_objects/components/post_solved_button.rb
new file mode 100644
index 00000000000..20bbb610a95
--- /dev/null
+++ b/plugins/discourse-solved/spec/system/page_objects/components/post_solved_button.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Components
+ class PostSolvedButton < PageObjects::Components::Base
+ def initialize(post)
+ @post = post
+ end
+
+ def accept_answer
+ within_post { find(".post-action-menu__solved-unaccepted").click }
+ self
+ end
+
+ def has_accept_button?
+ within_post { has_css?(".post-action-menu__solved-unaccepted") }
+ end
+
+ def has_no_accept_button?
+ within_post { has_no_css?(".post-action-menu__solved-unaccepted") }
+ end
+
+ def has_accepted_button?
+ within_post { has_css?(".post-action-menu__solved-accepted") }
+ end
+
+ private
+
+ def within_post
+ within(post_selector) { yield }
+ end
+
+ def post_selector
+ "#post_#{@post.post_number}"
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-solved/spec/system/page_objects/components/solved_status_filter.rb b/plugins/discourse-solved/spec/system/page_objects/components/solved_status_filter.rb
new file mode 100644
index 00000000000..6bfc942ee5c
--- /dev/null
+++ b/plugins/discourse-solved/spec/system/page_objects/components/solved_status_filter.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Components
+ class SolvedStatusFilter < PageObjects::Components::Base
+ SELECTOR = ".solved-status-filter"
+
+ def visible?
+ has_css?(SELECTOR)
+ end
+
+ def filter_solved
+ select_kit.expand
+ select_kit.select_row_by_value("solved")
+ self
+ end
+
+ def filter_unsolved
+ select_kit.expand
+ select_kit.select_row_by_value("unsolved")
+ self
+ end
+
+ private
+
+ def select_kit
+ @select_kit ||= PageObjects::Components::SelectKit.new(SELECTOR)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-solved/spec/system/solved_with_tags_spec.rb b/plugins/discourse-solved/spec/system/solved_with_tags_spec.rb
new file mode 100644
index 00000000000..0f7f4202680
--- /dev/null
+++ b/plugins/discourse-solved/spec/system/solved_with_tags_spec.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+describe "Solved with tags", type: :system do
+ fab!(:user)
+ fab!(:replier, :user)
+ fab!(:tag)
+ fab!(:unsolved_topic) { Fabricate(:topic_with_op, user:, tags: [tag]) }
+ fab!(:reply) { Fabricate(:post, topic: unsolved_topic, user: replier) }
+ fab!(:solved_topic) { Fabricate(:topic_with_op, tags: [tag]) }
+ fab!(:answer_post) { Fabricate(:post, topic: solved_topic) }
+ fab!(:solved_topic_record) do
+ Fabricate(:solved_topic, topic: solved_topic, answer_post: answer_post)
+ end
+
+ let(:topic_page) { PageObjects::Pages::Topic.new }
+ let(:tag_page) { PageObjects::Pages::Tag.new }
+ let(:topic_list) { PageObjects::Components::TopicList.new }
+ let(:solved_status_filter) { PageObjects::Components::SolvedStatusFilter.new }
+
+ before do
+ SiteSetting.solved_enabled = true
+ SiteSetting.allow_solved_on_all_topics = false
+ SiteSetting.enable_solved_tags = tag.name
+ SiteSetting.accept_solutions_topic_author = true
+ end
+
+ it "allows accepting an answer when topic has an enabled solved tag" do
+ sign_in(user)
+ topic_page.visit_topic(unsolved_topic, post_number: 2)
+
+ post_solved_button = PageObjects::Components::PostSolvedButton.new(reply)
+
+ expect(post_solved_button).to have_accept_button
+
+ post_solved_button.accept_answer
+
+ expect(post_solved_button).to have_accepted_button
+ end
+
+ it "does not show accept button on topics without enabled tags" do
+ other_tag = Fabricate(:tag)
+ other_topic = Fabricate(:topic_with_op, user:, tags: [other_tag])
+ other_reply = Fabricate(:post, topic: other_topic)
+
+ sign_in(user)
+ topic_page.visit_topic(other_topic, post_number: 2)
+
+ post_solved_button = PageObjects::Components::PostSolvedButton.new(other_reply)
+
+ expect(post_solved_button).to have_no_accept_button
+ end
+
+ it "shows solved status filter on tag page and filters topics correctly" do
+ SiteSetting.show_filter_by_solved_status = true
+
+ sign_in(user)
+ tag_page.visit_tag(tag)
+
+ expect(solved_status_filter).to be_visible
+ expect(topic_list).to have_topic(solved_topic)
+ expect(topic_list).to have_topic(unsolved_topic)
+
+ solved_status_filter.filter_solved
+
+ expect(topic_list).to have_topic(solved_topic)
+ expect(topic_list).to have_no_topic(unsolved_topic)
+
+ solved_status_filter.filter_unsolved
+
+ expect(topic_list).to have_no_topic(solved_topic)
+ expect(topic_list).to have_topic(unsolved_topic)
+ end
+end