|
|
|
@ -2,12 +2,27 @@ import Panel from '../../../../src/panels/model/Panel'; |
|
|
|
import Preview from '../../../../src/commands/view/Preview'; |
|
|
|
|
|
|
|
describe('Preview command', () => { |
|
|
|
let command: Preview; |
|
|
|
let fakePanels: Panel[]; |
|
|
|
let fakeEditor: any; |
|
|
|
let fakeIsActive: any; |
|
|
|
const obj: any = {}; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
command = new Preview({}); |
|
|
|
command.ppfx = ''; |
|
|
|
command.em = { |
|
|
|
Canvas: { |
|
|
|
getBody: jest.fn(() => ({ |
|
|
|
querySelectorAll: jest.fn(() => []), |
|
|
|
})), |
|
|
|
getToolbarEl: jest.fn(() => ({ |
|
|
|
style: {}, |
|
|
|
})), |
|
|
|
}, |
|
|
|
on: jest.fn(), |
|
|
|
off: jest.fn(), |
|
|
|
} as any; |
|
|
|
fakePanels = [new Panel(obj, obj), new Panel(obj, obj), new Panel(obj, obj)]; |
|
|
|
fakeIsActive = false; |
|
|
|
|
|
|
|
@ -44,63 +59,63 @@ describe('Preview command', () => { |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
|
Preview.panels = undefined; |
|
|
|
Preview.shouldRunSwVisibility = undefined; |
|
|
|
command.panels = undefined; |
|
|
|
command.shouldRunSwVisibility = undefined; |
|
|
|
}); |
|
|
|
|
|
|
|
describe('.getPanels', () => { |
|
|
|
test('it should return panels set with the editor panels if not already set', () => { |
|
|
|
Preview.getPanels(fakeEditor); |
|
|
|
expect(Preview.panels).toBe(fakePanels); |
|
|
|
Preview.getPanels(fakeEditor); |
|
|
|
command.getPanels(fakeEditor); |
|
|
|
expect(command.panels).toBe(fakePanels); |
|
|
|
command.getPanels(fakeEditor); |
|
|
|
expect(fakeEditor.Panels.getPanels).toHaveBeenCalledTimes(1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('.run', () => { |
|
|
|
beforeEach(() => { |
|
|
|
Preview.helper = { style: {} }; |
|
|
|
command.helper = { style: {} } as any; |
|
|
|
}); |
|
|
|
|
|
|
|
it('should hide all panels', () => { |
|
|
|
fakePanels.forEach((panel) => expect(panel.get('visible')).toEqual(true)); |
|
|
|
Preview.run!(fakeEditor, obj, obj); |
|
|
|
command.run(fakeEditor, obj); |
|
|
|
fakePanels.forEach((panel) => expect(panel.get('visible')).toEqual(false)); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should stop the 'core:component-outline' command if active", () => { |
|
|
|
Preview.run!(fakeEditor, obj, obj); |
|
|
|
command.run(fakeEditor, obj); |
|
|
|
expect(fakeEditor.stopCommand).not.toHaveBeenCalled(); |
|
|
|
fakeIsActive = true; |
|
|
|
Preview.run!(fakeEditor, obj, obj); |
|
|
|
command.run(fakeEditor, obj); |
|
|
|
expect(fakeEditor.stopCommand).toHaveBeenCalledWith('core:component-outline'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not reset the `shouldRunSwVisibility` state once active if run multiple times', () => { |
|
|
|
expect(Preview.shouldRunSwVisibility).toBeUndefined(); |
|
|
|
expect(command.shouldRunSwVisibility).toBeUndefined(); |
|
|
|
fakeIsActive = true; |
|
|
|
Preview.run!(fakeEditor, obj, obj); |
|
|
|
expect(Preview.shouldRunSwVisibility).toEqual(true); |
|
|
|
command.run(fakeEditor, obj); |
|
|
|
expect(command.shouldRunSwVisibility).toEqual(true); |
|
|
|
fakeIsActive = false; |
|
|
|
Preview.run!(fakeEditor, obj, obj); |
|
|
|
expect(Preview.shouldRunSwVisibility).toEqual(true); |
|
|
|
command.run(fakeEditor, obj); |
|
|
|
expect(command.shouldRunSwVisibility).toEqual(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('.stop', () => { |
|
|
|
it('should show all panels', () => { |
|
|
|
fakePanels.forEach((panel) => panel.set('visible', false)); |
|
|
|
Preview.stop!(fakeEditor, obj, obj); |
|
|
|
command.stop(fakeEditor); |
|
|
|
fakePanels.forEach((panel) => expect(panel.get('visible')).toEqual(true)); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should run the 'core:component-outline' command if it was active before run", () => { |
|
|
|
Preview.stop!(fakeEditor, obj, obj); |
|
|
|
command.stop(fakeEditor); |
|
|
|
expect(fakeEditor.runCommand).not.toHaveBeenCalled(); |
|
|
|
Preview.shouldRunSwVisibility = true; |
|
|
|
Preview.stop!(fakeEditor, obj, obj); |
|
|
|
command.shouldRunSwVisibility = true; |
|
|
|
command.stop(fakeEditor); |
|
|
|
expect(fakeEditor.runCommand).toHaveBeenCalledWith('core:component-outline'); |
|
|
|
expect(Preview.shouldRunSwVisibility).toEqual(false); |
|
|
|
expect(command.shouldRunSwVisibility).toEqual(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|