@open-elements/ui 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +153 -18
  2. package/dist/components/capability-status.d.ts +10 -0
  3. package/dist/components/capability-status.d.ts.map +1 -0
  4. package/dist/components/capability-status.js +12 -0
  5. package/dist/components/capability-status.js.map +1 -0
  6. package/dist/components/markdown-editor.d.ts +1 -1
  7. package/dist/components/markdown-editor.d.ts.map +1 -1
  8. package/dist/components/markdown-editor.js +131 -44
  9. package/dist/components/markdown-editor.js.map +1 -1
  10. package/dist/components/markdown-view.d.ts +1 -1
  11. package/dist/components/markdown-view.d.ts.map +1 -1
  12. package/dist/components/markdown-view.js +110 -27
  13. package/dist/components/markdown-view.js.map +1 -1
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/markdown-extensions.d.ts +48 -0
  19. package/dist/lib/markdown-extensions.d.ts.map +1 -0
  20. package/dist/lib/markdown-extensions.js +73 -0
  21. package/dist/lib/markdown-extensions.js.map +1 -0
  22. package/dist/tsconfig.build.tsbuildinfo +1 -1
  23. package/dist/types/index.d.ts +17 -0
  24. package/dist/types/index.d.ts.map +1 -1
  25. package/package.json +41 -24
  26. package/src/components/__tests__/capability-status.test.tsx +82 -0
  27. package/src/components/__tests__/markdown-editor.test.tsx +226 -22
  28. package/src/components/__tests__/markdown-view.test.tsx +274 -21
  29. package/src/components/capability-status.tsx +63 -0
  30. package/src/components/markdown-editor.tsx +185 -79
  31. package/src/components/markdown-view.tsx +133 -28
  32. package/src/index.ts +3 -0
  33. package/src/lib/__tests__/markdown-extensions.test.ts +290 -0
  34. package/src/lib/markdown-extensions.ts +107 -0
  35. package/src/test/setup.ts +29 -0
  36. package/src/types/__tests__/markdown-toolbar-action.test.ts +34 -0
  37. package/src/types/index.ts +32 -0
@@ -46,12 +46,29 @@ export interface UserMultiSelectProps {
46
46
  readonly disabledIds?: readonly string[];
47
47
  readonly translations: UserMultiSelectTranslations;
48
48
  }
49
+ /**
50
+ * A single action offered in the {@link MarkdownEditorProps.toolbar}. Names follow
51
+ * the underlying TipTap node/mark names so the mapping to commands is obvious.
52
+ * Unlink is deliberately absent — it is rendered contextually as part of `"link"`.
53
+ */
54
+ export type MarkdownToolbarAction = "bold" | "italic" | "strike" | "code" | "link" | "h1" | "h2" | "h3" | "bulletList" | "orderedList" | "taskList" | "blockquote" | "codeBlock" | "horizontalRule";
49
55
  export interface MarkdownEditorProps {
50
56
  readonly value: string;
51
57
  readonly onChange: (value: string) => void;
52
58
  readonly placeholder?: string;
59
+ /** Actions offered in the toolbar, in render order. Defaults to `["bold", "italic"]`. */
60
+ readonly toolbar?: readonly MarkdownToolbarAction[];
53
61
  }
54
62
  export interface MarkdownViewProps {
55
63
  readonly content: string;
64
+ /**
65
+ * Called when the reader toggles a task list checkbox, with the complete
66
+ * updated Markdown. Omit to render checkboxes as read-only.
67
+ *
68
+ * Return a Promise to have the view disable interaction until it settles and
69
+ * revert the document if it rejects. Return nothing (`void`) to apply the
70
+ * toggle without a busy state or rollback.
71
+ */
72
+ readonly onChange?: (markdown: string) => void | Promise<void>;
56
73
  }
57
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YA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C;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAC;CACpD;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAC7B,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,YAAY,GACZ,aAAa,GACb,UAAU,GACV,YAAY,GACZ,WAAW,GACX,gBAAgB,CAAC;AAErB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,yFAAyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACrD;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-elements/ui",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Shared UI component library for Open Elements applications",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,43 +29,56 @@
29
29
  "**/*.css"
