Browse Source

Update command tests

ts-style-manager
Artur Arseniev 4 years ago
parent
commit
a1d18dd0ae
  1. 49
      test/specs/commands/index.ts
  2. 34
      test/specs/commands/model/CommandModels.js

49
test/specs/commands/index.js → test/specs/commands/index.ts

@ -1,36 +1,17 @@
import Backbone from 'backbone'; import Backbone from 'backbone';
import Commands from 'commands'; import Commands from '../../../src/commands';
import EditorModel from '../../../src/editor/model/Editor';
describe('Commands', () => { describe('Commands', () => {
describe('Main', () => { describe('Main', () => {
let obj, let em: EditorModel;
commSimple, let obj: Commands;
commRunOnly, let commSimple;
commFunc, let commRunOnly;
commName = 'commandTest', let commFunc;
commResultRun = 'Run executed', let commName = 'commandTest';
commResultStop = 'Stop executed'; let commResultRun = 'Run executed';
let 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() {},
};
beforeEach(() => { beforeEach(() => {
commSimple = { commSimple = {
@ -41,11 +22,13 @@ describe('Commands', () => {
run: () => commResultRun, run: () => commResultRun,
}; };
commFunc = () => commResultRun; commFunc = () => commResultRun;
obj = new Commands().init({ em: mockEditor }); em = new EditorModel();
em.set('Editor', { ...Backbone.Events });
obj = em.Commands;
}); });
afterEach(() => { afterEach(() => {
obj = null; em.destroy();
}); });
test('No commands inside', () => { test('No commands inside', () => {
@ -58,15 +41,15 @@ describe('Commands', () => {
obj.add('test', comm); obj.add('test', comm);
expect(obj.has('test')).toBe(true); expect(obj.has('test')).toBe(true);
expect(Object.keys(obj.getAll()).length).toBe(len + 1); 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', () => { test('Default commands after loadDefaultCommands', () => {
obj.loadDefaultCommands();
expect(obj.get('select-comp')).not.toBeUndefined(); expect(obj.get('select-comp')).not.toBeUndefined();
}); });
test('Commands module should not have toLoad property', () => { test('Commands module should not have toLoad property', () => {
// @ts-ignore
expect(obj.toLoad).toBeUndefined(); expect(obj.toLoad).toBeUndefined();
}); });

34
test/specs/commands/model/CommandModels.js

@ -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();
});
});
Loading…
Cancel
Save