Skip to content

Build your personal knowledge base with Trilium Notes

test(ckeditor5): cover the reachable gaps in the collapsible plugin

Elian Doranb712e1b33daa
diff --git a/packages/ckeditor5/src/plugins/collapsible/block_drag_handle.spec.ts b/packages/ckeditor5/src/plugins/collapsible/block_drag_handle.spec.ts
index a4c1c848de..f4930c8280 100644
--- a/packages/ckeditor5/src/plugins/collapsible/block_drag_handle.spec.ts
+++ b/packages/ckeditor5/src/plugins/collapsible/block_drag_handle.spec.ts
@@ -166,7 +166,61 @@ describe("BlockDragHandle", () => {
});
});
+ describe("finding a target", () => {
+ it("falls back to the nearest top-level block when the pointer is in the margin", () => {
+ setModelData(editor.model, "<paragraph>one</paragraph><paragraph>two[]</paragraph>");
+ const rect = topLevelDom(0).getBoundingClientRect();
+ // To the left of the editable, level with the first block: no element under the
+ // cursor, so the nearest-child fallback picks it by vertical distance.
+ const margin = { x: rect.left - 40, y: rect.top + 2 };
+
+ handle.start(0, 0, modelBlock(1), root);
+ mouse("mousemove", margin.x, margin.y);
+ mouse("mouseup", margin.x, margin.y);
+
+ expect(getModelData(editor.model, { withoutSelection: true })).toBe(
+ "<paragraph>two</paragraph><paragraph>one</paragraph>"
+ );
+ });
+ });
+
describe("target refinement", () => {
+ it("keeps the original target when refineTarget returns it unchanged", () => {
+ setModelData(editor.model, "<paragraph>one[]</paragraph><paragraph>two</paragraph>");
+ const refineTarget = vi.fn((model) => model);
+ const refining = new BlockDragHandle({ editor, indicatorClass: INDICATOR_CLASS, refineTarget });
+ const rect = topLevelDom(1).getBoundingClientRect();
+ const lowerHalf = { x: rect.left + 5, y: rect.bottom - 2 };
+
+ refining.start(0, 0, modelBlock(0), root);
+ mouse("mousemove", lowerHalf.x, lowerHalf.y);
+ mouse("mouseup", lowerHalf.x, lowerHalf.y);
+
+ expect(refineTarget).toHaveBeenCalled();
+ expect(getModelData(editor.model, { withoutSelection: true })).toBe(
+ "<paragraph>two</paragraph><paragraph>one</paragraph>"
+ );
+ });
+
+ it("tolerates a refineTarget that returns something with no rendered DOM", () => {
+ setModelData(editor.model, "<paragraph>one[]</paragraph><paragraph>two</paragraph>");
+ // A detached element maps to no DOM, so the original element's rect is kept.
+ const detached = editor.model.change((writer) => writer.createElement("paragraph"));
+ const refining = new BlockDragHandle({
+ editor,
+ indicatorClass: INDICATOR_CLASS,
+ refineTarget: () => detached
+ });
+ const target = blockCentre(1);
+
+ refining.start(0, 0, modelBlock(0), root);
+
+ expect(() => {
+ mouse("mousemove", target.x, target.y);
+ mouse("mouseup", target.x, target.y);
+ }).not.toThrow();
+ });
+
it("re-routes the target through refineTarget", () => {
setModelData(
editor.model,
diff --git a/packages/ckeditor5/src/plugins/collapsible/enter_and_arrow.spec.ts b/packages/ckeditor5/src/plugins/collapsible/enter_and_arrow.spec.ts
new file mode 100644
index 0000000000..6c2613cc45
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/collapsible/enter_and_arrow.spec.ts
@@ -0,0 +1,218 @@
+import { _getModelData as getModelData, _setModelData as setModelData, ClassicEditor, Essentials, Paragraph } from "ckeditor5";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { createTestEditor, getEditorElement } from "../../../test/editor-kit.js";
+import CollapsibleEditing from "./collapsible_editing.js";
+
+/**
+ * Enter inside a title and the ArrowDown escape out of one. Both depend on where the caret sits,
+ * and ArrowDown additionally consults the caret's real position on screen, so these run against a
+ * laid-out editable with a genuine DOM selection.
+ */
+describe("collapsible Enter and ArrowDown", () => {
+ let editor: ClassicEditor;
+ let root: HTMLElement;
+
+ beforeEach(async () => {
+ editor = await createTestEditor([Essentials, Paragraph, CollapsibleEditing]);
+ getEditorElement(editor).style.cssText = "width: 600px; position: absolute; top: 0; left: 0;";
+ root = editor.editing.view.getDomRoot() as HTMLElement;
+ });
+
+ function fireEnter(): void {
+ editor.editing.view.document.fire("enter", { preventDefault: vi.fn(), isSoft: false });
+ }
+
+ /**
+ * Put a real DOM selection where the model selection is, so `caretAtVisualEdge` measures an
+ * actual caret rectangle rather than bailing out on an empty selection.
+ */
+ function syncDomSelection(): void {
+ editor.editing.view.forceRender();
+ const domSelection = document.getSelection();
+ const viewSelection = editor.editing.view.document.selection;
+ const viewPosition = viewSelection.getFirstPosition();
+ if (!domSelection || !viewPosition) {
+ return;
+ }
+ const domPosition = editor.editing.view.domConverter.viewPositionToDom(viewPosition);
+ if (!domPosition) {
+ return;
+ }
+ const range = document.createRange();
+ range.setStart(domPosition.parent, domPosition.offset);
+ range.collapse(true);
+ domSelection.removeAllRanges();
+ domSelection.addRange(range);
+ }
+
+ function fireDomKey(key: string, init: KeyboardEventInit = {}): KeyboardEvent {
+ const event = new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...init });
+ root.dispatchEvent(event);
+ return event;
+ }
+
+ describe("Enter in a title", () => {
+ it("inserts a paragraph before the collapsible when the caret is at the start", () => {
+ setModelData(editor.model, "<details open=\"true\"><summary>[]Title</summary><paragraph>body</paragraph></details>");
+
+ fireEnter();
+
+ expect(getModelData(editor.model)).toBe(
+ "<paragraph>[]</paragraph>" +
+ "<details open=\"true\"><summary>Title</summary><paragraph>body</paragraph></details>"
+ );
+ });
+
+ it("drops a non-collapsed selection in the title before acting on it", () => {
+ setModelData(editor.model, "<details open=\"true\"><summary>[Title]</summary><paragraph>body</paragraph></details>");
+
+ fireEnter();
+
+ // The whole title was selected, so deleting it leaves the caret at the start —
+ // which then takes the "paragraph before" path.
+ expect(getModelData(editor.model)).toBe(
+ "<paragraph>[]</paragraph>" +
+ "<details open=\"true\"><summary></summary><paragraph>body</paragraph></details>"
+ );
+ });
+
+ it("opens a fresh first body block when the caret is at the end of an expanded title", () => {
+ setModelData(editor.model, "<details open=\"true\"><summary>Title[]</summary><paragraph>body</paragraph></details>");
+
+ fireEnter();
+
+ expect(getModelData(editor.model)).toBe(
+ "<details open=\"true\"><summary>Title</summary>" +
+ "<paragraph>[]</paragraph><paragraph>body</paragraph></details>"
+ );
+ });
+
+ it("reuses an empty block already sitting at that spot instead of stacking another", () => {
+ setModelData(
+ editor.model,
+ "<details open=\"true\"><summary>Title[]</summary><paragraph></paragraph></details>"
+ );
+
+ fireEnter();
+
+ // One empty paragraph, not two.
+ expect(getModelData(editor.model)).toBe(
+ "<details open=\"true\"><summary>Title</summary><paragraph>[]</paragraph></details>"
+ );
+ });
+
+ it("escapes past a collapsed collapsible when the caret is at the end of its title", () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+
+ fireEnter();
+
+ expect(getModelData(editor.model)).toBe(
+ "<details><summary>Title</summary><paragraph>body</paragraph></details>" +
+ "<paragraph>[]</paragraph>"
+ );
+ });
+ });
+
+ describe("Enter in an empty trailing body block", () => {
+ it("moves into the paragraph that already follows the collapsible", () => {
+ setModelData(
+ editor.model,
+ "<details open=\"true\"><summary>T</summary><paragraph>body</paragraph><paragraph>[]</paragraph></details>" +
+ "<paragraph>after</paragraph>"
+ );
+
+ fireEnter();
+
+ expect(getModelData(editor.model)).toBe(
+ "<details open=\"true\"><summary>T</summary><paragraph>body</paragraph></details>" +
+ "<paragraph>[]after</paragraph>"
+ );
+ });
+
+ it("leaves a body block alone when it is not the last one", () => {
+ setModelData(
+ editor.model,
+ "<details open=\"true\"><summary>T</summary><paragraph>[]</paragraph><paragraph>body</paragraph></details>"
+ );
+
+ fireEnter();
+
+ // Native Enter handled it: still inside the collapsible.
+ expect(getModelData(editor.model, { withoutSelection: true })).toContain("<summary>T</summary>");
+ expect(editor.model.document.getRoot()?.childCount).toBe(1);
+ });
+ });
+
+ describe("ArrowDown out of a title", () => {
+ it("jumps into the body of an expanded collapsible", () => {
+ setModelData(editor.model, "<details open=\"true\"><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ syncDomSelection();
+
+ const event = fireDomKey("ArrowDown");
+
+ expect(event.defaultPrevented).toBe(true);
+ expect(getModelData(editor.model)).toBe(
+ "<details open=\"true\"><summary>Title</summary><paragraph>[]body</paragraph></details>"
+ );
+ });
+
+ it("skips past a collapsed collapsible to the block after it", () => {
+ setModelData(
+ editor.model,
+ "<details><summary>Title[]</summary><paragraph>body</paragraph></details><paragraph>after</paragraph>"
+ );
+ syncDomSelection();
+
+ fireDomKey("ArrowDown");
+
+ expect(getModelData(editor.model)).toBe(
+ "<details><summary>Title</summary><paragraph>body</paragraph></details><paragraph>[]after</paragraph>"
+ );
+ });
+
+ it("does nothing when there is nowhere to go", () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ syncDomSelection();
+
+ const event = fireDomKey("ArrowDown");
+
+ expect(event.defaultPrevented).toBe(false);
+ });
+
+ it("ignores ArrowDown outside a title", () => {
+ setModelData(editor.model, "<paragraph>plain[]</paragraph>");
+ syncDomSelection();
+
+ const event = fireDomKey("ArrowDown");
+
+ expect(event.defaultPrevented).toBe(false);
+ });
+
+ it("ignores a modified or extended ArrowDown", () => {
+ setModelData(editor.model, "<details open=\"true\"><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ syncDomSelection();
+
+ expect(fireDomKey("ArrowDown", { shiftKey: true }).defaultPrevented).toBe(false);
+ expect(fireDomKey("ArrowDown", { ctrlKey: true }).defaultPrevented).toBe(false);
+ expect(fireDomKey("ArrowDown", { altKey: true }).defaultPrevented).toBe(false);
+ });
+ });
+
+ describe("Ctrl+Enter in a title", () => {
+ it("toggles the collapsible", () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+
+ const event = fireDomKey("Enter", { ctrlKey: true });
+
+ expect(event.defaultPrevented).toBe(true);
+ expect(getModelData(editor.model, { withoutSelection: true })).toContain("open=\"true\"");
+ });
+
+ it("is ignored outside a title", () => {
+ setModelData(editor.model, "<paragraph>plain[]</paragraph>");
+
+ expect(fireDomKey("Enter", { ctrlKey: true }).defaultPrevented).toBe(false);
+ });
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/collapsible/find_reveal.spec.ts b/packages/ckeditor5/src/plugins/collapsible/find_reveal.spec.ts
index 195d519894..34fef33340 100644
--- a/packages/ckeditor5/src/plugins/collapsible/find_reveal.spec.ts
+++ b/packages/ckeditor5/src/plugins/collapsible/find_reveal.spec.ts
@@ -38,6 +38,29 @@ describe("collapsible find-in-note reveal", () => {
"<details class=\"trilium-collapsible\"><summary>A</summary><p>needle one</p></details>" +
"<details class=\"trilium-collapsible\"><summary>B</summary><p>needle two</p></details>";
+ it("stays force-open through a reconversion while the match is still revealed", () => {
+ editor.setData("<details class=\"trilium-collapsible\"><summary>T</summary><p>needle in body</p></details>");
+ editor.execute("find", "needle");
+ expect(detailsDom().open).toBe(true);
+ expect(isTransient()).toBe(true);
+
+ // Adding a body block changes the <details>'s children, which reconverts the whole
+ // structure in the editing view. The structure callback has to re-apply the transient
+ // open, or the block would snap shut under the highlight.
+ model.change((writer) => {
+ const details = model.document.getRoot()?.getChild(0);
+ if (details?.is("element")) {
+ writer.insertElement("paragraph", writer.createPositionAt(details, "end"));
+ }
+ });
+ editor.editing.view.forceRender();
+
+ expect(detailsDom().open).toBe(true);
+ expect(isTransient()).toBe(true);
+ // Still nothing persisted.
+ expect(getModelData(model, { withoutSelection: true })).not.toContain("open=");
+ });
+
it("opens a collapsed block to reveal a match, marks it transient, and leaves the saved HTML untouched", () => {
editor.setData("<details class=\"trilium-collapsible\"><summary>T</summary><p>needle in body</p></details>");
expect(detailsDom().open).toBe(false);
diff --git a/packages/ckeditor5/src/plugins/collapsible/structure_and_conversion.spec.ts b/packages/ckeditor5/src/plugins/collapsible/structure_and_conversion.spec.ts
new file mode 100644
index 0000000000..9789d19de7
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/collapsible/structure_and_conversion.spec.ts
@@ -0,0 +1,96 @@
+import { _getModelData as getModelData, _setModelData as setModelData, ClassicEditor, Essentials, Paragraph } from "ckeditor5";
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { createTestEditor, getEditorElement } from "../../../test/editor-kit.js";
+import CollapsibleEditing from "./collapsible_editing.js";
+
+describe("collapsible structure and conversion", () => {
+ let editor: ClassicEditor;
+ let root: HTMLElement;
+
+ beforeEach(async () => {
+ editor = await createTestEditor([Essentials, Paragraph, CollapsibleEditing]);
+ getEditorElement(editor).style.cssText = "width: 600px; position: absolute; top: 0; left: 0;";
+ root = editor.editing.view.getDomRoot() as HTMLElement;
+ });
+
+ describe("editing-view downcast", () => {
+ it("keeps an expanded collapsible open through the reconvert a body edit triggers", () => {
+ setModelData(
+ editor.model,
+ "<details open=\"true\"><summary>T</summary><paragraph>body[]</paragraph></details>"
+ );
+ editor.editing.view.forceRender();
+ expect(root.querySelector("details")?.open).toBe(true);
+
+ // Editing a body block rebuilds the whole <details> in the editing view.
+ editor.model.change((writer) => {
+ const details = editor.model.document.getRoot()?.getChild(0);
+ const body = details?.is("element") ? details.getChild(1) : null;
+ if (body?.is("element")) {
+ writer.insertText("!", body, "end");
+ }
+ });
+ editor.editing.view.forceRender();
+
+ // Still open — the renderer seeds `open` from the model rather than defaulting closed.
+ expect(root.querySelector("details")?.open).toBe(true);
+ });
+
+ it("renders a collapsed collapsible closed", () => {
+ setModelData(editor.model, "<details><summary>T</summary><paragraph>body[]</paragraph></details>");
+ editor.editing.view.forceRender();
+
+ expect(root.querySelector("details")?.open).toBe(false);
+ });
+ });
+
+ describe("structural post-fixer", () => {
+ it("removes a <summary> inserted outside any collapsible", () => {
+ setModelData(editor.model, "<paragraph>foo[]</paragraph>");
+
+ editor.model.change((writer) => {
+ const root_ = editor.model.document.getRoot();
+ const stray = writer.createElement("summary");
+ writer.insert(stray, writer.createPositionAt(root_ ?? stray, "end"));
+ });
+
+ expect(getModelData(editor.model, { withoutSelection: true })).not.toContain("<summary>");
+ });
+
+ it("removes an empty collapsible that arrives as part of a multi-block insert", () => {
+ setModelData(editor.model, "<paragraph>foo[]</paragraph>");
+
+ editor.model.change((writer) => {
+ const root_ = editor.model.document.getRoot();
+ if (!root_) {
+ return;
+ }
+ // Two top-level nodes in one insert, so the post-fixer walks the run via
+ // nextSibling rather than looking at a single node.
+ const fragment = writer.createDocumentFragment();
+ writer.append(writer.createElement("paragraph"), fragment);
+ writer.append(writer.createElement("details"), fragment);
+ writer.insert(fragment, writer.createPositionAt(root_, "end"));
+ });
+
+ expect(getModelData(editor.model, { withoutSelection: true })).not.toContain("<details>");
+ });
+
+ it("removes a collapsible left empty after its last child is deleted", () => {
+ setModelData(
+ editor.model,
+ "<paragraph>keep[]</paragraph><details><summary>T</summary><paragraph>body</paragraph></details>"
+ );
+
+ editor.model.change((writer) => {
+ const details = editor.model.document.getRoot()?.getChild(1);
+ if (details?.is("element")) {
+ writer.remove(writer.createRangeIn(details));
+ }
+ });
+
+ expect(getModelData(editor.model, { withoutSelection: true })).toBe("<paragraph>keep</paragraph>");
+ });
+ });
+});
diff --git a/packages/ckeditor5/src/plugins/collapsible/summary_affordances.spec.ts b/packages/ckeditor5/src/plugins/collapsible/summary_affordances.spec.ts
index 414db971b4..a78b3993ff 100644
--- a/packages/ckeditor5/src/plugins/collapsible/summary_affordances.spec.ts
+++ b/packages/ckeditor5/src/plugins/collapsible/summary_affordances.spec.ts
@@ -124,6 +124,37 @@ describe("collapsible summary affordances", () => {
expect(editor.model.document.selection.getSelectedElement()).toBeNull();
});
+ it("drops onto a plain paragraph as-is, with no retargeting", () => {
+ setModelData(
+ editor.model,
+ "<paragraph>first</paragraph>" +
+ "<details open=\"true\"><summary>T</summary><paragraph>body[]</paragraph></details>"
+ );
+
+ const source = handleDom();
+ const start = source.getBoundingClientRect();
+ const firstBlock = root.children[0];
+ if (!(firstBlock instanceof HTMLElement)) {
+ throw new Error("Expected a rendered first block.");
+ }
+ const targetRect = firstBlock.getBoundingClientRect();
+
+ source.dispatchEvent(new MouseEvent("mousedown", {
+ button: 0, clientX: start.left, clientY: start.top, bubbles: true, cancelable: true
+ }));
+ document.dispatchEvent(new MouseEvent("mousemove", {
+ clientX: targetRect.left + 20, clientY: targetRect.top + 1, bubbles: true
+ }));
+ document.dispatchEvent(new MouseEvent("mouseup", {
+ clientX: targetRect.left + 20, clientY: targetRect.top + 1, bubbles: true
+ }));
+
+ // The paragraph is not a summary, so refineTarget hands it back untouched and the
+ // collapsible lands before it.
+ const data = getModelData(editor.model, { withoutSelection: true });
+ expect(data.indexOf("<details")).toBeLessThan(data.indexOf("first"));
+ });
+
it("reorders relative to the whole collapsible when dropped on another one's summary", () => {
setModelData(
editor.model,
diff --git a/packages/ckeditor5/src/plugins/collapsible/summary_hints.spec.ts b/packages/ckeditor5/src/plugins/collapsible/summary_hints.spec.ts
new file mode 100644
index 0000000000..a43f0ed8c8
--- /dev/null
+++ b/packages/ckeditor5/src/plugins/collapsible/summary_hints.spec.ts
@@ -0,0 +1,154 @@
+import { _setModelData as setModelData, ClassicEditor, Essentials, Paragraph } from "ckeditor5";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { createTestEditor, getEditorElement } from "../../../test/editor-kit.js";
+import CollapsibleEditing from "./collapsible_editing.js";
+
+/**
+ * The hint popup attached to each `<summary>`. Visibility is derived from two independent drivers,
+ * hover and caret, so the interesting cases are the transitions between them.
+ */
+describe("collapsible summary hints", () => {
+ let editor: ClassicEditor;
+ let root: HTMLElement;
+
+ async function createEditor(extraConfig: Record<string, unknown> = {}): Promise<void> {
+ editor = await createTestEditor([Essentials, Paragraph, CollapsibleEditing], extraConfig);
+ getEditorElement(editor).style.cssText = "width: 600px; position: absolute; top: 0; left: 0;";
+ root = editor.editing.view.getDomRoot() as HTMLElement;
+ }
+
+ const summaryDom = (index = 0) =>
+ root.querySelectorAll<HTMLElement>("details.trilium-collapsible > summary")[index];
+
+ function hover(target: HTMLElement, type: "mouseenter" | "mouseleave"): void {
+ target.dispatchEvent(new MouseEvent(type, { bubbles: false }));
+ }
+
+ /** Tooltip elements Bootstrap has attached to the document for this editor. */
+ const tooltips = () => document.querySelectorAll(".tooltip, [data-bs-toggle], .text-editor-content-tooltip");
+
+ beforeEach(async () => {
+ await createEditor();
+ });
+
+ it("does not throw when the pointer enters and leaves a title", () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ editor.editing.view.forceRender();
+ const summary = summaryDom();
+
+ expect(() => {
+ hover(summary, "mouseenter");
+ hover(summary, "mouseleave");
+ }).not.toThrow();
+ });
+
+ it("keeps the hint alive across a hover that starts while the caret is elsewhere", () => {
+ setModelData(
+ editor.model,
+ "<details><summary>Title</summary><paragraph>body</paragraph></details><paragraph>out[]side</paragraph>"
+ );
+ editor.editing.view.forceRender();
+ const summary = summaryDom();
+
+ hover(summary, "mouseenter");
+ // Now move the caret into the title as well — caret should take over from hover.
+ editor.model.change((writer) => {
+ const details = editor.model.document.getRoot()?.getChild(0);
+ const title = details?.is("element") ? details.getChild(0) : null;
+ if (title?.is("element")) {
+ writer.setSelection(title, 0);
+ }
+ });
+ hover(summary, "mouseleave");
+
+ expect(summaryDom()).toBe(summary);
+ });
+
+ it("rebinds its listeners when a reconvert replaces the summary's DOM node", () => {
+ setModelData(
+ editor.model,
+ "<details open=\"true\"><summary>Title</summary><paragraph>body[]</paragraph></details>"
+ );
+ editor.editing.view.forceRender();
+ const before = summaryDom();
+
+ hover(before, "mouseenter");
+
+ // Changing a body block triggers a reconvert of the whole <details>.
+ editor.model.change((writer) => {
+ const details = editor.model.document.getRoot()?.getChild(0);
+ const body = details?.is("element") ? details.getChild(1) : null;
+ if (body?.is("element")) {
+ writer.insertText("more", body, "end");
+ }
+ });
+ editor.editing.view.forceRender();
+
+ const after = summaryDom();
+ expect(after).toBeInstanceOf(HTMLElement);
+ // Hovering the fresh node must still be wired up.
+ expect(() => {
+ hover(after, "mouseenter");
+ hover(after, "mouseleave");
+ }).not.toThrow();
+ });
+
+ it("reaps the state when the collapsible is removed", () => {
+ setModelData(
+ editor.model,
+ "<details><summary>Title</summary><paragraph>body</paragraph></details><paragraph>[]after</paragraph>"
+ );
+ editor.editing.view.forceRender();
+ expect(summaryDom()).toBeInstanceOf(HTMLElement);
+
+ editor.model.change((writer) => {
+ const details = editor.model.document.getRoot()?.getChild(0);
+ if (details?.is("element")) {
+ writer.remove(details);
+ }
+ });
+ editor.editing.view.forceRender();
+
+ expect(summaryDom()).toBeUndefined();
+ expect(() => editor.editing.view.forceRender()).not.toThrow();
+ });
+
+ it("skips all hint wiring when content hints are switched off", async () => {
+ await editor.destroy();
+ await createEditor({ contentHintsEnabled: false });
+
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ editor.editing.view.forceRender();
+ const summary = summaryDom();
+ const before = tooltips().length;
+
+ hover(summary, "mouseenter");
+
+ expect(tooltips().length).toBe(before);
+ });
+
+ it("shows the drag handle's own hint on hover", () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ editor.editing.view.forceRender();
+ const handle = root.querySelector<HTMLElement>(".trilium-collapsible-handle");
+ if (!handle) {
+ throw new Error("Expected a rendered drag handle.");
+ }
+
+ expect(() => {
+ hover(handle, "mouseenter");
+ hover(handle, "mouseleave");
+ }).not.toThrow();
+ });
+
+ it("tears everything down without leaking on destroy", async () => {
+ setModelData(editor.model, "<details><summary>Title[]</summary><paragraph>body</paragraph></details>");
+ editor.editing.view.forceRender();
+ hover(summaryDom(), "mouseenter");
+
+ await expect(editor.destroy()).resolves.not.toThrow();
+ // A second destroy from the kit's afterEach must stay harmless.
+ vi.restoreAllMocks();
+ });
+});