Browse Source

refactor: clean up deprecated properties in ComponentDrag and improve command test clarity

carlos/505-improve-grapesjs-absolute-mode
Carlos 2 years ago
parent
commit
407454dea7
  1. 7
      packages/core/src/commands/view/ComponentDrag.ts
  2. 81
      packages/core/test/specs/commands/index.ts

7
packages/core/src/commands/view/ComponentDrag.ts

@ -67,9 +67,9 @@ export default {
return { return {
mode: this.opts.mode, mode: this.opts.mode,
component: this.target, component: this.target,
target: this.target, // deprecated target: this.target,
guidesTarget: this.guidesTarget, // deprecated guidesTarget: this.guidesTarget,
guidesStatic: this.guidesStatic, // deprecated guidesStatic: this.guidesStatic,
guidesMatched: this.getGuidesMatched(guidesActive), guidesMatched: this.getGuidesMatched(guidesActive),
}; };
}, },
@ -238,7 +238,6 @@ export default {
const guides = guidePoints.map((guidePoint) => { const guides = guidePoints.map((guidePoint) => {
const guide = opts.debug ? this.renderGuide(guidePoint) : undefined; const guide = opts.debug ? this.renderGuide(guidePoint) : undefined;
// INFO: origin, originRect, and guide are repeated to don't introduce breaking changes
return { return {
...guidePoint, ...guidePoint,
component, component,

81
packages/core/test/specs/commands/index.ts

@ -95,50 +95,45 @@ describe('Commands', () => {
expect(Object.keys(obj.getActive()).length).toBe(0); expect(Object.keys(obj.getActive()).length).toBe(0);
}); });
test.skip('Run command with and without default options', () => { test('Run command and check if defaultOptions are passed or not', () => {
const options = { test: 'custom' }; const defaultOptions = { key: 'defaultValue' };
// const defaultOptions = { test: 'default' }; const customOptions = { key: 'customValue' };
const command = { run: jest.fn(), stop: jest.fn() }; const mergedOptions = { ...defaultOptions, ...customOptions };
obj.add(commName, command);
// Test run command without default options const comm = {
obj.run(commName, options); run: jest.fn(() => commResultRun), // Mock the run method
expect(command.run).toHaveBeenCalledWith(em, expect.objectContaining(options)); };
// TODO: Fix this test // Add the command
// Test run command with default options obj.add(commName, comm);
// em.config.commands = { expect(obj.isActive(commName)).toBe(false);
// defaultOptions: {
// [commName]: { // Run the command without defaultOptions
// run: (opts) => ({ ...opts, ...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);
// obj.run(commName, options);
// expect(command.run).toHaveBeenCalledWith(em, expect.objectContaining(defaultOptions)); // 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', () => { // Run the command with custom options
const options = { test: 'custom' }; result = obj.run(commName, customOptions);
// const defaultOptions = { test: 'default' }; expect(result).toBe(commResultRun);
const command = { run: jest.fn(), stop: jest.fn() }; expect(comm.run).toHaveBeenCalledWith(em, expect.objectContaining(mergedOptions));
obj.add(commName, command); expect(obj.isActive(commName)).toBe(false);
// 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));
}); });
}); });
}); });

Loading…
Cancel
Save