import { forwardRef, useImperativeHandle, useRef, useState } from "react"; import { describe, it, expect, vi, beforeEach } from "vitest"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; const mockPush = vi.hoisted(() => vi.fn()); const mockCreateIssue = vi.hoisted(() => vi.fn()); const mockSetDraft = vi.hoisted(() => vi.fn()); const mockClearDraft = vi.hoisted(() => vi.fn()); const mockToastCustom = vi.hoisted(() => vi.fn()); const mockToastDismiss = vi.hoisted(() => vi.fn()); const mockToastError = vi.hoisted(() => vi.fn()); const mockDraftStore = { draft: { title: "", description: "", status: "todo" as const, priority: "none" as const, assigneeType: undefined, assigneeId: undefined, dueDate: null, }, setDraft: mockSetDraft, clearDraft: mockClearDraft, }; vi.mock("../navigation", () => ({ useNavigation: () => ({ push: mockPush }), })); vi.mock("@multica/core/paths", () => ({ useCurrentWorkspace: () => ({ name: "Test Workspace" }), useWorkspacePaths: () => ({ issueDetail: (id: string) => `/ws-test/issues/${id}`, }), })); vi.mock("@multica/core/issues/stores/draft-store", () => ({ useIssueDraftStore: Object.assign( (selector?: (state: typeof mockDraftStore) => unknown) => (selector ? selector(mockDraftStore) : mockDraftStore), { getState: () => mockDraftStore }, ), })); vi.mock("@multica/core/issues/mutations", () => ({ useCreateIssue: () => ({ mutateAsync: mockCreateIssue }), useUpdateIssue: () => ({ mutate: vi.fn() }), })); vi.mock("@multica/core/hooks/use-file-upload", () => ({ useFileUpload: () => ({ uploadWithToast: vi.fn() }), })); vi.mock("@multica/core/api", () => ({ api: {}, })); vi.mock("../editor", () => { const ContentEditor = forwardRef(({ defaultValue, onUpdate, placeholder }: any, ref: any) => { const valueRef = useRef(defaultValue || ""); const [value, setValue] = useState(defaultValue || ""); useImperativeHandle(ref, () => ({ getMarkdown: () => valueRef.current, uploadFile: vi.fn(), })); return (