|
|
|
@ -9,7 +9,7 @@ const Editor = require('editor/model/Editor'); |
|
|
|
const utils = require('./../test_utils.js'); |
|
|
|
|
|
|
|
describe('DOM Components', () => { |
|
|
|
describe.only('Main', () => { |
|
|
|
describe('Main', () => { |
|
|
|
var em; |
|
|
|
var obj; |
|
|
|
var config; |
|
|
|
@ -179,7 +179,7 @@ describe('DOM Components', () => { |
|
|
|
obj.addType(id, { |
|
|
|
model: { |
|
|
|
defaults: { |
|
|
|
testProp, |
|
|
|
testProp |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
@ -189,6 +189,63 @@ describe('DOM Components', () => { |
|
|
|
expect(comp.get('type')).toEqual(id); |
|
|
|
expect(comp.get('testProp')).toEqual(testProp); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Add new component type with custom isComponent', () => { |
|
|
|
obj = em.get('DomComponents'); |
|
|
|
const id = 'test-type'; |
|
|
|
const testProp = 'testValue'; |
|
|
|
obj.addType(id, { |
|
|
|
isComponent: el => { |
|
|
|
return el.getAttribute('test-prop') === testProp; |
|
|
|
} |
|
|
|
}); |
|
|
|
expect(obj.componentTypes[0].id).toEqual(id); |
|
|
|
obj.addComponent(`<div test-prop="${testProp}"></div>`); |
|
|
|
const comp = obj.getComponents().at(0); |
|
|
|
expect(comp.get('type')).toEqual(id); |
|
|
|
expect(comp.getAttributes()['test-prop']).toEqual(testProp); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Extend component type with custom model and view', () => { |
|
|
|
obj = em.get('DomComponents'); |
|
|
|
const id = 'text'; |
|
|
|
const testProp = 'testValue'; |
|
|
|
const testText = 'Some text'; |
|
|
|
const initialTypes = obj.getTypes().length; |
|
|
|
obj.addType('text', { |
|
|
|
model: { |
|
|
|
defaults: { |
|
|
|
testProp |
|
|
|
} |
|
|
|
}, |
|
|
|
view: { |
|
|
|
onRender() { |
|
|
|
this.el.style.backgroundColor = 'red'; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
expect(obj.getTypes().length).toBe(initialTypes); |
|
|
|
obj.addComponent(`<div>${testText}</div>`); |
|
|
|
const comp = obj.getComponents().at(0); |
|
|
|
expect(comp.get('type')).toBe(id); |
|
|
|
expect(comp.get('testProp')).toBe(testProp); |
|
|
|
expect(comp.get('editable')).toBe(true); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Add new component type by extending another one', () => { |
|
|
|
obj = em.get('DomComponents'); |
|
|
|
const id = 'test-type'; |
|
|
|
const testProp = 'testValue'; |
|
|
|
obj.addType(id, { |
|
|
|
extend: 'text', |
|
|
|
isComponent: el => el.getAttribute('test-prop') === testProp |
|
|
|
}); |
|
|
|
obj.addComponent(`<div test-prop="${testProp}"></div>`); |
|
|
|
expect(obj.getTypes()[0].id).toEqual(id); |
|
|
|
const comp = obj.getComponents().at(0); |
|
|
|
expect(comp.get('type')).toBe(id); |
|
|
|
expect(comp.get('editable')).toBe(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
ComponentModels.run(); |
|
|
|
|