diff --git a/packages/core/src/commands/view/ComponentDrag.ts b/packages/core/src/commands/view/ComponentDrag.ts index 8fab1a7fe..082db665e 100644 --- a/packages/core/src/commands/view/ComponentDrag.ts +++ b/packages/core/src/commands/view/ComponentDrag.ts @@ -67,9 +67,9 @@ export default { return { mode: this.opts.mode, component: this.target, - target: this.target, // deprecated - guidesTarget: this.guidesTarget, // deprecated - guidesStatic: this.guidesStatic, // deprecated + target: this.target, + guidesTarget: this.guidesTarget, + guidesStatic: this.guidesStatic, guidesMatched: this.getGuidesMatched(guidesActive), }; }, @@ -238,7 +238,6 @@ export default { const guides = guidePoints.map((guidePoint) => { const guide = opts.debug ? this.renderGuide(guidePoint) : undefined; - // INFO: origin, originRect, and guide are repeated to don't introduce breaking changes return { ...guidePoint, component, diff --git a/packages/core/test/specs/commands/index.ts b/packages/core/test/specs/commands/index.ts index c8b3688ec..f2ad5d2be 100644 --- a/packages/core/test/specs/commands/index.ts +++ b/packages/core/test/specs/commands/index.ts @@ -95,50 +95,45 @@ describe('Commands', () => { expect(Object.keys(obj.getActive()).length).toBe(0); }); - test.skip('Run command with and without default options', () => { - const options = { test: 'custom' }; - // const defaultOptions = { test: 'default' }; - const command = { run: jest.fn(), stop: jest.fn() }; - obj.add(commName, command); - // Test run command without default options - obj.run(commName, options); - expect(command.run).toHaveBeenCalledWith(em, expect.objectContaining(options)); - - // TODO: Fix this test - // Test run command with default options - // em.config.commands = { - // defaultOptions: { - // [commName]: { - // run: (opts) => ({ ...opts, ...defaultOptions }), - // }, - // }, - // }; - // obj.run(commName, options); - // expect(command.run).toHaveBeenCalledWith(em, expect.objectContaining(defaultOptions)); - }); + test('Run command and check if defaultOptions are passed or not', () => { + const defaultOptions = { key: 'defaultValue' }; + const customOptions = { key: 'customValue' }; + const mergedOptions = { ...defaultOptions, ...customOptions }; + + const comm = { + run: jest.fn(() => commResultRun), // Mock the run method + }; + + // Add the command + obj.add(commName, comm); + expect(obj.isActive(commName)).toBe(false); + + // Run the command without defaultOptions + let result = obj.run(commName, customOptions); + expect(result).toBe(commResultRun); + expect(comm.run).toHaveBeenCalledWith(em, expect.objectContaining(customOptions)); + expect(obj.isActive(commName)).toBe(false); + + // Configure defaultOptions + em.config.commands = { + defaultOptions: { + [commName]: { + run: (opts) => ({ ...defaultOptions, ...opts }), // Merge defaultOptions with provided options + }, + }, + }; + + // Run the command without custom options + result = obj.run(commName); + expect(result).toBe(commResultRun); + expect(comm.run).toHaveBeenCalledWith(em, expect.objectContaining(defaultOptions)); + expect(obj.isActive(commName)).toBe(false); - test.skip('Stop command with and without default options', () => { - const options = { test: 'custom' }; - // const defaultOptions = { test: 'default' }; - const command = { run: jest.fn(), stop: jest.fn() }; - obj.add(commName, command); - - // Test stop command without default options - obj.stop(commName, options); - expect(command.stop).toHaveBeenCalledWith(em, expect.objectContaining(options)); - - // TODO: Fix this test - // Test stop command with default options - // em.config.commands = { - // defaultOptions: { - // [commName]: { - // stop: (opts) => ({ ...opts, ...defaultOptions }), - // }, - // }, - // }; - // obj.run(commName, options); - // obj.stop(commName, options); - // expect(command.stop).toHaveBeenCalledWith(em, expect.objectContaining(defaultOptions)); + // Run the command with custom options + result = obj.run(commName, customOptions); + expect(result).toBe(commResultRun); + expect(comm.run).toHaveBeenCalledWith(em, expect.objectContaining(mergedOptions)); + expect(obj.isActive(commName)).toBe(false); }); }); });