diff --git a/ui/src/components/InlineEditor.test.tsx b/ui/src/components/InlineEditor.test.tsx index ddf99936..1f474f7b 100644 --- a/ui/src/components/InlineEditor.test.tsx +++ b/ui/src/components/InlineEditor.test.tsx @@ -1,27 +1,171 @@ // @vitest-environment jsdom -import { act } from "react"; +import { act, forwardRef, useImperativeHandle, useRef } from "react"; +import { createRoot } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import { queueContainedBlurCommit } from "./InlineEditor"; vi.mock("./MarkdownEditor", () => ({ - MarkdownEditor: () => null, -})); - -vi.mock("../hooks/useAutosaveIndicator", () => ({ - useAutosaveIndicator: () => ({ - state: "idle", - markDirty: () => {}, - reset: () => {}, - runSave: async (save: () => Promise) => { - await save(); - }, + MarkdownEditor: forwardRef< + { focus: () => void }, + { value: string; onChange: (value: string) => void } + >(function MarkdownEditorMock(props, ref) { + const taRef = useRef(null); + useImperativeHandle(ref, () => ({ + focus: () => taRef.current?.focus(), + })); + return ( +