30
30
  ],
31
31
  "dependencies": {
32
+ "@tiptap/core": "^3.22.0",
33
+ "@tiptap/extension-list": "^3.22.0",
34
+ "@tiptap/extension-placeholder": "^3.22.0",
35
+ "@tiptap/react": "^3.22.0",
36
+ "@tiptap/starter-kit": "^3.22.0",
32
37
  "class-variance-authority": "^0.7.0",
33
38
  "clsx": "^2.1.0",
34
- "tailwind-merge": "^3.0.0",
35
39
  "date-fns": "^4.1.0",
36
40
  "react-day-picker": "^9.14.0",
37
- "@tiptap/core": "^3.22.0",
38
- "@tiptap/react": "^3.22.0",
39
- "@tiptap/starter-kit": "^3.22.0",
40
- "@tiptap/extension-link": "^3.22.0",
41
- "@tiptap/extension-placeholder": "^3.22.0",
41
+ "tailwind-merge": "^3.0.0",
42
42
  "tiptap-markdown": "^0.9.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "react": "^19.0.0",
46
- "react-dom": "^19.0.0",
47
45
  "@base-ui/react": "^1.3.0",
46
+ "lucide-react": "^0.500.0",
48
47
  "radix-ui": "^1.4.0",
49
- "lucide-react": "^0.500.0"
48
+ "react": "^19.0.0",
49
+ "react-dom": "^19.0.0"
50
50
  },
51
51
  "devDependencies": {
52
+ "@base-ui/react": "^1.3.0",
53
+ "@cyclonedx/cyclonedx-library": "^10.2.0",
54
+ "@eslint/js": "^9.0.0",
55
+ "@storybook/addon-a11y": "^10.5.9",
56
+ "@storybook/addon-docs": "^10.5.9",
57
+ "@storybook/react-vite": "^10.5.9",
58
+ "@tailwindcss/typography": "^0.5.20",
59
+ "@tailwindcss/vite": "^4.3.3",
60
+ "@testing-library/jest-dom": "^6.0.0",
61
+ "@testing-library/react": "^16.0.0",
52
62
  "@types/react": "^19.0.0",
53
63
  "@types/react-dom": "^19.0.0",
54
- "typescript": "^5.0.0",
55
64
  "@vitejs/plugin-react": "^4.0.0",
56
- "vitest": "^3.0.0",
57
- "jsdom": "^26.0.0",
58
- "@testing-library/react": "^16.0.0",
59
- "@testing-library/jest-dom": "^6.0.0",
65
+ "ajv": "^8.20.0",
66
+ "ajv-formats": "^3.0.1",
67
+ "ajv-formats-draft2019": "^1.6.1",
60
68
  "eslint": "^9.0.0",
61
- "@eslint/js": "^9.0.0",
62
- "typescript-eslint": "^8.0.0",
69
+ "jsdom": "^26.0.0",
70
+ "lucide-react": "^0.500.0",
63
71
  "prettier": "^3.0.0",
72
+ "radix-ui": "^1.4.0",
64
73
  "react": "^19.0.0",
65
74
  "react-dom": "^19.0.0",
66
- "@base-ui/react": "^1.3.0",
67
- "radix-ui": "^1.4.0",
68
- "lucide-react": "^0.500.0"
75
+ "storybook": "^10.5.9",
76
+ "tailwindcss": "^4.3.3",
77
+ "tw-animate-css": "^1.4.0",
78
+ "typescript": "^5.0.0",
79
+ "typescript-eslint": "^8.0.0",
80
+ "vite": "^7.3.2",
81
+ "vitest": "^3.0.0"
69
82
  },
