|
|
|
@ -4,18 +4,14 @@ import Editor from '../../../src/editor/model/Editor'; |
|
|
|
|
|
|
|
describe('Panels', () => { |
|
|
|
describe('Main', () => { |
|
|
|
var em; |
|
|
|
var obj; |
|
|
|
let em: Editor; |
|
|
|
let obj: Panels; |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
em = new Editor({}); |
|
|
|
obj = new Panels(em); |
|
|
|
}); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
obj = null; |
|
|
|
}); |
|
|
|
|
|
|
|
test('Object exists', () => { |
|
|
|
expect(obj).toBeTruthy(); |
|
|
|
}); |
|
|
|
@ -31,7 +27,7 @@ describe('Panels', () => { |
|
|
|
|
|
|
|
test('New panel has no buttons', () => { |
|
|
|
var panel = obj.addPanel({ id: 'test' }); |
|
|
|
expect(panel.get('buttons').length).toEqual(0); |
|
|
|
expect(panel.buttons.length).toEqual(0); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Adds new panel correctly via Panel instance', () => { |
|
|
|
@ -57,8 +53,8 @@ describe('Panels', () => { |
|
|
|
test('Add button correctly', () => { |
|
|
|
var panel = obj.addPanel({ id: 'test' }); |
|
|
|
var btn = obj.addButton('test', { id: 'btn' }); |
|
|
|
expect(panel.get('buttons').length).toEqual(1); |
|
|
|
expect(panel.get('buttons').at(0).get('id')).toEqual('btn'); |
|
|
|
expect(panel.buttons.length).toEqual(1); |
|
|
|
expect(panel.buttons.at(0).get('id')).toEqual('btn'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('getButton returns null in case there is no requested panel', () => { |
|
|
|
@ -83,7 +79,7 @@ describe('Panels', () => { |
|
|
|
test('Active correctly activable buttons', () => { |
|
|
|
const fn = jest.fn(); |
|
|
|
obj.addPanel({ id: 'test' }); |
|
|
|
const btn = obj.addButton('test', { id: 'btn', active: true }); |
|
|
|
const btn = obj.addButton('test', { id: 'btn', active: true })!; |
|
|
|
btn.on('updateActive', fn); |
|
|
|
obj.active(); |
|
|
|
expect(fn).toBeCalledTimes(1); |
|
|
|
@ -92,7 +88,7 @@ describe('Panels', () => { |
|
|
|
test('Disable correctly buttons flagged as disabled', () => { |
|
|
|
const fn = jest.fn(); |
|
|
|
obj.addPanel({ id: 'test' }); |
|
|
|
const btn = obj.addButton('test', { id: 'btn', disable: true }); |
|
|
|
const btn = obj.addButton('test', { id: 'btn', disable: true })!; |
|
|
|
btn.on('change:disable', fn); |
|
|
|
obj.disableButtons(); |
|
|
|
expect(fn).toBeCalledTimes(1); |
|
|
|
@ -106,19 +102,19 @@ describe('Panels', () => { |
|
|
|
test('Remove button correctly with object', () => { |
|
|
|
var panel = obj.addPanel({ id: 'test' }); |
|
|
|
var btn = obj.addButton('test', { id: 'btn' }); |
|
|
|
expect(panel.get('buttons').length).toEqual(1); |
|
|
|
expect(panel.get('buttons').at(0).get('id')).toEqual('btn'); |
|
|
|
expect(panel.buttons.length).toEqual(1); |
|
|
|
expect(panel.buttons.at(0).get('id')).toEqual('btn'); |
|
|
|
expect(obj.removeButton('test', { id: 'btn' })).toEqual(btn); |
|
|
|
expect(panel.get('buttons').length).toEqual(0); |
|
|
|
expect(panel.buttons.length).toEqual(0); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Remove button correctly with sting', () => { |
|
|
|
var panel = obj.addPanel({ id: 'test' }); |
|
|
|
var btn = obj.addButton('test', { id: 'btn' }); |
|
|
|
expect(panel.get('buttons').length).toEqual(1); |
|
|
|
expect(panel.get('buttons').at(0).get('id')).toEqual('btn'); |
|
|
|
expect(panel.buttons.length).toEqual(1); |
|
|
|
expect(panel.buttons.at(0).get('id')).toEqual('btn'); |
|
|
|
expect(obj.removeButton('test', 'btn')).toEqual(btn); |
|
|
|
expect(panel.get('buttons').length).toEqual(0); |
|
|
|
expect(panel.buttons.length).toEqual(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -126,7 +122,7 @@ describe('Panels', () => { |
|
|
|
test('Removes panel correctly via object', () => { |
|
|
|
var panel = obj.addPanel({ id: 'test' }); |
|
|
|
expect(panel.get('id')).toEqual('test'); |
|
|
|
obj.removePanel({ id: 'test' }); |
|
|
|
obj.removePanel('test'); |
|
|
|
expect(panel.get('id')).toEqual('test'); |
|
|
|
}); |
|
|
|
|
|
|
|
|