import React from 'react'; import { describe, it, expect, beforeEach, vi } from 'vitest'; import { render, act, fireEvent, within } from '@testing-library/react'; vi.mock('@monaco-editor/react', () => ({ default: () =>
, })); vi.mock('@milkdown/kit/core', () => { const makeChain = () => { const chain = { config: (callback: (ctx: { set: () => void; get: () => { markdownUpdated: () => void } }) => void) => { callback({ set: () => {}, get: () => ({ markdownUpdated: () => {} }) }); return chain; }, use: () => chain, }; return chain; }; return { Editor: { make: makeChain }, defaultValueCtx: Symbol('defaultValueCtx'), editorViewCtx: Symbol('editorViewCtx'), rootCtx: Symbol('rootCtx'), remarkStringifyOptionsCtx: Symbol('remarkStringifyOptionsCtx'), remarkPluginsCtx: Symbol('remarkPluginsCtx'), }; }); vi.mock('@milkdown/kit/preset/commonmark', () => ({ commonmark: {}, toggleStrongCommand: { key: 'toggleStrong' }, toggleEmphasisCommand: { key: 'toggleEmphasis' }, wrapInBlockquoteCommand: { key: 'wrapInBlockquote' }, wrapInBulletListCommand: { key: 'wrapInBulletList' }, wrapInOrderedListCommand: { key: 'wrapInOrderedList' }, insertHrCommand: { key: 'insertHr' }, toggleInlineCodeCommand: { key: 'toggleInlineCode' }, insertImageCommand: { key: 'insertImage' }, toggleLinkCommand: { key: 'toggleLink' }, })); vi.mock('@milkdown/kit/preset/gfm', () => ({ gfm: {}, toggleStrikethroughCommand: { key: 'toggleStrike' }, })); vi.mock('@milkdown/kit/plugin/history', () => ({ history: {}, undoCommand: { key: 'undo' }, redoCommand: { key: 'redo' }, })); vi.mock('@milkdown/kit/plugin/listener', () => ({ listener: {}, listenerCtx: Symbol('listenerCtx'), })); vi.mock('@milkdown/kit/plugin/clipboard', () => ({ clipboard: {} })); vi.mock('@milkdown/kit/plugin/trailing', () => ({ trailing: {} })); vi.mock('@milkdown/kit/plugin/indent', () => ({ indent: {} })); vi.mock('@milkdown/kit/plugin/cursor', () => ({ cursor: {} })); vi.mock('@milkdown/kit/utils', () => ({ $node: () => ({}), $inputRule: () => ({}), $remark: () => ({}), $prose: () => ({}), replaceAll: () => () => {}, callCommand: () => () => {}, })); vi.mock('@milkdown/react', () => ({ Milkdown: () =>
, MilkdownProvider: ({ children }: { children: React.ReactNode }) => <>{children}, useInstance: () => [false, () => ({ action: (action: unknown) => { if (typeof action === 'function') { action({ get: () => ({}) }); } } })] as const, useEditor: (factory: (root: Node) => unknown) => { factory(document.createElement('div')); }, })); vi.mock('../../../src/renderer/components/Lightbox', () => ({ Lightbox: () => null, useMarkdownImages: () => [], })); vi.mock('../../../src/renderer/components/MilkdownEditor', () => ({ MilkdownEditor: ({ content, onChange }: { content: string; onChange: (value: string) => void }) => (