0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-15 14:06:35 +08:00
discourse/plugins/discourse-solved/spec/system/shared_issue_spec.rb
Kris c894e2f722
FEATURE: make shared issues optional per-category (#40501)
This makes the shared issue feature of support categories optional
per-category, so admins can turn it off selectively.

This is accomplished by adding a category level setting: `Enable shared
issues`

<img width="1404" height="564" alt="image"
src="https://github.com/user-attachments/assets/e4997382-b5fb-4839-af9d-6baf57ec3201"
/>


When enabled this exposes the Site Setting to edit the button's text in
the section below.

Enabled: 
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/39293f0d-63a3-421c-8c2b-2ee967faee56"
/>


Disabled:
<img width="500" alt="image"
src="https://github.com/user-attachments/assets/6bc92173-0cd4-40cf-89b2-56d74469e752"
/>
2026-06-04 11:58:28 -04:00

153 lines
4.6 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Solved | Shared issue button" do
fab!(:author, :user)
fab!(:member, :user)
fab!(:support_category) do
Fabricate(:category).tap do |c|
c.upsert_custom_fields(DiscourseSolved::ENABLE_ACCEPTED_ANSWERS_CUSTOM_FIELD => "true")
end
end
fab!(:topic) do
Fabricate(
:post,
user: author,
topic: Fabricate(:topic, category: support_category, user: author),
).topic
end
fab!(:op) { topic.first_post }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:shared_issue_button) { PageObjects::Components::PostSharedIssueButton.new(op) }
before do
SiteSetting.solved_enabled = true
SiteSetting.enable_solved_shared_issues = true
DiscourseSolved::AcceptedAnswerCache.reset_accepted_answer_cache
end
it "lets a member toggle the shared issue on and off" do
sign_in(member)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_shared_issue_button
expect(shared_issue_button).to have_count(0)
shared_issue_button.click
expect(shared_issue_button).to have_count(1)
expect(shared_issue_button).to have_active
expect(TopicUser.get(topic, member).notification_level).to eq(
TopicUser.notification_levels[:tracking],
)
shared_issue_button.click
expect(shared_issue_button).to have_count(0)
expect(shared_issue_button).to have_no_css(".has-shared-issue")
end
it "hides the button once the topic is solved" do
answer_post = Fabricate(:post, topic:)
solved_topic = Fabricate(:solved_topic, topic:)
Fabricate(:topic_answer, solved_topic:, post: answer_post, accepter: author)
sign_in(member)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_no_shared_issue_button
end
it "re-shows the button after a solution is accepted then unaccepted" do
answer_post = Fabricate(:post, topic:)
sign_in(author)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_shared_issue_button
within("#post_#{answer_post.post_number}") do
find(".post-action-menu__solved-unaccepted").click
end
expect(page).to have_css(".accepted-answers")
expect(shared_issue_button).to have_no_shared_issue_button
within("#post_#{answer_post.post_number}") { find(".post-action-menu__solved-accepted").click }
expect(page).to have_no_css(".accepted-answers")
expect(shared_issue_button).to have_shared_issue_button
end
it "hides the button when the upcoming change is disabled" do
SiteSetting.enable_solved_shared_issues = false
sign_in(member)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_no_shared_issue_button
end
it "hides the button when shared issues are disabled for the category" do
support_category.upsert_custom_fields(
DiscourseSolved::SHARED_ISSUES_ENABLED_CUSTOM_FIELD => "false",
)
sign_in(member)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_no_shared_issue_button
end
it "prompts anonymous visitors to log in" do
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_shared_issue_button
shared_issue_button.click
expect(page).to have_current_path(%r{/login})
end
it "hides the button on topics outside a support category" do
other_topic = Fabricate(:post, user: author).topic
sign_in(member)
topic_page.visit_topic(other_topic)
expect(shared_issue_button).to have_no_shared_issue_button
end
it "shows the button as read-only for the topic author" do
sign_in(author)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_shared_issue_button
expect(shared_issue_button).to have_read_only
expect(shared_issue_button).to have_count(0)
end
describe "with multiple solutions enabled" do
before { SiteSetting.solved_allow_multiple_solutions = true }
it "shows the button even after a solution is accepted" do
answer_post = Fabricate(:post, topic:)
solved_topic = Fabricate(:solved_topic, topic:)
Fabricate(:topic_answer, solved_topic:, post: answer_post, accepter: author)
sign_in(member)
topic_page.visit_topic(topic)
expect(shared_issue_button).to have_shared_issue_button
end
it "lets a member create a shared issue on a solved topic" do
answer_post = Fabricate(:post, topic:)
solved_topic = Fabricate(:solved_topic, topic:)
Fabricate(:topic_answer, solved_topic:, post: answer_post, accepter: author)
sign_in(member)
topic_page.visit_topic(topic)
shared_issue_button.click
expect(shared_issue_button).to have_active
expect(shared_issue_button).to have_count(1)
end
end
end