|
|
|
@ -1,10 +1,5 @@ |
|
|
|
import DomComponents from 'dom_components'; |
|
|
|
import Components from 'dom_components/model/Components'; |
|
|
|
import ComponentModels from './model/Component'; |
|
|
|
import ComponentView from './view/ComponentV'; |
|
|
|
import ComponentsView from './view/ComponentsView'; |
|
|
|
import ComponentTextView from './view/ComponentTextView'; |
|
|
|
import ComponentImageView from './view/ComponentImageView'; |
|
|
|
import Editor from 'editor/model/Editor'; |
|
|
|
import utils from './../../test_utils.js'; |
|
|
|
|
|
|
|
@ -16,7 +11,7 @@ describe('DOM Components', () => { |
|
|
|
var storagMock = utils.storageMock(); |
|
|
|
var editorModel = { |
|
|
|
config: { |
|
|
|
loadCompsOnRender: 0 |
|
|
|
loadCompsOnRender: 0, |
|
|
|
}, |
|
|
|
get() { |
|
|
|
return {}; |
|
|
|
@ -35,14 +30,14 @@ describe('DOM Components', () => { |
|
|
|
}, |
|
|
|
getCacheLoad() { |
|
|
|
return storagMock.load(); |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
// Methods
|
|
|
|
var setSmConfig = () => { |
|
|
|
config.stm = storagMock; |
|
|
|
config.stm.getConfig = () => ({ |
|
|
|
storeHtml: 1, |
|
|
|
storeComponents: 1 |
|
|
|
storeComponents: 1, |
|
|
|
}); |
|
|
|
}; |
|
|
|
var setEm = () => { |
|
|
|
@ -51,12 +46,12 @@ describe('DOM Components', () => { |
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
em = new Editor({ |
|
|
|
avoidInlineStyle: 1 |
|
|
|
avoidInlineStyle: 1, |
|
|
|
}); |
|
|
|
em.get('PageManager').onLoad(); |
|
|
|
config = { |
|
|
|
em, |
|
|
|
storeWrapper: 1 |
|
|
|
storeWrapper: 1, |
|
|
|
}; |
|
|
|
obj = em.get('DomComponents'); |
|
|
|
// obj = new DomComponents().init(config);
|
|
|
|
@ -79,9 +74,9 @@ describe('DOM Components', () => { |
|
|
|
getConfig() { |
|
|
|
return { |
|
|
|
storeHtml: 1, |
|
|
|
storeComponents: 1 |
|
|
|
storeComponents: 1, |
|
|
|
}; |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
expect(obj.storageKey()).toEqual(['html', 'components']); |
|
|
|
}); |
|
|
|
@ -94,7 +89,7 @@ describe('DOM Components', () => { |
|
|
|
(obj = em.get('DomComponents').init(config)); |
|
|
|
var expected = { |
|
|
|
html: 'testHtml', |
|
|
|
components: JSON.stringify(obj.getWrapper()) |
|
|
|
components: JSON.stringify(obj.getWrapper()), |
|
|
|
}; |
|
|
|
expect(obj.store(1)).toEqual(expected); |
|
|
|
}); |
|
|
|
@ -112,7 +107,7 @@ describe('DOM Components', () => { |
|
|
|
const result = [{}, {}]; |
|
|
|
expect( |
|
|
|
obj.load({ |
|
|
|
components: '[{}, {}]' |
|
|
|
components: '[{}, {}]', |
|
|
|
}) |
|
|
|
).toEqual(result); |
|
|
|
}); |
|
|
|
@ -121,7 +116,7 @@ describe('DOM Components', () => { |
|
|
|
const result = [{}, {}]; |
|
|
|
expect( |
|
|
|
obj.load({ |
|
|
|
components: result |
|
|
|
components: result, |
|
|
|
}) |
|
|
|
).toEqual(result); |
|
|
|
}); |
|
|
|
@ -130,7 +125,7 @@ describe('DOM Components', () => { |
|
|
|
const result = {}; |
|
|
|
expect( |
|
|
|
obj.load({ |
|
|
|
components: result |
|
|
|
components: result, |
|
|
|
}) |
|
|
|
).toEqual(result); |
|
|
|
}); |
|
|
|
@ -164,16 +159,13 @@ describe('DOM Components', () => { |
|
|
|
</style>`); |
|
|
|
expect(em.getHtml()).toEqual(`<div id="${id}">Text</div>`); |
|
|
|
expect(obj.getComponents().length).toEqual(1); |
|
|
|
obj |
|
|
|
.getComponents() |
|
|
|
.first() |
|
|
|
.addStyle({ margin: '10px' }); |
|
|
|
obj.getComponents().first().addStyle({ margin: '10px' }); |
|
|
|
expect(cc.getAll().length).toEqual(1); |
|
|
|
expect(cc.getIdRule(id).getStyle()).toEqual({ |
|
|
|
color: 'red', |
|
|
|
'background-color': 'red', |
|
|
|
padding: '50px 100px', |
|
|
|
margin: '10px' |
|
|
|
margin: '10px', |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -185,9 +177,9 @@ describe('DOM Components', () => { |
|
|
|
obj.addType(id, { |
|
|
|
model: { |
|
|
|
defaults: { |
|
|
|
testProp |
|
|
|
} |
|
|
|
} |
|
|
|
testProp, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
expect(obj.componentTypes.length).toEqual(initialTypes + 1); |
|
|
|
obj.addComponent(`<div data-gjs-type="${id}"></div>`); |
|
|
|
@ -203,7 +195,7 @@ describe('DOM Components', () => { |
|
|
|
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>`); |
|
|
|
@ -220,14 +212,14 @@ describe('DOM Components', () => { |
|
|
|
obj.addType(id, { |
|
|
|
model: { |
|
|
|
defaults: () => ({ |
|
|
|
testProp |
|
|
|
}) |
|
|
|
testProp, |
|
|
|
}), |
|
|
|
}, |
|
|
|
view: { |
|
|
|
onRender() { |
|
|
|
this.el.style.backgroundColor = 'red'; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
expect(obj.getTypes().length).toBe(initialTypes); |
|
|
|
obj.addComponent(`<img src="##"/>`); |
|
|
|
@ -245,9 +237,9 @@ describe('DOM Components', () => { |
|
|
|
extend: 'image', |
|
|
|
model: { |
|
|
|
defaults: { |
|
|
|
testProp |
|
|
|
} |
|
|
|
} |
|
|
|
testProp, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
obj.addComponent(`<img src="##"/>`); |
|
|
|
expect(obj.getTypes()[0].id).toEqual(id); |
|
|
|
@ -264,7 +256,7 @@ describe('DOM Components', () => { |
|
|
|
const testProp = 'testValue'; |
|
|
|
obj.addType(id, { |
|
|
|
extend: 'image', |
|
|
|
isComponent: el => el.getAttribute('test-prop') === testProp |
|
|
|
isComponent: el => el.getAttribute('test-prop') === testProp, |
|
|
|
}); |
|
|
|
obj.addComponent(`<img src="##" test-prop="${testProp}"/>`); |
|
|
|
expect(obj.getTypes()[0].id).toEqual(id); |
|
|
|
|