|
|
|
@ -1,13 +1,47 @@ |
|
|
|
import Backbone from 'backbone'; |
|
|
|
var Commands = require('commands'); |
|
|
|
var Models = require('./model/CommandModels'); |
|
|
|
var CommandAbstract = require('./view/CommandAbstract'); |
|
|
|
|
|
|
|
describe('Commands', () => { |
|
|
|
describe.only('Commands', () => { |
|
|
|
describe('Main', () => { |
|
|
|
let obj; |
|
|
|
let obj, |
|
|
|
commSimple, |
|
|
|
commRunOnly, |
|
|
|
commFunc, |
|
|
|
commName = 'commandTest', |
|
|
|
commResultRun = 'Run executed', |
|
|
|
commResultStop = 'Stop executed'; |
|
|
|
|
|
|
|
const mockEditor = { |
|
|
|
get(id) { |
|
|
|
switch (id) { |
|
|
|
case 'Canvas': |
|
|
|
return { |
|
|
|
getElement: () => ({}), |
|
|
|
getWrapperEl: () => ({}), |
|
|
|
getFrameEl: () => ({}), |
|
|
|
getToolsEl: () => ({}), |
|
|
|
getBody: () => ({}) |
|
|
|
}; |
|
|
|
case 'Editor': |
|
|
|
return { ...Backbone.Events }; |
|
|
|
default: |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
obj = new Commands().init(); |
|
|
|
commSimple = { |
|
|
|
run: () => commResultRun, |
|
|
|
stop: () => commResultStop |
|
|
|
}; |
|
|
|
commRunOnly = { |
|
|
|
run: () => commResultRun |
|
|
|
}; |
|
|
|
commFunc = () => commResultRun; |
|
|
|
obj = new Commands().init({ em: mockEditor }); |
|
|
|
}); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
@ -19,8 +53,11 @@ describe('Commands', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('Push new command', () => { |
|
|
|
var comm = { test: 'test' }; |
|
|
|
const comm = { test: 'test' }; |
|
|
|
const len = Object.keys(obj.getAll()).length; |
|
|
|
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'); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -58,6 +95,48 @@ describe('Commands', () => { |
|
|
|
test('Commands module should not have toLoad property', () => { |
|
|
|
expect(obj.toLoad).toBeUndefined(); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Run simple command and check if the state is tracked', () => { |
|
|
|
// Add the command
|
|
|
|
obj.add(commName, commSimple); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
|
|
|
|
// Start the command
|
|
|
|
let result = obj.run(commName); |
|
|
|
expect(result).toBe(commResultRun); |
|
|
|
expect(obj.isActive(commName)).toBe(true); |
|
|
|
expect(Object.keys(obj.getActive()).length).toBe(1); |
|
|
|
|
|
|
|
// Stop the command
|
|
|
|
result = obj.stop(commName); |
|
|
|
expect(result).toBe(commResultStop); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
expect(Object.keys(obj.getActive()).length).toBe(0); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Run command only with run method, ensure is not tracked', () => { |
|
|
|
// Add the command
|
|
|
|
obj.add(commName, commRunOnly); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
|
|
|
|
// Start the command
|
|
|
|
let result = obj.run(commName); |
|
|
|
expect(result).toBe(commResultRun); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
expect(Object.keys(obj.getActive()).length).toBe(0); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Run function command, ensure is not tracked', () => { |
|
|
|
// Add the command
|
|
|
|
obj.add(commName, commFunc); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
|
|
|
|
// Start the command
|
|
|
|
let result = obj.run(commName); |
|
|
|
expect(result).toBe(commResultRun); |
|
|
|
expect(obj.isActive(commName)).toBe(false); |
|
|
|
expect(Object.keys(obj.getActive()).length).toBe(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|