70
83
  "scripts": {
71
84
  "build": "tsc -p tsconfig.build.json && pnpm run build:css",
@@ -75,9 +88,13 @@
75
88
  "dev": "tsc -p tsconfig.build.json --watch",
76
89
  "test": "vitest run",
77
90
  "test:watch": "vitest",
78
- "lint": "eslint src/",
79
- "format": "prettier --write src/",
80
- "format:check": "prettier --check src/",
81
- "typecheck": "tsc --noEmit"
91
+ "storybook": "storybook dev -p 6006",
92
+ "build-storybook": "storybook build",
93
+ "lint": "eslint src/ stories/ .storybook/",
94
+ "format": "prettier --write src/ stories/ .storybook/",
95
+ "format:check": "prettier --check src/ stories/ .storybook/",
96
+ "typecheck": "tsc --noEmit",
97
+ "sbom": "node scripts/generate-sbom.mjs",
98
+ "sbom:verify": "node scripts/verify-sbom.mjs"
82
99
  }
83
100
  }
@@ -0,0 +1,82 @@
1
+ import { describe, it, expect, afterEach } from "vitest";
2
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
3
+ import { CapabilityStatus } from "../capability-status.tsx";
4
+ import { TooltipProvider } from "../tooltip.tsx";
5
+
6
+ function renderWithTooltip(ui: React.ReactElement) {
7
+ return render(<TooltipProvider delayDuration={0}>{ui}</TooltipProvider>);
8
+ }
9
+
10
+ afterEach(() => {
11
+ cleanup();
12
+ });
13
+
14
+ describe("CapabilityStatus", () => {
15
+ it("renders a green indicator and the available text when available", () => {
16
+ const { container } = renderWithTooltip(
17
+ <CapabilityStatus
18
+ available
19
+ label="HEIC image decoding"
20
+ availableText="Available"
21
+ unavailableText="Not available"
22
+ />,
23
+ );
24
+
25
+ expect(screen.getByText("HEIC image decoding")).toBeInTheDocument();
26
+ expect(screen.getByText("Available")).toBeInTheDocument();
27
+
28
+ const icon = container.querySelector("svg.lucide-circle-check");
29
+ expect(icon).toBeInTheDocument();
30
+ expect(icon?.getAttribute("class")).toContain("text-oe-green");
31
+ });
32
+
33
+ it("renders a red warning indicator and the unavailable text when not available", () => {
34
+ const { container } = renderWithTooltip(
35
+ <CapabilityStatus
36
+ available={false}
37
+ label="HEIC image decoding"
38
+ availableText="Available"
39
+ unavailableText="Not available"
40
+ hint="HEIC uploads will be rejected with 415 — check Dockerfile"
41
+ />,
42
+ );
43
+
44
+ expect(screen.getByText("Not available")).toBeInTheDocument();
45
+
46
+ const icon = container.querySelector("svg.lucide-triangle-alert");
47
+ expect(icon).toBeInTheDocument();
48
+ expect(icon?.getAttribute("class")).toContain("text-oe-red");
49
+ });
50
+
51
+ it("exposes the hint as a tooltip when a hint is provided", async () => {
52
+ renderWithTooltip(
53
+ <CapabilityStatus
54
+ available={false}
55
+ label="HEIC image decoding"
56
+ availableText="Available"
57
+ unavailableText="Not available"
58
+ hint="HEIC uploads will be rejected with 415 — check Dockerfile"
59
+ />,
60
+ );
61
+
62
+ const trigger = screen.getByRole("note");
63
+ fireEvent.focus(trigger);
64
+
65
+ const tooltip = await screen.findByRole("tooltip");
66
+ expect(tooltip).toHaveTextContent("HEIC uploads will be rejected with 415 — check Dockerfile");
67
+ });
68
+
69
+ it("renders without a tooltip trigger and does not error when no hint is provided", () => {
70
+ renderWithTooltip(
71
+ <CapabilityStatus
72
+ available
73
+ label="HEIC image decoding"
74
+ availableText="Available"
75
+ unavailableText="Not available"
76
+ />,
77
+ );
78
+
79
+ expect(screen.queryByRole("note")).not.toBeInTheDocument();
80
+ expect(screen.getByText("HEIC image decoding")).toBeInTheDocument();
81
+ });
82
+ });
@@ -1,35 +1,239 @@
1
1
  import { describe, it, expect, vi, afterEach } from "vitest";
