diff --git a/test/specs/commands/index.js b/test/specs/commands/index.ts similarity index 73% rename from test/specs/commands/index.js rename to test/specs/commands/index.ts index 733c44f17..3813ddd44 100644 --- a/test/specs/commands/index.js +++ b/test/specs/commands/index.ts @@ -1,36 +1,17 @@ import Backbone from 'backbone'; -import Commands from 'commands'; +import Commands from '../../../src/commands'; +import EditorModel from '../../../src/editor/model/Editor'; describe('Commands', () => { describe('Main', () => { - let obj, - commSimple, - commRunOnly, - commFunc, - commName = 'commandTest', - commResultRun = 'Run executed', - commResultStop = 'Stop executed'; - - const mockEditor = { - ...Backbone.Events, - get(id) { - switch (id) { - case 'Canvas': - return { - getElement: () => ({}), - getWrapperEl: () => ({}), - getFrameEl: () => ({}), - getToolsEl: () => ({}), - getBody: () => ({}), - }; - case 'Editor': - return { ...Backbone.Events }; - default: - } - return null; - }, - logWarning() {}, - }; + let em: EditorModel; + let obj: Commands; + let commSimple; + let commRunOnly; + let commFunc; + let commName = 'commandTest'; + let commResultRun = 'Run executed'; + let commResultStop = 'Stop executed'; beforeEach(() => { commSimple = { @@ -41,11 +22,13 @@ describe('Commands', () => { run: () => commResultRun, }; commFunc = () => commResultRun; - obj = new Commands().init({ em: mockEditor }); + em = new EditorModel(); + em.set('Editor', { ...Backbone.Events }); + obj = em.Commands; }); afterEach(() => { - obj = null; + em.destroy(); }); test('No commands inside', () => { @@ -58,15 +41,15 @@ describe('Commands', () => { obj.add('test', comm); expect(obj.has('test')).toBe(true); expect(Object.keys(obj.getAll()).length).toBe(len + 1); - expect(obj.get('test').test).toEqual('test'); + expect(obj.get('test')!.test).toEqual('test'); }); test('Default commands after loadDefaultCommands', () => { - obj.loadDefaultCommands(); expect(obj.get('select-comp')).not.toBeUndefined(); }); test('Commands module should not have toLoad property', () => { + // @ts-ignore expect(obj.toLoad).toBeUndefined(); }); diff --git a/test/specs/commands/model/CommandModels.js b/test/specs/commands/model/CommandModels.js deleted file mode 100644 index ac338fdf2..000000000 --- a/test/specs/commands/model/CommandModels.js +++ /dev/null @@ -1,34 +0,0 @@ -import Command from 'commands/model/Command'; -import Commands from 'commands'; - -describe('Command', () => { - let obj; - - beforeEach(() => { - obj = new Command(); - }); - - afterEach(() => { - obj = null; - }); - - test('Has id property', () => { - expect(obj.has('id')).toEqual(true); - }); -}); - -describe('Commands', () => { - var obj; - - beforeEach(() => { - obj = new Commands(); - }); - - afterEach(() => { - obj = null; - }); - - test('Object is ok', () => { - expect(obj).toBeTruthy(); - }); -});