1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Android: Fixes #10152: Fix broken plugin API: editor.execCommand (#10153)

This commit is contained in:
Henry Heino
2024-03-20 03:58:42 -07:00
committed by GitHub
parent 32141d4e23
commit 44e8950f1b
8 changed files with 78 additions and 20 deletions

View File

@ -0,0 +1,36 @@
import CommandService from '@joplin/lib/services/CommandService';
import useEditorCommandHandler from './useEditorCommandHandler';
import commandDeclarations from '../commandDeclarations';
import createTestEditorControl from '@joplin/editor/CodeMirror/testUtil/createEditorControl';
import { renderHook } from '@testing-library/react-native';
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();
});
});