2
- import { render, cleanup } from "@testing-library/react";
3
-
4
- // Mock TipTap before importing the component
5
- vi.mock("@tiptap/react", () => ({
6
- useEditor: () => null,
7
- EditorContent: () => <div data-testid="editor-content" />,
8
- }));
9
- vi.mock("@tiptap/starter-kit", () => ({ default: { configure: () => ({}) } }));
10
- vi.mock("@tiptap/extension-link", () => ({ default: { configure: () => ({}) } }));
11
- vi.mock("@tiptap/extension-placeholder", () => ({ default: { configure: () => ({}) } }));
12
- vi.mock("tiptap-markdown", () => ({ Markdown: {} }));
13
-
2
+ import { render, cleanup, waitFor, within } from "@testing-library/react";
3
+ import type { Editor } from "@tiptap/core";
4
+ import type { MarkdownToolbarAction } from "../../types/index.ts";
14
5
  import { MarkdownEditor } from "../markdown-editor.tsx";
15
6
 
16
7
  afterEach(cleanup);
17
8
 
18
- describe("MarkdownEditor", () => {
19
- it("mounts without error", () => {
20
- const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
21
- expect(container).toBeTruthy();
9
+ /** Accessible names of the toolbar buttons, in DOM order. */
10
+ function toolbarButtonNames(container: HTMLElement): string[] {
11
+ return Array.from(container.querySelectorAll("button[aria-label]")).map(
12
+ (b) => b.getAttribute("aria-label") ?? "",
13
+ );
14
+ }
15
+
16
+ function dispatchKey(editor: Editor, init: KeyboardEventInit): void {
17
+ editor.view.dom.dispatchEvent(
18
+ new KeyboardEvent("keydown", { bubbles: true, cancelable: true, ...init }),
19
+ );
20
+ }
21
+
22
+ /** The rendered ProseMirror element carries a back-reference to the live editor. */
23
+ function getEditor(container: HTMLElement): Editor {
24
+ const dom = container.querySelector(".ProseMirror") as (HTMLElement & { editor?: Editor }) | null;
25
+ if (!dom?.editor) throw new Error("editor not mounted yet");
26
+ return dom.editor;
27
+ }
28
+
29
+ async function waitForEditor(container: HTMLElement): Promise<Editor> {
30
+ await waitFor(() => expect(container.querySelector(".ProseMirror")).toBeTruthy());
31
+ return getEditor(container);
32
+ }
33
+
34
+ describe("MarkdownEditor — no corruption on open", () => {
35
+ it("does not call onChange when opened with content it used to strip", async () => {
36
+ const onChange = vi.fn();
37
+ const { container } = render(
38
+ <MarkdownEditor value={"- [x] Write the press release"} onChange={onChange} />,
39
+ );
40
+ await waitForEditor(container);
41
+ // Give the sync effect a chance to run before asserting nothing fired.
42
+ await waitFor(() => {
43
+ expect(getEditor(container).storage.markdown.getMarkdown()).toBe(
44
+ "- [x] Write the press release",
45
+ );
46
+ });
47
+ expect(onChange).not.toHaveBeenCalled();
48
+ });
49
+
50
+ it("reports the full document, task list intact, when the paragraph is edited", async () => {
51
+ const onChange = vi.fn();
52
+ const { container } = render(
53
+ <MarkdownEditor value={"- [x] Task\n\nHello"} onChange={onChange} />,
54
+ );
55
+ const editor = await waitForEditor(container);
56
+ onChange.mockClear();
57
+
58
+ // Type a character at the end of the paragraph — same onUpdate path as a keystroke.
59
+ editor.chain().focus("end").insertContent("X").run();
60
+
61
+ await waitFor(() => expect(onChange).toHaveBeenCalled());
62
+ const reported = onChange.mock.calls.at(-1)?.[0] as string;
63
+ expect(reported).toContain("- [x] Task");
64
+ expect(reported).toContain("HelloX");
22
65
  });
23
66
 
24
- it("renders editor content area", () => {
25
- const { container } = render(<MarkdownEditor value="" onChange={() => {}} />);
26
- expect(container.querySelector("[data-testid='editor-content']")).toBeTruthy();
67
+ it("replaces the document when the parent passes a different value", async () => {
68
+ const onChange = vi.fn();
69
+ const { container, rerender } = render(
70
+ <MarkdownEditor value={"# First"} onChange={onChange} />,
71
+ );
72
+ const editor = await waitForEditor(container);
73
+ await waitFor(() => expect(editor.storage.markdown.getMarkdown()).toBe("# First"));
74
+
75
+ rerender(<MarkdownEditor value={"# Second"} onChange={onChange} />);
76
+ await waitFor(() => expect(editor.storage.markdown.getMarkdown()).toBe("# Second"));
27
77
  });
78
+ });
79
+
80
+ describe("MarkdownEditor — toolbar rendering", () => {
81
+ it("renders exactly the declared actions and nothing else", async () => {
82
+ const { container } = render(
83
+ <MarkdownEditor value={"x"} onChange={() => {}} toolbar={["bold", "taskList", "link"]} />,
84
+ );
85
+ await waitForEditor(container);
86
+ expect(toolbarButtonNames(container)).toEqual(["Bold", "Task list", "Link"]);
87
+ });
88
+
89
+ it("renders the buttons in the order of the array", async () => {
90
+ const { container } = render(
91
+ <MarkdownEditor value={"x"} onChange={() => {}} toolbar={["link", "bold"]} />,
92
+ );
93
+ await waitForEditor(container);
94
+ expect(toolbarButtonNames(container)).toEqual(["Link", "Bold"]);
95
+ });
96
+
97
+ it("defaults to exactly Bold and Italic when the prop is omitted", async () => {
98
+ const { container } = render(<MarkdownEditor value={"plain"} onChange={() => {}} />);
99
+ await waitForEditor(container);
100
+ expect(toolbarButtonNames(container)).toEqual(["Bold", "Italic"]);
101
+ });
102
+
103
+ it("renders no toolbar element for an empty array", async () => {
104
+ const { container } = render(<MarkdownEditor value={"x"} onChange={() => {}} toolbar={[]} />);
105
+ await waitForEditor(container);
106
+ expect(container.querySelectorAll("button")).toHaveLength(0);
107
+ expect(container.querySelector(".border-b")).toBeNull();
108
+ });
109
+
110
+ it("renders a duplicated action only once", async () => {
111
+ const { container } = render(
112
+ <MarkdownEditor value={"x"} onChange={() => {}} toolbar={["bold", "bold"]} />,
113
+ );
114
+ await waitForEditor(container);
115
+ expect(toolbarButtonNames(container)).toEqual(["Bold"]);
116
+ });
117
+ });
118
+
119
+ describe("MarkdownEditor — executing actions", () => {
120
+ it("transforms the current block with a heading action", async () => {
121
+ const onChange = vi.fn();
122
+ const { container } = render(
123
+ <MarkdownEditor value={"Title"} onChange={onChange} toolbar={["h2"]} />,
124
+ );
125
+ const editor = await waitForEditor(container);
126
+ editor.commands.focus("end");
127
+ within(container).getByRole("button", { name: "Heading 2" }).click();
128
+ await waitFor(() => expect(onChange.mock.calls.at(-1)?.[0]).toBe("## Title"));
129
+ });
130
+
131
+ it("wraps the current block with a list action", async () => {
132
+ const onChange = vi.fn();
133
+ const { container } = render(
134
+ <MarkdownEditor value={"Call Anna"} onChange={onChange} toolbar={["taskList"]} />,
135
+ );
136
+ const editor = await waitForEditor(container);
137
+ editor.commands.focus("end");
138
+ within(container).getByRole("button", { name: "Task list" }).click();
139
+ await waitFor(() => expect(onChange.mock.calls.at(-1)?.[0]).toBe("- [ ] Call Anna"));
140
+ });
141
+
142
+ it("marks an active action as pressed", async () => {
143
+ const { container } = render(
144
+ <MarkdownEditor value={"**bold**"} onChange={() => {}} toolbar={["bold"]} />,
145
+ );
146
+ const editor = await waitForEditor(container);
147
+ // Set the selection without focus(): focus() scrolls into view, which needs
148
+ // getClientRects — unavailable in jsdom. The toolbar still re-renders on the
149
+ // selection transaction.
150
+ editor.commands.setTextSelection(3);
151
+ await waitFor(() => {
152
+ const bold = within(container).getByRole("button", { name: "Bold" });
153
+ expect(bold.getAttribute("aria-pressed")).toBe("true");
154
+ });
155
+ });
156
+
157
+ it("shows a contextual Unlink button only while the cursor is in a link", async () => {
158
+ const { container } = render(
159
+ <MarkdownEditor
160
+ value={"[the offer](https://example.com) and text"}
161
+ onChange={() => {}}
162
+ toolbar={["link"]}
163
+ />,
164
+ );
165
+ const editor = await waitForEditor(container);
166
+
167
+ editor.commands.setTextSelection(3);
168
+ await waitFor(() => expect(toolbarButtonNames(container)).toContain("Remove link"));
169
+
170
+ // Move the cursor out of the link (to the end of the plain text).
171
+ editor.commands.setTextSelection(editor.state.doc.content.size - 1);
172
+ await waitFor(() => expect(toolbarButtonNames(container)).not.toContain("Remove link"));
173
+ });
174
+ });
175
+
176
+ describe("MarkdownEditor — marks are gated at the button only", () => {
177
+ it("still bolds via Mod-b when the Bold button is absent", async () => {
178
+ const onChange = vi.fn();
179
+ const { container } = render(
180
+ <MarkdownEditor value={"hello"} onChange={onChange} toolbar={["italic"]} />,
181
+ );
182
+ const editor = await waitForEditor(container);
183
+ expect(toolbarButtonNames(container)).toEqual(["Italic"]);
184
+ editor.commands.selectAll();
185
+ dispatchKey(editor, { key: "b", code: "KeyB", ctrlKey: true });
186
+ await waitFor(() => expect(onChange.mock.calls.at(-1)?.[0]).toBe("**hello**"));
187
+ });
188
+
189
+ // The typing/input-rule variant is verified at the extension level
190
+ // (markdown-extensions.test.ts) where literal content can be injected without
191
+ // the component's markdown parsing rewriting the incomplete `**bold*` on load.
192
+ });
193
+
194
+ describe("MarkdownEditor — accessibility", () => {
195
+ it("gives every button a matching aria-label and title", async () => {
196
+ const ALL: readonly MarkdownToolbarAction[] = [
197
+ "bold",
198
+ "italic",
199
+ "strike",
200
+ "code",
201
+ "link",
202
+ "h1",
203
+ "h2",
204
+ "h3",
205
+ "bulletList",
206
+ "orderedList",
207
+ "taskList",
208
+ "blockquote",
209
+ "codeBlock",
210
+ "horizontalRule",
211
+ ];
212
+ const { container } = render(<MarkdownEditor value={"x"} onChange={() => {}} toolbar={ALL} />);
213
+ await waitForEditor(container);
214
+ const buttons = Array.from(container.querySelectorAll("button"));
215
+ expect(buttons).toHaveLength(ALL.length);
216
+ for (const button of buttons) {
217
+ const label = button.getAttribute("aria-label");
218
+ expect(label).toBeTruthy();
219
+ expect(button.getAttribute("title")).toBe(label);
220
+ expect(within(container).getByRole("button", { name: label as string })).toBe(button);
221
+ }
222
+ });
223
+ });
28
224
 
29
- it("accepts placeholder prop without error", () => {
225
+ describe("MarkdownEditor — rendering is independent of the toolbar", () => {
226
+ it("renders undeclared constructs as structure", async () => {
30
227
  const { container } = render(
31
- <MarkdownEditor value="" onChange={() => {}} placeholder="Type here..." />,
228
+ <MarkdownEditor
229
+ value={"# Heading\n\n> quote\n\n- [ ] task"}
230
+ onChange={() => {}}
231
+ toolbar={["bold"]}
232
+ />,
32
233
  );
33
- expect(container).toBeTruthy();
234
+ await waitForEditor(container);
235
+ expect(container.querySelector("h1")).toBeTruthy();
236
+ expect(container.querySelector("blockquote")).toBeTruthy();
237
+ expect(container.querySelector("input[type=checkbox]")).toBeTruthy();
34
238
  });
35
239
  });