文件
mynode/packages/app-mobile/components/NoteEditor/hooks/useEditorCommandHandler.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

39 行
1.6 KiB
TypeScript

/** @jest-environment jsdom */
import CommandService from '@joplin/lib/services/CommandService';
import useEditorCommandHandler from './useEditorCommandHandler';
import commandDeclarations from '../commandDeclarations';
import createTestEditorControl from '@joplin/editor/CodeMirror/testing/createEditorControl';
import { renderHook } from '../../../utils/testing/testingLibrary';
import { defaultState } from '@joplin/lib/reducer';
describe('useEditorCommandHandler', () => {
beforeAll(() => {
const storeMock = { getState: () => defaultState, dispatch: jest.fn() };
CommandService.instance().initialize(storeMock, false, ()=>({}));
for (const declaration of commandDeclarations) {
CommandService.instance().registerDeclaration(declaration);
}
});
it('should support running custom commands with editor.execCommand', async () => {
const editor = createTestEditorControl('Test.');
renderHook(() => useEditorCommandHandler(editor));
const testCommandCallback = jest.fn();
editor.registerCommand('myCommand', testCommandCallback);
expect(testCommandCallback).not.toHaveBeenCalled();
// Should support running commands with arguments
await CommandService.instance().execute('editor.execCommand', { name: 'myCommand', args: ['a', 'b', 'c'] });
expect(testCommandCallback).toHaveBeenCalledTimes(1);
expect(testCommandCallback).toHaveBeenLastCalledWith('a', 'b', 'c');
// Should support running commands without arguments
await CommandService.instance().execute('editor.execCommand', { name: 'myCommand' });
expect(testCommandCallback).toHaveBeenCalledTimes(2);
expect(testCommandCallback).toHaveBeenLastCalledWith();
});
});