discourse/spec/lib/nested_replies/post_tree_serializer_spec.rb
Mark VanLandingham a32f887725
FIX: Hide ignored user posts from nested topic view (#39504)
Behavior matches flat mode. OP simply says "Ignored content":
<img width="1291" height="578" alt="Screenshot 2026-04-23 at 3 25 35 PM"
src="https://github.com/user-attachments/assets/ce7d23ef-79c1-4aa5-8a43-7afbf00e554b"
/>

For ignored replies, they are hidden by default but clicking the eye
opens them

<img width="1292" height="946" alt="Screenshot 2026-04-23 at 3 05 33 PM"
src="https://github.com/user-attachments/assets/9b2a50ac-8c6d-458e-895b-6dc01eb4b2d7"
/>
<img width="1289" height="928" alt="Screenshot 2026-04-23 at 3 05 38 PM"
src="https://github.com/user-attachments/assets/52707e3d-25e1-41bd-b466-c15a131303c6"
/>
2026-04-28 12:50:09 -05:00

83 lines
2.8 KiB
Ruby

# frozen_string_literal: true
RSpec.describe NestedReplies::PostTreeSerializer do
fab!(:user)
fab!(:ignored_user, :user)
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
let(:topic_view) do
TopicView.new(topic.id, user, skip_custom_fields: true, skip_post_loading: true)
end
before { SiteSetting.nested_replies_enabled = true }
def serializer_for(viewer)
described_class.new(topic: topic, topic_view: topic_view, guardian: Guardian.new(viewer))
end
describe "#serialize_post" do
fab!(:reply) do
Fabricate(:post, topic: topic, user: ignored_user, reply_to_post_number: 1, raw: "secret")
end
context "when the viewer has ignored the author" do
before { Fabricate(:ignored_user, user: user, ignored_user: ignored_user) }
it "marks it as an ignored_post_placeholder, clears content, keeps metadata" do
json = serializer_for(user).serialize_post(reply, {})
expect(json[:ignored_post_placeholder]).to eq(true)
expect(json[:cooked]).to eq("")
expect(json[:raw]).to be_nil
expect(json[:actions_summary]).to eq([])
expect(json[:username]).to eq(ignored_user.username)
expect(json).to include(:id, :post_number, :reply_to_post_number, :avatar_template)
end
end
context "when the viewer has not ignored the author" do
it "returns the full post JSON" do
json = serializer_for(user).serialize_post(reply, {})
expect(json).not_to have_key(:ignored_post_placeholder)
expect(json[:cooked]).to include("secret")
end
end
context "when the viewer is anonymous" do
it "returns the full post JSON" do
json = serializer_for(nil).serialize_post(reply, {})
expect(json).not_to have_key(:ignored_post_placeholder)
expect(json[:cooked]).to include("secret")
end
end
context "when the ignored author wrote the OP (post_number == 1)" do
before { Fabricate(:ignored_user, user: user, ignored_user: ignored_user) }
it "does not placeholder the OP (client-side firstPost handles it)" do
op.update!(user: ignored_user)
json = serializer_for(user).serialize_post(op, {})
expect(json).not_to have_key(:ignored_post_placeholder)
expect(json[:cooked]).to be_present
end
end
context "when the post is both deleted and from an ignored author" do
before { Fabricate(:ignored_user, user: user, ignored_user: ignored_user) }
it "prefers the deleted_post_placeholder path" do
reply.trash!(user)
json = serializer_for(user).serialize_post(reply.reload, {})
expect(json[:deleted_post_placeholder]).to eq(true)
expect(json).not_to have_key(:ignored_post_placeholder)
end
end
end
end