0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-calendar/test/javascripts/integration/components/rich-editor-extension-test.js
Renato Atilio b834edd625
DEV: Remove rich_editor site setting (#41873)
The setting has been hidden and enabled by default since it was switched
on for all sites in mid-2025, making it effectively dead configuration.
The rich editor is now always available, and the per-user
`composition_mode` preference remains the only way to pick between the
markdown and rich text editors.

This also makes the first toolbar button focusable when a
`composer-force-editor-mode` transformer hides the editor mode toggle,
which previously left the toolbar without a tabbable button in that
state.

Since it comes from the same rollout, this also drops the shim that
migrated the pre-`composition_mode` localStorage preference
(`d-editor-prefers-rich-editor`) into the user option. The key hasn't
been written since the rich editor was enabled everywhere a year ago,
and the shim deleted it on first composer open, so any remaining copies
belong to browsers that haven't composed since then — for those, the
default mode is rich anyway.
2026-07-23 19:49:20 -03:00

93 lines
3.4 KiB
JavaScript
Vendored

import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { testMarkdown } from "discourse/tests/helpers/rich-editor-helper";
module("Integration | Component | RichEditorExtension", function (hooks) {
setupRenderingTest(hooks);
const testCases = {
"event alone": [
[
`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\n[/event]\n`,
(assert) => {
assert
.dom(".composer-event-node")
.exists("Event node should be rendered");
assert
.dom(".composer-event__status")
.hasText("Public", "Status should be displayed");
assert
.dom(".composer-event__date-display")
.exists("Date should be displayed");
},
`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\n[/event]\n`,
],
],
"event with content around": [
[
`Hello world\n\n[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\n[/event]\nGoodbye world`,
(assert) => {
assert
.dom("p")
.exists({ count: 2 }, "Should have paragraphs around event");
assert
.dom(".composer-event-node")
.exists("Event node should be rendered");
assert
.dom(".composer-event__status")
.hasText("Public", "Status should be displayed");
},
`Hello world\n\n[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\n[/event]\nGoodbye world`,
],
],
"event with content inside": [
[
`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris"]\ntest\n[/event]\n`,
(assert) => {
assert
.dom(".composer-event-node")
.exists("Event node should be rendered");
assert
.dom(".composer-event__status")
.hasText("Public", "Status should be displayed");
},
`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris]\ntest\n\n[/event]\n`,
],
],
};
Object.entries(testCases).forEach(([name, tests]) => {
tests.forEach(([markdown, expectedHtml, expectedMarkdown]) => {
test(name, async function (assert) {
await testMarkdown(assert, markdown, expectedHtml, expectedMarkdown);
});
});
});
test("event preserves allowed custom fields", async function (assert) {
this.siteSettings.discourse_post_event_allowed_custom_fields =
"fancy_field";
await testMarkdown(
assert,
`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris" fancyField="hello world"]\n[/event]\n`,
(a) => {
a.dom(".composer-event-node").exists("Event node should be rendered");
},
`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris fancyField="hello world"]\n[/event]\n`
);
});
test("event preserves custom fields with uppercase letters", async function (assert) {
this.siteSettings.discourse_post_event_allowed_custom_fields = "dress_CODE";
await testMarkdown(
assert,
`[event start="2025-03-21 15:41" status="public" timezone="Europe/Paris" dressCode="black tie"]\n[/event]\n`,
(a) => {
a.dom(".composer-event-node").exists("Event node should be rendered");
},
`[event start="2025-03-21 15:41" status=public timezone=Europe/Paris dressCode="black tie"]\n[/event]\n`
);
});
});