From 9d018ab61553c3182d2a796b59484528922f2ad5 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sun, 23 Mar 2025 21:27:11 -0700 Subject: [PATCH] feat: add run and stop command tests --- packages/core/src/commands/config/config.ts | 3 -- packages/core/src/commands/index.ts | 1 - .../core/src/commands/view/ComponentDrag.ts | 4 +- packages/core/test/specs/commands/index.ts | 47 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/packages/core/src/commands/config/config.ts b/packages/core/src/commands/config/config.ts index 4daab89b0..321588c0a 100644 --- a/packages/core/src/commands/config/config.ts +++ b/packages/core/src/commands/config/config.ts @@ -61,9 +61,6 @@ const config: () => CommandsConfig = () => ({ 'core:component-drag': { run: (options: CommandOptions) => ({ ...options, - customElements: { - guideIndicator: false, - }, // addStyle: ({ componentView, matchedEl }) => { // // TODO: test if you can conver to percentage // // componentView.setStyle({ opacity: 0.5 }); diff --git a/packages/core/src/commands/index.ts b/packages/core/src/commands/index.ts index eba5f1740..a43f88b4f 100644 --- a/packages/core/src/commands/index.ts +++ b/packages/core/src/commands/index.ts @@ -388,7 +388,6 @@ export default class CommandsModule extends Module { expect(obj.isActive(commName)).toBe(false); expect(Object.keys(obj.getActive()).length).toBe(0); }); + + test('Run command with and without default options', () => { + const defaultOptions = { test: 'default' }; + const options = { test: 'custom' }; + const command = { run: jest.fn(), stop: jest.fn() }; + obj.add(commName, command); + em.config.commands = { + defaultOptions: { + [commName]: { + run: (opts) => ({ ...opts, ...defaultOptions }), + }, + }, + }; + + // Test run command with default options + obj.run(commName, options); + expect(command.run).toHaveBeenCalledWith(em, { ...options, ...defaultOptions }); + + // Test run command without default options + em.config.commands.defaultOptions![commName].run = undefined; + obj.run(commName, options); + expect(command.run).toHaveBeenCalledWith(em, options); + }); + + test('Stop command with and without default options', () => { + const defaultOptions = { test: 'default' }; + const options = { test: 'custom' }; + const command = { run: jest.fn(), stop: jest.fn() }; + obj.add(commName, command); + em.config.commands = { + defaultOptions: { + [commName]: { + stop: (opts) => ({ ...opts, ...defaultOptions }), + }, + }, + }; + + // Test stop command with default options + obj.run(commName, options); + obj.stop(commName, options); + expect(command.stop).toHaveBeenCalledWith(em, { ...options, ...defaultOptions }); + + // Test stop command without default options + em.config.commands.defaultOptions![commName].stop = undefined; + obj.stop(commName, options); + expect(command.stop).toHaveBeenCalledWith(em, options); + }); }); });