0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 15:18:34 +08:00
discourse/spec/system/nested_pagination_spec.rb
Mark VanLandingham 63c4950c90
DEV: route nested view through topic route (#40820)
## What

Draft spike for rendering nested replies through the normal topic
route/controller/template (`/t/:slug/:id[/post_number]`) instead of a
separate Ember `/n/...` browser page route.

This keeps `/n/...` for internal JSON/API endpoints and legacy browser
redirects, while using the canonical topic route for user-facing nested
topic navigation.

## Changes

- Add nested-topic loading/setup to `topic.fromParams` so `/t/...` can
render the nested tree.
- Render `<Nested>` from the topic template when the topic is in nested
mode.
- Keep the nested controller as the nested tree state owner, bridged
from the topic route/controller.
- Redirect legacy client-side `/n/...` browser routes to the
corresponding `/t/...` routes.
- Preserve nested context depth through model processing, controller
state, and cache snapshots.
- Update nested post/admin URLs, notifications, activity, copy links,
and system specs to canonical `/t/...` browser URLs.
- Split scroll-anchor persistence from full nested model cache snapshots
to avoid expensive cache writes on scroll.
- Add bounded scroll restoration retries for mobile browser-back focus
restoration.
2026-06-15 11:42:20 -05:00

120 lines
3.2 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Nested view pagination" do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:op) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
let(:nested_view) { PageObjects::Pages::NestedView.new }
before do
SiteSetting.nested_replies_enabled = true
Fabricate(:nested_topic, topic: topic)
sign_in(user)
end
describe "load more children" do
fab!(:root_reply) do
Fabricate(:post, topic: topic, user: Fabricate(:user), raw: "Root post with many children")
end
# Create 5 child replies — initial load preloads 3, so "load more" appears
fab!(:child_1) do
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Child reply one",
reply_to_post_number: root_reply.post_number,
created_at: 5.minutes.ago,
)
end
fab!(:child_2) do
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Child reply two",
reply_to_post_number: root_reply.post_number,
created_at: 4.minutes.ago,
)
end
fab!(:child_3) do
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Child reply three",
reply_to_post_number: root_reply.post_number,
created_at: 3.minutes.ago,
)
end
fab!(:child_4) do
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Child reply four",
reply_to_post_number: root_reply.post_number,
created_at: 2.minutes.ago,
)
end
fab!(:child_5) do
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Child reply five",
reply_to_post_number: root_reply.post_number,
created_at: 1.minute.ago,
)
end
it "shows load more button and loads additional children on click" do
nested_view.visit_nested(topic)
expect(nested_view).to have_post(root_reply)
expect(page).to have_css(".nested-post-children__load-more")
find(".nested-post-children__load-more").click
expect(nested_view).to have_post(child_1)
expect(nested_view).to have_post(child_2)
expect(nested_view).to have_post(child_3)
expect(nested_view).to have_post(child_4)
expect(nested_view).to have_post(child_5)
expect(page).to have_no_css(".nested-post-children__load-more")
end
end
describe "load more roots" do
# ROOTS_PER_PAGE is 20, so create 22 to have pagination
before do
22.times do |i|
Fabricate(
:post,
topic: topic,
user: Fabricate(:user),
raw: "Root post number #{i + 1}",
reply_to_post_number: nil,
)
end
end
it "initially shows first page of roots and loads more on scroll" do
nested_view.visit_nested(topic)
expect(nested_view).to have_nested_view
initial_count = all(".nested-view__roots > .nested-post").count
expect(initial_count).to eq(20)
page.execute_script("window.scrollTo(0, document.body.scrollHeight)")
expect(page).to have_css(".nested-view__roots > .nested-post", count: 22, wait: 5)
end
end
end