discourse-shared-edits/test/javascripts/acceptance/composer-test.js
Sam 4e51a4e231
Some checks failed
Discourse Plugin / ci (push) Has been cancelled
FEATURE: allow shared edits to be enabled on any group (#163)
Allow sites to choose which groups can enable or disable shared edits instead of hardcoding staff and TL4 users. Expose the permission on the current user serializer so the admin menu can hide toggle actions for unauthorized users.

Add rate limits to privileged reset and recover endpoints, and update specs, acceptance tests, docs, and settings copy for the new permission model.

* Update config/settings.yml

Co-authored-by: Martin Brennan <martin@discourse.org>

* fix spec

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2026-06-25 16:28:07 +10:00

122 lines
3.3 KiB
JavaScript

import { click, visit, waitUntil } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance(`Discourse Shared Edits | Composer`, function (needs) {
let commitCalls;
needs.user({ can_toggle_shared_edits: true });
needs.settings({
rich_editor: true,
});
needs.pretender((server, helper) => {
commitCalls = [];
server.put("/shared_edits/p/:id/enable.json", () =>
helper.response({ success: "OK" })
);
server.get("/posts/:id.json", () =>
helper.response({
id: 398,
raw: "initial post content",
})
);
server.get("/shared_edits/p/:id", () =>
helper.response({
state: "",
raw: "the latest iteration of the post",
version: 2,
message_bus_last_id: 0,
})
);
server.put("/shared_edits/p/:id", () => helper.response({ success: "OK" }));
server.put("/shared_edits/p/:id/commit.json", () => {
commitCalls.push(Date.now());
return helper.response({ success: "OK" });
});
server.put("/shared_edits/p/:id/selection", () =>
helper.response({ success: "OK" })
);
});
async function openSharedEdit() {
await visit("/t/internationalization-localization/280");
await click(".show-more-actions");
await click(".show-post-admin-menu");
await click(".admin-toggle-shared-edits");
await click(".shared-edit");
}
test("edit the first post", async function (assert) {
await openSharedEdit();
assert
.dom(".d-editor-input")
.hasValue(
"the latest iteration of the post",
"populates the input with the post text"
);
await click(".leave-shared-edit .btn-primary");
});
test("Done button commits and closes composer", async function (assert) {
commitCalls.length = 0;
await openSharedEdit();
assert.dom("#reply-control.open").exists("Composer is open");
await click(".leave-shared-edit .btn-primary");
// Wait for commit to complete
await waitUntil(() => commitCalls.length > 0, { timeout: 2000 });
assert.strictEqual(commitCalls.length, 1, "Commit was called once");
assert
.dom("#reply-control.open")
.doesNotExist("Composer is closed after Done");
});
test("creatingSharedEdit flag is set correctly", async function (assert) {
await openSharedEdit();
const composer = this.container.lookup("service:composer");
assert.true(
composer.model?.creatingSharedEdit,
"creatingSharedEdit is true when in shared edit mode"
);
await click(".leave-shared-edit .btn-primary");
});
test("composer shows Done button in shared edit mode", async function (assert) {
await openSharedEdit();
assert
.dom(".leave-shared-edit .btn-primary")
.exists("Done button is visible");
assert
.dom(".leave-shared-edit .btn-primary")
.hasText(/Done/i, "Button says Done");
await click(".leave-shared-edit .btn-primary");
});
test("editor mode toggle is hidden in shared edit mode", async function (assert) {
await openSharedEdit();
assert
.dom(".composer-toggle-switch")
.doesNotExist("editor mode toggle is hidden when in shared edit mode");
await click(".leave-shared-edit .btn-primary");
});
});