discourse/spec/system/nested_topic_admin_toggle_spec.rb
Mark VanLandingham 8feeaa5d69
FEATURE: First iteration of nested replies (#38888)
### Super high level description:
Adds a nested/threaded view for Discourse topics, allowing posts to be
displayed as an indented reply tree instead of the default flat
chronological stream.

  Backend:
- New /n/:slug/:topic_id routes serving roots, children (paginated), and
context (ancestor chain) endpoints
- TreeLoader recursively fetches reply trees with configurable max
depth, Sort supports top/new/old ordering
- NestedViewPostStat caches per-post reply counts (direct + total
descendants, whisper-aware) with a backfill job for existing data
  - NestedTopic model tracks per-topic opt-in and pinned post

  Frontend:
- Recursive <NestedPost> / <NestedPostChildren> components with
lazy-load expansion, cloaking, and scroll tracking
- NestedViewCache service preserves expansion state and scroll position
across back/forward navigation (15 entries, 10min TTL)
- Context view for deep-linking to a specific post with its ancestor
chain
  - Floating actions bar, sort selector, real-time MessageBus updates

Site settings (hidden): nested_replies_enabled, nested_replies_default,
nested_replies_default_sort, nested_replies_max_depth,
nested_replies_cap_nesting_depth, nested_replies_toggle_mode_groups,
plus a per-category default override.

Co-authored-by: Rafael Silva <xfalcox@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Sérgio Saquetim <saquetim@discourse.org>
2026-04-16 08:06:44 -05:00

47 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require_relative "../support/nested_replies_helpers"
RSpec.describe "Nested replies topic admin toggle" do
include NestedRepliesHelpers
fab!(:admin)
fab!(:topic) { Fabricate(:topic, user: admin) }
fab!(:op) { Fabricate(:post, topic: topic, user: admin, post_number: 1) }
fab!(:reply) { Fabricate(:post, topic: topic, user: Fabricate(:user), raw: "A reply") }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:nested_view) { PageObjects::Pages::NestedView.new }
before do
SiteSetting.nested_replies_enabled = true
sign_in(admin)
end
it "enables nested replies from the flat view and routes to nested" do
topic_page.visit_topic(topic)
topic_page.click_admin_menu_button
find(".topic-admin-nested-replies").click
expect(page).to have_current_path(%r{/n/#{topic.slug}/#{topic.id}})
expect(nested_view).to have_nested_view
topic.reload
expect(topic.reload.nested_topic).to be_present
end
it "disables nested replies from the nested view and routes to flat" do
Fabricate(:nested_topic, topic: topic)
nested_view.visit_nested(topic)
nested_view.open_admin_menu
find(".topic-admin-nested-replies").click
expect(page).to have_current_path(%r{/t/#{topic.slug}/#{topic.id}})
expect(nested_view).to have_no_nested_view
topic.reload
expect(topic.reload.nested_topic).to be_nil
end
end