|
|
|
@ -18,14 +18,14 @@ let em; |
|
|
|
|
|
|
|
describe('Component', () => { |
|
|
|
beforeEach(() => { |
|
|
|
em = new Editor(); |
|
|
|
em = new Editor({ avoidDefaults: true }); |
|
|
|
dcomp = em.get('DomComponents'); |
|
|
|
em.get('PageManager').onLoad(); |
|
|
|
// dcomp = new DomComponents();
|
|
|
|
compOpts = { |
|
|
|
em, |
|
|
|
componentTypes: dcomp.componentTypes, |
|
|
|
domc: dcomp |
|
|
|
domc: dcomp, |
|
|
|
}; |
|
|
|
obj = new Component({}, compOpts); |
|
|
|
dcomp.init({ em }); |
|
|
|
@ -51,22 +51,11 @@ describe('Component', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('Clones correctly with traits', () => { |
|
|
|
obj |
|
|
|
.get('traits') |
|
|
|
.at(0) |
|
|
|
.set('value', 'testTitle'); |
|
|
|
obj.get('traits').at(0).set('value', 'testTitle'); |
|
|
|
var cloned = obj.clone(); |
|
|
|
cloned.set('stylable', 0); |
|
|
|
cloned |
|
|
|
.get('traits') |
|
|
|
.at(0) |
|
|
|
.set('value', 'testTitle2'); |
|
|
|
expect( |
|
|
|
obj |
|
|
|
.get('traits') |
|
|
|
.at(0) |
|
|
|
.get('value') |
|
|
|
).toEqual('testTitle'); |
|
|
|
cloned.get('traits').at(0).set('value', 'testTitle2'); |
|
|
|
expect(obj.get('traits').at(0).get('value')).toEqual('testTitle'); |
|
|
|
expect(obj.get('stylable')).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -75,12 +64,12 @@ describe('Component', () => { |
|
|
|
{ |
|
|
|
label: 'Title', |
|
|
|
name: 'title', |
|
|
|
value: 'The title' |
|
|
|
value: 'The title', |
|
|
|
}, |
|
|
|
{ |
|
|
|
label: 'Context', |
|
|
|
value: 'primary' |
|
|
|
} |
|
|
|
value: 'primary', |
|
|
|
}, |
|
|
|
]); |
|
|
|
expect(obj.get('attributes')).toEqual({ title: 'The title' }); |
|
|
|
}); |
|
|
|
@ -104,27 +93,25 @@ describe('Component', () => { |
|
|
|
tagName: 'article', |
|
|
|
attributes: { |
|
|
|
'data-test1': 'value1', |
|
|
|
'data-test2': 'value2' |
|
|
|
} |
|
|
|
'data-test2': 'value2', |
|
|
|
}, |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual( |
|
|
|
'<article data-test1="value1" data-test2="value2"></article>' |
|
|
|
); |
|
|
|
expect(obj.toHTML()).toEqual('<article data-test1="value1" data-test2="value2"></article>'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Component toHTML with value-less attribute', () => { |
|
|
|
obj = new Component({ |
|
|
|
tagName: 'div', |
|
|
|
attributes: { |
|
|
|
'data-is-a-test': '' |
|
|
|
} |
|
|
|
'data-is-a-test': '', |
|
|
|
}, |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual('<div data-is-a-test=""></div>'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Component toHTML with classes', () => { |
|
|
|
obj = new Component({ |
|
|
|
tagName: 'article' |
|
|
|
tagName: 'article', |
|
|
|
}); |
|
|
|
['class1', 'class2'].forEach(item => { |
|
|
|
obj.get('classes').add({ name: item }); |
|
|
|
@ -157,17 +144,41 @@ describe('Component', () => { |
|
|
|
expect(obj.toHTML()).toEqual('<div data-test=""value""></div>'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Component toHTML and withProps', () => { |
|
|
|
obj = new Component({}, { em }); |
|
|
|
obj.set({ |
|
|
|
bool: true, |
|
|
|
boolf: false, |
|
|
|
string: `st'ri"ng`, |
|
|
|
array: [1, 'string', true], |
|
|
|
object: { a: 1, b: 'string', c: true }, |
|
|
|
null: null, |
|
|
|
undef: undefined, |
|
|
|
empty: '', |
|
|
|
zero: 0, |
|
|
|
_private: 'value', |
|
|
|
}); |
|
|
|
let resStr = `st'ri"ng`; |
|
|
|
let resArr = '[1,"string",true]'; |
|
|
|
let resObj = '{"a":1,"b":"string","c":true}'; |
|
|
|
let res = `<div data-gjs-bool data-gjs-string="${resStr}" data-gjs-array="${resArr}" data-gjs-object="${resObj}" data-gjs-empty="" data-gjs-zero="0"></div>`; |
|
|
|
expect(obj.toHTML({ withProps: true })).toEqual(res); |
|
|
|
resStr = `st'ri"ng`; |
|
|
|
resArr = '[1,"string",true]'; |
|
|
|
resObj = '{"a":1,"b":"string","c":true}'; |
|
|
|
res = `<div data-gjs-bool data-gjs-string='${resStr}' data-gjs-array='${resArr}' data-gjs-object='${resObj}' data-gjs-empty="" data-gjs-zero="0"></div>`; |
|
|
|
expect(obj.toHTML({ withProps: true, beautifyAttr: true })).toEqual(res); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Manage correctly boolean attributes', () => { |
|
|
|
obj = new Component(); |
|
|
|
obj.set('attributes', { |
|
|
|
'data-test': 'value', |
|
|
|
checked: false, |
|
|
|
required: true, |
|
|
|
avoid: true |
|
|
|
avoid: true, |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual( |
|
|
|
'<div data-test="value" required avoid></div>' |
|
|
|
); |
|
|
|
expect(obj.toHTML()).toEqual('<div data-test="value" required avoid></div>'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Component parse empty div', () => { |
|
|
|
@ -261,18 +272,18 @@ describe('Component', () => { |
|
|
|
id: 'test', |
|
|
|
'data-test': 'value', |
|
|
|
class: 'class1 class2', |
|
|
|
style: 'color: white; background: #fff' |
|
|
|
style: 'color: white; background: #fff', |
|
|
|
}); |
|
|
|
expect(obj.getAttributes()).toEqual({ |
|
|
|
id: 'test', |
|
|
|
class: 'class1 class2', |
|
|
|
style: 'color:white;background:#fff;', |
|
|
|
'data-test': 'value' |
|
|
|
'data-test': 'value', |
|
|
|
}); |
|
|
|
expect(obj.get('classes').length).toEqual(2); |
|
|
|
expect(obj.getStyle()).toEqual({ |
|
|
|
color: 'white', |
|
|
|
background: '#fff' |
|
|
|
background: '#fff', |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -370,7 +381,7 @@ describe('Component', () => { |
|
|
|
obj.append({ |
|
|
|
removable: false, |
|
|
|
draggable: false, |
|
|
|
propagate: ['removable', 'draggable'] |
|
|
|
propagate: ['removable', 'draggable'], |
|
|
|
}); |
|
|
|
const result = obj.components(); |
|
|
|
const newObj = result.models[0]; |
|
|
|
@ -433,7 +444,7 @@ describe('Image Component', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new ComponentImage({ |
|
|
|
attributes: { alt: 'AltTest' }, |
|
|
|
src: 'testPath' |
|
|
|
src: 'testPath', |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual('<img alt="AltTest" src="testPath"/>'); |
|
|
|
}); |
|
|
|
@ -475,7 +486,7 @@ describe('Text Component', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new ComponentText({ |
|
|
|
attributes: { 'data-test': 'value' }, |
|
|
|
content: 'test content' |
|
|
|
content: 'test content', |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual('<div data-test="value">test content</div>'); |
|
|
|
}); |
|
|
|
@ -505,7 +516,7 @@ describe('Text Node Component', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new ComponentTextNode({ |
|
|
|
attributes: { 'data-test': 'value' }, |
|
|
|
content: `test content &<>"'` |
|
|
|
content: `test content &<>"'`, |
|
|
|
}); |
|
|
|
expect(obj.toHTML()).toEqual('test content &<>"''); |
|
|
|
}); |
|
|
|
@ -555,9 +566,7 @@ describe('Map Component', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('Component parse not map iframe', () => { |
|
|
|
var el = $( |
|
|
|
'<iframe src="https://www.youtube.com/watch?v=jNQXAC9IVRw"></iframe>' |
|
|
|
); |
|
|
|
var el = $('<iframe src="https://www.youtube.com/watch?v=jNQXAC9IVRw"></iframe>'); |
|
|
|
obj = ComponentMap.isComponent(el.get(0)); |
|
|
|
expect(obj).toEqual(''); |
|
|
|
}); |
|
|
|
@ -593,7 +602,7 @@ describe('Components', () => { |
|
|
|
em.get('PageManager').onLoad(); |
|
|
|
compOpts = { |
|
|
|
em, |
|
|
|
componentTypes: dcomp.componentTypes |
|
|
|
componentTypes: dcomp.componentTypes, |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|