discourse/spec/system/nested_post_admin_menu_spec.rb
Rafael dos Santos Silva aaa5d8fdf4
FIX: Wire up wrench post-menu actions in nested replies (#40138)
## Summary

Clicking items in the post wrench (admin) menu in nested replies —
Change Owner, Lock Post, Rebuild HTML, Change Notice, Grant Badge,
Toggle Wiki, etc. — did nothing: no error, no network request, no UI
change.

`AdminPostMenu#topicAction` invokes the chosen item via
`this.args.data[name]?.()`. The optional chain silently no-ops when the
action is `undefined`. In nested mode none of these actions were plumbed
to `<PostMenu>`, so every click was a quiet no-op.

This adds delegate actions on the nested controller (mirroring the
existing `editPost`/`recoverPost`/`showHistory` pattern that forwards to
the hydrated topic controller and topic route), then plumbs them
through:

- `templates/nested.gjs` → `<Nested>` / `<NestedContextView>`
- `<Nested>` / `<NestedContextView>` → `<NestedOp>` and `<NestedPost>`
- `<NestedOp>` → OP's `<PostMenu>`
- `<NestedPost>` → reply's `<PostMenu>` and recursive
`<NestedPostChildren>`
- `<NestedPostChildren>` → recursive `<NestedPost>` (so the menu works
at any depth)

Affected actions: `changeNotice`, `changePostOwner`, `grantBadge`,
`lockPost`, `unlockPost`, `permanentlyDeletePost`, `rebakePost`,
`showPagePublish`, `togglePostType`, `toggleWiki`, `unhidePost`.

## Test plan

- [x] Added `spec/system/nested_post_admin_menu_spec.rb` exercising
lock-post on a reply, lock-post on the OP, and change-owner modal on a
reply (CI will run)
- [x] `bin/lint --fix` on all changed files (eslint, prettier, rubocop
pass)
- [ ] Manually: as admin in nested mode, open wrench on OP and replies —
each menu action fires (lock, rebake, change owner modal, etc.)

---------

Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
2026-05-19 13:13:39 -03:00

59 lines
2 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "Nested view post admin menu" do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:topic) { Fabricate(:topic, user: user) }
fab!(:op) do
Fabricate(
:post,
topic: topic,
user: user,
post_number: 1,
raw: "Original OP content that is long enough to render",
)
end
fab!(:reply) { Fabricate(:post, topic: topic, user: user, raw: "Some reply body here") }
let(:nested_view) { PageObjects::Pages::NestedView.new }
before { SiteSetting.nested_replies_enabled = true }
def open_admin_menu_for(post)
selector = "[data-post-number='#{post.post_number}']"
within(selector) do
find(".show-more-actions").click if has_css?(".show-more-actions", wait: 2)
find(".post-action-menu__admin").click
end
end
context "as an admin" do
before { sign_in(admin) }
it "fires lockPost when clicking the admin menu item on a reply" do
nested_view.visit_nested(topic)
open_admin_menu_for(reply)
expect(page).to have_css("[data-content][data-identifier='admin-post-menu']")
find("[data-content][data-identifier='admin-post-menu'] .lock-post").click
try_until_success { expect(reply.reload.locked_by_id).to eq(admin.id) }
end
it "fires lockPost when clicking the admin menu item on the OP" do
nested_view.visit_nested(topic)
open_admin_menu_for(op)
expect(page).to have_css("[data-content][data-identifier='admin-post-menu']")
find("[data-content][data-identifier='admin-post-menu'] .lock-post").click
try_until_success { expect(op.reload.locked_by_id).to eq(admin.id) }
end
it "opens the change-owner modal when clicking the admin menu item" do
nested_view.visit_nested(topic)
open_admin_menu_for(reply)
find("[data-content][data-identifier='admin-post-menu'] .change-owner").click
expect(page).to have_css(".change-ownership-modal")
end
end
end