discourse-solved/spec/system/solved_spec.rb
Natalie Tay f96aceb5f4
FIX: Use SolvedTopics to list posts in /activity/solved instead of user actions (#376)
In https://github.com/discourse/discourse-solved/pull/342 we moved solutions away from topic_custom_fields into proper tables, with the tables as the proper source of truth to a topic's solution.

The user's /my/activity/solved route uses user_actions which is not accurate, and a user has reported a bug where their solution is not reflected there (user actions are not a good representation of what a topic's solution is). 

This commit introduces 
- a new route to get solutions, and is mindful `hide_user_profiles_from_public` and such settings
- also mindful of PMs and private categories
- a new template that makes use of the `<UserStream>` to load posts safely and avoid reimplementation
2025-07-02 16:56:12 +08:00

52 lines
1.7 KiB
Ruby

# frozen_string_literal: true
describe "Solved", type: :system do
fab!(:admin)
fab!(:solver) { Fabricate(:user) }
fab!(:accepter) { Fabricate(:user) }
fab!(:topic) { Fabricate(:post, user: admin).topic }
fab!(:solver_post) { Fabricate(:post, topic:, user: solver, cooked: "The answer is 42") }
let(:topic_page) { PageObjects::Pages::Topic.new }
before do
SiteSetting.solved_enabled = true
SiteSetting.allow_solved_on_all_topics = true
SiteSetting.accept_all_solutions_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.show_who_marked_solved = true
end
%w[enabled disabled].each do |value|
before { SiteSetting.glimmer_post_stream_mode = value }
context "when glimmer_post_stream_mode=#{value}" do
it "accepts post as solution and shows in OP" do
sign_in(accepter)
topic_page.visit_topic(topic, post_number: 2)
expect(topic_page).to have_css(".post-action-menu__solved-unaccepted")
find(".post-action-menu__solved-unaccepted").click
expect(topic_page).to have_css(".post-action-menu__solved-accepted")
expect(topic_page.find(".title .accepted-answer--solver")).to have_content(
"Solved by #{solver.username}",
)
expect(topic_page.find(".title .accepted-answer--accepter")).to have_content(
"Marked as solved by #{accepter.username}",
)
expect(topic_page.find("blockquote")).to have_content("The answer is 42")
end
end
end
it "shows the solved post in user activity at /my/activity/solved" do
Fabricate(:solved_topic, topic:, answer_post: solver_post, accepter:)
sign_in(solver)
visit "/my/activity/solved"
expect(page.find(".post-list")).to have_content(solver_post.cooked)
end
end