mirror of
https://github.com/discourse/discourse.git
synced 2026-08-09 21:45:25 +08:00
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.
85 lines
2.3 KiB
JavaScript
Vendored
85 lines
2.3 KiB
JavaScript
Vendored
import { getOwner } from "@ember/owner";
|
|
import { click } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import {
|
|
setupRichEditor,
|
|
testMarkdown,
|
|
} from "discourse/tests/helpers/rich-editor-helper";
|
|
|
|
module(
|
|
"Integration | Component | prosemirror-editor - math extension",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("renders inline math and preserves markdown", async function (assert) {
|
|
this.siteSettings.discourse_math_enabled = true;
|
|
|
|
const markdown = "Inline $E=mc^2$ math.";
|
|
|
|
await testMarkdown(
|
|
assert,
|
|
markdown,
|
|
() => {
|
|
assert.dom("span.composer-math-node").exists();
|
|
assert.dom(".math-node-content").hasText("E=mc^2");
|
|
},
|
|
markdown
|
|
);
|
|
});
|
|
|
|
test("renders block math and preserves markdown", async function (assert) {
|
|
this.siteSettings.discourse_math_enabled = true;
|
|
|
|
const markdown = "$$\nE=mc^2\n$$";
|
|
const expectedMarkdown = "$$\nE=mc^2\n$$\n\n";
|
|
|
|
await testMarkdown(
|
|
assert,
|
|
markdown,
|
|
() => {
|
|
assert.dom("div.composer-math-node").exists();
|
|
assert
|
|
.dom("div.composer-math-node .math-node-content")
|
|
.hasText("E=mc^2");
|
|
},
|
|
expectedMarkdown
|
|
);
|
|
});
|
|
|
|
test("edits math via modal", async function (assert) {
|
|
this.siteSettings.discourse_math_enabled = true;
|
|
|
|
const markdown = "Inline $E=mc^2$ math.";
|
|
const modalService = getOwner(this).lookup("service:modal");
|
|
const originalShow = modalService.show;
|
|
let modalModel;
|
|
|
|
modalService.show = (_component, { model } = {}) => {
|
|
modalModel = model;
|
|
};
|
|
|
|
try {
|
|
const [editor] = await setupRichEditor(assert, markdown);
|
|
|
|
await click(".math-node-edit-button");
|
|
|
|
assert.notStrictEqual(
|
|
modalModel,
|
|
undefined,
|
|
"Opens the math edit modal"
|
|
);
|
|
|
|
modalModel.onApply("a^2 + b^2 = c^2");
|
|
|
|
assert.strictEqual(
|
|
editor.value,
|
|
"Inline $a^2 + b^2 = c^2$ math.",
|
|
"Markdown updates after editing math"
|
|
);
|
|
} finally {
|
|
modalService.show = originalShow;
|
|
}
|
|
});
|
|
}
|
|
);
|