import { composeStories } from "@storybook/react" import { expect, userEvent, waitFor } from "storybook/test" import { test } from "vitest" import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts" import { mountStory } from "../mountStory.testHelpers.ts" import { expectAgentDrivable } from "../testing/index.ts" import * as stories from "./MarkdownEditor.stories.tsx" const { AllStates, AllVariants, Blank, Playground, Interactive, NoUpload, Responsive, } = composeStories(stories) type Canvas = Awaited< ReturnType >["canvas"] const getEditor = (canvas: Canvas, name: string) => canvas.getByRole("textbox", { name, }) as HTMLTextAreaElement /** * A **harness** artifact, and it exists nowhere in the product. * * `user-event` keeps its own shadow copy of a control's value and * applies the next keystroke against *that* rather than against the * DOM. An edit the component made through * `document.execCommand("insertText")` — which is the entire reason * the native undo stack survives — never passes through the `value` * setter it intercepts, so its copy goes stale and the next typed * character lands at an offset from two edits ago. * * Re-assigning `.value` is what resets that copy. A browser has no * second opinion about what is in a textarea, so nothing like this * is needed outside a test. */ const resyncHarness = (editor: HTMLTextAreaElement) => { const { selectionEnd, selectionStart, value } = editor editor.value = value editor.setSelectionRange(selectionStart, selectionEnd) } /** * The surface is a real `