Browse Source

Update command tests

ts-style-manager
Artur Arseniev 3 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 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();
});

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