diff --git a/test/main.js b/test/main.js index 91eec0d48..9c9958d24 100644 --- a/test/main.js +++ b/test/main.js @@ -14,4 +14,5 @@ describe('Main', () => { require(`${path}code_manager`); require(`${path}commands`); require(`${path}css_composer`); + require(`${path}dom_components`); }); diff --git a/test/specs/dom_components/index.js b/test/specs/dom_components/index.js new file mode 100644 index 000000000..0e496bbe1 --- /dev/null +++ b/test/specs/dom_components/index.js @@ -0,0 +1,117 @@ +const DomComponents = require('dom_components'); +const ComponentModels = require('./model/Component'); +const ComponentView = require('./view/ComponentV'); +const ComponentsView = require('./view/ComponentsView'); +const ComponentTextView = require('./view/ComponentTextView'); +const ComponentImageView = require('./view/ComponentImageView'); +const utils = require('./../test_utils.js'); + +describe('DOM Components', function() { + + describe('Main', function() { + + var obj; + var config; + var storagMock = utils.storageMock(); + var editorModel = { + config: { + loadCompsOnRender: 0, + }, + get: function(){return;}, + getHtml: function(){return 'testHtml';}, + getComponents: function(){return {test: 1};}, + getCacheLoad: function(){ + return storagMock.load(); + } + }; + // Methods + var setSmConfig = function(){ + config.stm = storagMock; + config.stm.getConfig = function(){ + return { + storeHtml: 1, + storeComponents: 1, + } + }; + }; + var setEm = function(){ + config.em = editorModel; + } + + + beforeEach(function () { + config = {}; + obj = new DomComponents().init(config); + }); + + afterEach(function () { + obj = null; + }); + + it('Object exists', function() { + expect(DomComponents).toExist(); + }); + + it('storageKey returns array', function() { + expect(obj.storageKey() instanceof Array).toEqual(true); + }); + + it('storageKey returns correct composition', function() { + config.stm = { + getConfig: function(){ + return { + storeHtml: 1, + storeComponents: 1, + } + } + }; + expect(obj.storageKey()).toEqual(['html', 'components']); + }); + + it('Store data', function() { + setSmConfig(); + setEm(); + var expected = { + html: 'testHtml', + components: '{"test":1}', + }; + expect(obj.store(1)).toEqual(expected); + }); + + it('Store and load data', function() { + setSmConfig(); + setEm(); + obj.store(); + expect(obj.load()).toEqual({test: 1}); + }); + + it('Wrapper exists', function() { + expect(obj.getWrapper()).toExist(); + }); + + it('No components inside', function() { + expect(obj.getComponents().length).toEqual(0); + }); + + it('Add new component', function() { + var comp = obj.addComponent({}); + expect(obj.getComponents().length).toEqual(1); + }); + + it('Add more components at once', function() { + var comp = obj.addComponent([{},{}]); + expect(obj.getComponents().length).toEqual(2); + }); + + it('Render wrapper', function() { + expect(obj.render()).toExist(); + }); + }); + + ComponentModels.run(); + ComponentView.run(); + ComponentsView.run(); + ComponentTextView.run(); + ComponentImageView.run(); + +}); diff --git a/test/specs/dom_components/main.js b/test/specs/dom_components/main.js deleted file mode 100644 index 86455cdaf..000000000 --- a/test/specs/dom_components/main.js +++ /dev/null @@ -1,125 +0,0 @@ -define(function(require, exports, module){ - 'use strict'; - var DomComponents = require('DomComponents'); - var ComponentImageView = require('undefined'); - var utils = require('./../test_utils.js'); - - describe('DOM Components', function() { - - describe('Main', function() { - - var obj; - var config; - var storagMock = utils.storageMock(); - var editorModel = { - config: { - loadCompsOnRender: 0, - }, - get: function(){return;}, - getHtml: function(){return 'testHtml';}, - getComponents: function(){return {test: 1};}, - getCacheLoad: function(){ - return storagMock.load(); - } - }; - // Methods - var setSmConfig = function(){ - config.stm = storagMock; - config.stm.getConfig = function(){ - return { - storeHtml: 1, - storeComponents: 1, - } - }; - }; - var setEm = function(){ - config.em = editorModel; - } - - - beforeEach(function () { - config = {}; - obj = new DomComponents().init(config); - }); - - afterEach(function () { - delete obj; - }); - - it('Object exists', function() { - DomComponents.should.be.exist; - }); - - it('storageKey returns array', function() { - obj.storageKey().should.be.instanceOf(Array); - }); - - it('storageKey returns correct composition', function() { - config.stm = { - getConfig: function(){ - return { - storeHtml: 1, - storeComponents: 1, - } - } - }; - obj.storageKey().should.eql(['html', 'components']); - }); - - it('Store data', function() { - setSmConfig(); - setEm(); - var expected = { - html: 'testHtml', - components: '{"test":1}', - }; - obj.store(1).should.deep.equal(expected); - }); - - it('Store and load data', function() { - setSmConfig(); - setEm(); - obj.store(); - // Load object between html and components - obj.load().should.deep.equal({test: 1}); - }); - - it('Wrapper exists', function() { - obj.getWrapper().should.not.be.empty; - }); - - it('No components inside', function() { - obj.getComponents().length.should.equal(0); - }); - - it('Add new component', function() { - var comp = obj.addComponent({}); - obj.getComponents().length.should.equal(1); - }); - - it('Add more components at once', function() { - var comp = obj.addComponent([{},{}]); - obj.getComponents().length.should.equal(2); - }); - - it('Render wrapper', function() { - obj.render().should.be.ok; - }); - - it.skip('Add components at init', function() { - obj = new DomComponents().init({ - components : [{}, {}, {}] - }); - obj.getComponents().length.should.equal(3); - }); - - }); - - ComponentModels.run(); - ComponentView.run(); - ComponentsView.run(); - ComponentTextView.run(); - ComponentImageView.run(); - - }); -}); \ No newline at end of file diff --git a/test/specs/dom_components/model/Component.js b/test/specs/dom_components/model/Component.js index d9d746220..48f7b0dda 100644 --- a/test/specs/dom_components/model/Component.js +++ b/test/specs/dom_components/model/Component.js @@ -1,285 +1,281 @@ -define(function(require, exports, module){ - 'use strict'; - var DomComponents = require('DomComponents'); - var Component = require('DomComponents/model/Component'); - var ComponentImage = require('DomComponents/model/ComponentImage'); - var ComponentText = require('DomComponents/model/ComponentText'); - var ComponentLink = require('DomComponents/model/ComponentLink'); - var ComponentMap = require('DomComponents/model/ComponentMap'); - var ComponentVideo = require('DomComponents/model/ComponentVideo'); - var Components = require('DomComponents/model/Components'); - - module.exports = { - run : function(){ - var obj; - var dcomp; - var compOpts; - - describe('Component', function() { - - beforeEach(function () { - obj = new Component(); - dcomp = new DomComponents(); - compOpts = { - defaultTypes: dcomp.componentTypes, - }; - }); - - afterEach(function () { - delete obj; - }); - - it('Has no children', function() { - obj.get('components').length.should.equal(0); - }); - - it.skip('Clones correctly', function() { - var sAttr = obj.attributes; - var cloned = obj.clone(); - var eAttr = cloned.attributes; - eAttr.components = {}; - sAttr.components = {}; - eAttr.traits = {}; - sAttr.traits = {}; - sAttr.should.deep.equal(eAttr); - }); - - it('Clones correctly with traits', function() { - obj.get('traits').at(0).set('value', 'testTitle'); - var cloned = obj.clone(); - cloned.set('stylable', 0); - cloned.get('traits').at(0).set('value', 'testTitle2'); - obj.get('traits').at(0).get('value').should.equal('testTitle'); - obj.get('stylable').should.equal(true); - }); - - it('Has expected name', function() { - obj.getName().should.equal('Box'); - }); - - it('Has expected name 2', function() { - obj.cid = 'c999'; - obj.set('type','testType'); - obj.getName().should.equal('TestType'); - }); - - it('Component toHTML', function() { - obj.toHTML().should.equal('
'); - }); - - it('Component toHTML with attributes', function() { - obj = new Component({ - tagName: 'article', - attributes: { - 'data-test1': 'value1', - 'data-test2': 'value2' - } - }); - obj.toHTML().should.equal(''); - }); - - it('Component toHTML with classes', function() { - obj = new Component({ - tagName: 'article' - }); - ['class1', 'class2'].forEach(function(item){ - obj.get('classes').add({name: item}); - }); - obj.toHTML().should.equal(''); - }); - - it('Component toHTML with children', function() { - obj = new Component({tagName: 'article'}, compOpts); - obj.get('components').add({tagName: 'span'}); - obj.toHTML().should.equal('