|
|
|
@ -33,11 +33,11 @@ module.exports = { |
|
|
|
obj = null; |
|
|
|
}); |
|
|
|
|
|
|
|
it('Has no children', () => { |
|
|
|
test('Has no children', () => { |
|
|
|
expect(obj.get('components').length).toEqual(0); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Clones correctly', () => { |
|
|
|
test('Clones correctly', () => { |
|
|
|
var sAttr = obj.attributes; |
|
|
|
var cloned = obj.clone(); |
|
|
|
var eAttr = cloned.attributes; |
|
|
|
@ -48,7 +48,7 @@ module.exports = { |
|
|
|
expect(sAttr.length).toEqual(eAttr.length); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Clones correctly with traits', () => { |
|
|
|
test('Clones correctly with traits', () => { |
|
|
|
obj |
|
|
|
.get('traits') |
|
|
|
.at(0) |
|
|
|
@ -68,7 +68,7 @@ module.exports = { |
|
|
|
expect(obj.get('stylable')).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Sets attributes correctly from traits', () => { |
|
|
|
test('Sets attributes correctly from traits', () => { |
|
|
|
obj.set('traits', [ |
|
|
|
{ |
|
|
|
label: 'Title', |
|
|
|
@ -83,21 +83,21 @@ module.exports = { |
|
|
|
expect(obj.get('attributes')).toEqual({ title: 'The title' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Has expected name', () => { |
|
|
|
test('Has expected name', () => { |
|
|
|
expect(obj.getName()).toEqual('Box'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Has expected name 2', () => { |
|
|
|
test('Has expected name 2', () => { |
|
|
|
obj.cid = 'c999'; |
|
|
|
obj.set('type', 'testType'); |
|
|
|
expect(obj.getName()).toEqual('TestType'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML', () => { |
|
|
|
test('Component toHTML', () => { |
|
|
|
expect(obj.toHTML()).toEqual('<div></div>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with attributes', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new Component({ |
|
|
|
tagName: 'article', |
|
|
|
attributes: { |
|
|
|
@ -110,7 +110,7 @@ module.exports = { |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with value-less attribute', () => { |
|
|
|
test('Component toHTML with value-less attribute', () => { |
|
|
|
obj = new Component({ |
|
|
|
tagName: 'div', |
|
|
|
attributes: { |
|
|
|
@ -120,7 +120,7 @@ module.exports = { |
|
|
|
expect(obj.toHTML()).toEqual('<div data-is-a-test=""></div>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with classes', () => { |
|
|
|
test('Component toHTML with classes', () => { |
|
|
|
obj = new Component({ |
|
|
|
tagName: 'article' |
|
|
|
}); |
|
|
|
@ -132,13 +132,13 @@ module.exports = { |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with children', () => { |
|
|
|
test('Component toHTML with children', () => { |
|
|
|
obj = new Component({ tagName: 'article' }, compOpts); |
|
|
|
obj.get('components').add({ tagName: 'span' }); |
|
|
|
expect(obj.toHTML()).toEqual('<article><span></span></article>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with more children', () => { |
|
|
|
test('Component toHTML with more children', () => { |
|
|
|
obj = new Component({ tagName: 'article' }, compOpts); |
|
|
|
obj.get('components').add([{ tagName: 'span' }, { tagName: 'div' }]); |
|
|
|
expect(obj.toHTML()).toEqual( |
|
|
|
@ -146,12 +146,12 @@ module.exports = { |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with no closing tag', () => { |
|
|
|
test('Component toHTML with no closing tag', () => { |
|
|
|
obj = new Component({ void: 1 }); |
|
|
|
expect(obj.toHTML()).toEqual('<div/>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with quotes in attribute', () => { |
|
|
|
test('Component toHTML with quotes in attribute', () => { |
|
|
|
obj = new Component(); |
|
|
|
let attrs = obj.get('attributes'); |
|
|
|
attrs['data-test'] = '"value"'; |
|
|
|
@ -161,7 +161,7 @@ module.exports = { |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Manage correctly boolean attributes', () => { |
|
|
|
test('Manage correctly boolean attributes', () => { |
|
|
|
obj = new Component(); |
|
|
|
obj.set('attributes', { |
|
|
|
'data-test': 'value', |
|
|
|
@ -174,19 +174,19 @@ module.exports = { |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse empty div', () => { |
|
|
|
test('Component parse empty div', () => { |
|
|
|
var el = document.createElement('div'); |
|
|
|
obj = Component.isComponent(el); |
|
|
|
expect(obj).toEqual({ tagName: 'div' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse span', () => { |
|
|
|
test('Component parse span', () => { |
|
|
|
var el = document.createElement('span'); |
|
|
|
obj = Component.isComponent(el); |
|
|
|
expect(obj).toEqual({ tagName: 'span' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setClass single class string', () => { |
|
|
|
test('setClass single class string', () => { |
|
|
|
obj.setClass('class1'); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(1); |
|
|
|
@ -194,73 +194,73 @@ module.exports = { |
|
|
|
expect(result[0].get('name')).toEqual('class1'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setClass multiple class string', () => { |
|
|
|
test('setClass multiple class string', () => { |
|
|
|
obj.setClass('class1 class2'); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setClass single class array', () => { |
|
|
|
test('setClass single class array', () => { |
|
|
|
obj.setClass(['class1']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setClass multiple class array', () => { |
|
|
|
test('setClass multiple class array', () => { |
|
|
|
obj.setClass(['class1', 'class2']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('addClass multiple array', () => { |
|
|
|
test('addClass multiple array', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('addClass avoid same name classes', () => { |
|
|
|
test('addClass avoid same name classes', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
obj.addClass(['class1', 'class3']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(3); |
|
|
|
}); |
|
|
|
|
|
|
|
it('removeClass by string', () => { |
|
|
|
test('removeClass by string', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
obj.removeClass('class2'); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('removeClass by string with multiple classes', () => { |
|
|
|
test('removeClass by string with multiple classes', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
obj.removeClass('class2 class1'); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(0); |
|
|
|
}); |
|
|
|
|
|
|
|
it('removeClass by array', () => { |
|
|
|
test('removeClass by array', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
obj.removeClass(['class1', 'class2']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(0); |
|
|
|
}); |
|
|
|
|
|
|
|
it('removeClass do nothing with undefined classes', () => { |
|
|
|
test('removeClass do nothing with undefined classes', () => { |
|
|
|
obj.addClass(['class1', 'class2']); |
|
|
|
obj.removeClass(['class3']); |
|
|
|
const result = obj.get('classes').models; |
|
|
|
expect(result.length).toEqual(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('removeClass actually removes classes from attributes', () => { |
|
|
|
test('removeClass actually removes classes from attributes', () => { |
|
|
|
obj.addClass('class1'); |
|
|
|
obj.removeClass('class1'); |
|
|
|
const result = obj.getAttributes(); |
|
|
|
expect(result.class).toEqual(undefined); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setAttributes', () => { |
|
|
|
test('setAttributes', () => { |
|
|
|
obj.setAttributes({ |
|
|
|
id: 'test', |
|
|
|
'data-test': 'value', |
|
|
|
@ -279,20 +279,20 @@ module.exports = { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('setAttributes overwrites correctly', () => { |
|
|
|
test('setAttributes overwrites correctly', () => { |
|
|
|
obj.setAttributes({ id: 'test', 'data-test': 'value' }); |
|
|
|
obj.setAttributes({ 'data-test': 'value2' }); |
|
|
|
expect(obj.getAttributes()).toEqual({ 'data-test': 'value2' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('append() returns always an array', () => { |
|
|
|
test('append() returns always an array', () => { |
|
|
|
let result = obj.append('<span>text1</span>'); |
|
|
|
expect(result.length).toEqual(1); |
|
|
|
result = obj.append('<span>text1</span><div>text2</div>'); |
|
|
|
expect(result.length).toEqual(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('append() new components as string', () => { |
|
|
|
test('append() new components as string', () => { |
|
|
|
obj.append('<span>text1</span><div>text2</div>'); |
|
|
|
const comps = obj.components(); |
|
|
|
expect(comps.length).toEqual(2); |
|
|
|
@ -300,7 +300,7 @@ module.exports = { |
|
|
|
expect(comps.models[1].get('tagName')).toEqual('div'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('append() new components as Objects', () => { |
|
|
|
test('append() new components as Objects', () => { |
|
|
|
obj.append([{}, {}]); |
|
|
|
const comps = obj.components(); |
|
|
|
expect(comps.length).toEqual(2); |
|
|
|
@ -308,7 +308,7 @@ module.exports = { |
|
|
|
expect(comps.length).toEqual(3); |
|
|
|
}); |
|
|
|
|
|
|
|
it('components() set new collection', () => { |
|
|
|
test('components() set new collection', () => { |
|
|
|
obj.append([{}, {}]); |
|
|
|
obj.components('<span>test</div>'); |
|
|
|
const result = obj.components(); |
|
|
|
@ -316,7 +316,7 @@ module.exports = { |
|
|
|
expect(result.models[0].get('tagName')).toEqual('span'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Propagate properties to children', () => { |
|
|
|
test('Propagate properties to children', () => { |
|
|
|
obj.append({ propagate: 'removable' }); |
|
|
|
const result = obj.components(); |
|
|
|
const newObj = result.models[0]; |
|
|
|
@ -328,7 +328,7 @@ module.exports = { |
|
|
|
expect(child.get('propagate')).toEqual(['removable']); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Ability to stop/change propagation chain', () => { |
|
|
|
test('Ability to stop/change propagation chain', () => { |
|
|
|
obj.append({ |
|
|
|
removable: false, |
|
|
|
draggable: false, |
|
|
|
@ -379,20 +379,20 @@ module.exports = { |
|
|
|
obj = null; |
|
|
|
}); |
|
|
|
|
|
|
|
it('Has src property', () => { |
|
|
|
test('Has src property', () => { |
|
|
|
expect(obj.has('src')).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Not droppable', () => { |
|
|
|
test('Not droppable', () => { |
|
|
|
expect(obj.get('droppable')).toEqual(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('ComponentImage toHTML', () => { |
|
|
|
test('ComponentImage toHTML', () => { |
|
|
|
obj = new ComponentImage(); |
|
|
|
expect(obj.toHTML()).toEqual('<img/>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with attributes', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new ComponentImage({ |
|
|
|
attributes: { alt: 'AltTest' }, |
|
|
|
src: 'testPath' |
|
|
|
@ -400,19 +400,19 @@ module.exports = { |
|
|
|
expect(obj.toHTML()).toEqual('<img alt="AltTest" src="testPath"/>'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Refuse not img element', () => { |
|
|
|
test('Refuse not img element', () => { |
|
|
|
var el = document.createElement('div'); |
|
|
|
obj = ComponentImage.isComponent(el); |
|
|
|
expect(obj).toEqual(''); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse img element', () => { |
|
|
|
test('Component parse img element', () => { |
|
|
|
var el = document.createElement('img'); |
|
|
|
obj = ComponentImage.isComponent(el); |
|
|
|
expect(obj).toEqual({ type: 'image' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse img element with src', () => { |
|
|
|
test('Component parse img element with src', () => { |
|
|
|
var el = document.createElement('img'); |
|
|
|
el.src = 'http://localhost/'; |
|
|
|
obj = ComponentImage.isComponent(el); |
|
|
|
@ -429,15 +429,15 @@ module.exports = { |
|
|
|
obj = null; |
|
|
|
}); |
|
|
|
|
|
|
|
it('Has content property', () => { |
|
|
|
test('Has content property', () => { |
|
|
|
expect(obj.has('content')).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Not droppable', () => { |
|
|
|
test('Not droppable', () => { |
|
|
|
expect(obj.get('droppable')).toEqual(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component toHTML with attributes', () => { |
|
|
|
test('Component toHTML with attributes', () => { |
|
|
|
obj = new ComponentText({ |
|
|
|
attributes: { 'data-test': 'value' }, |
|
|
|
content: 'test content' |
|
|
|
@ -451,24 +451,24 @@ module.exports = { |
|
|
|
describe('Link Component', () => { |
|
|
|
const aEl = document.createElement('a'); |
|
|
|
|
|
|
|
it('Component parse link element', () => { |
|
|
|
test('Component parse link element', () => { |
|
|
|
obj = ComponentLink.isComponent(aEl); |
|
|
|
expect(obj).toEqual({ type: 'link' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse link element with text content', () => { |
|
|
|
test('Component parse link element with text content', () => { |
|
|
|
aEl.innerHTML = 'some text here '; |
|
|
|
obj = ComponentLink.isComponent(aEl); |
|
|
|
expect(obj).toEqual({ type: 'link' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse link element with not only text content', () => { |
|
|
|
test('Component parse link element with not only text content', () => { |
|
|
|
aEl.innerHTML = '<div>Some</div> text <div>here </div>'; |
|
|
|
obj = ComponentLink.isComponent(aEl); |
|
|
|
expect(obj).toEqual({ type: 'link' }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse link element with only not text content', () => { |
|
|
|
test('Component parse link element with only not text content', () => { |
|
|
|
aEl.innerHTML = `<div>Some</div>
|
|
|
|
<div>text</div> |
|
|
|
<div>here </div>`; |
|
|
|
@ -476,7 +476,7 @@ module.exports = { |
|
|
|
expect(obj).toEqual({ type: 'link', editable: 0 }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Link element with only an image inside is not editable', () => { |
|
|
|
test('Link element with only an image inside is not editable', () => { |
|
|
|
aEl.innerHTML = '<img src="##"/>'; |
|
|
|
obj = ComponentLink.isComponent(aEl); |
|
|
|
expect(obj).toEqual({ type: 'link', editable: 0 }); |
|
|
|
@ -484,7 +484,7 @@ module.exports = { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Map Component', () => { |
|
|
|
it('Component parse map iframe', () => { |
|
|
|
test('Component parse map iframe', () => { |
|
|
|
var src = |
|
|
|
'https://maps.google.com/maps?&q=London,UK&z=11&t=q&output=embed'; |
|
|
|
var el = $('<iframe src="' + src + '"></iframe>'); |
|
|
|
@ -492,7 +492,7 @@ module.exports = { |
|
|
|
expect(obj).toEqual({ type: 'map', src }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse not map iframe', () => { |
|
|
|
test('Component parse not map iframe', () => { |
|
|
|
var el = $( |
|
|
|
'<iframe src="https://www.youtube.com/watch?v=jNQXAC9IVRw"></iframe>' |
|
|
|
); |
|
|
|
@ -502,21 +502,21 @@ module.exports = { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Video Component', () => { |
|
|
|
it('Component parse video', () => { |
|
|
|
test('Component parse video', () => { |
|
|
|
var src = 'http://localhost/'; |
|
|
|
var el = $('<video src="' + src + '"></video>'); |
|
|
|
obj = ComponentVideo.isComponent(el.get(0)); |
|
|
|
expect(obj).toEqual({ type: 'video', src }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse youtube video iframe', () => { |
|
|
|
test('Component parse youtube video iframe', () => { |
|
|
|
var src = 'http://www.youtube.com/embed/jNQXAC9IVRw?'; |
|
|
|
var el = $('<iframe src="' + src + '"></video>'); |
|
|
|
obj = ComponentVideo.isComponent(el.get(0)); |
|
|
|
expect(obj).toEqual({ type: 'video', provider: 'yt', src }); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Component parse vimeo video iframe', () => { |
|
|
|
test('Component parse vimeo video iframe', () => { |
|
|
|
var src = 'http://player.vimeo.com/video/2?'; |
|
|
|
var el = $('<iframe src="' + src + '"></video>'); |
|
|
|
obj = ComponentVideo.isComponent(el.get(0)); |
|
|
|
@ -532,19 +532,19 @@ module.exports = { |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
it('Creates component correctly', () => { |
|
|
|
test('Creates component correctly', () => { |
|
|
|
var c = new Components({}, compOpts); |
|
|
|
var m = c.add({}); |
|
|
|
expect(m instanceof Component).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Creates image component correctly', () => { |
|
|
|
test('Creates image component correctly', () => { |
|
|
|
var c = new Components({}, compOpts); |
|
|
|
var m = c.add({ type: 'image' }); |
|
|
|
expect(m instanceof ComponentImage).toEqual(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Creates text component correctly', () => { |
|
|
|
test('Creates text component correctly', () => { |
|
|
|
var c = new Components({}, compOpts); |
|
|
|
var m = c.add({ type: 'text' }); |
|
|
|
expect(m instanceof ComponentText).toEqual(true); |
|
|
|
|