From 3297266b9ce2302e523385543415fe400aee9785 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 6 Jun 2017 00:05:41 +0200 Subject: [PATCH] Update device manager tests --- test/helper.js | 1 + test/main.js | 1 + test/specs/css_composer/e2e/CssComposer.js | 2 +- test/specs/device_manager/index.js | 67 +++++++++ test/specs/device_manager/main.js | 70 --------- test/specs/device_manager/view/DevicesView.js | 136 +++++++++--------- test/specs/dom_components/index.js | 52 ++++--- test/specs/dom_components/model/Component.js | 104 +++++++------- .../dom_components/view/ComponentImageView.js | 22 +-- .../dom_components/view/ComponentTextView.js | 22 +-- test/specs/dom_components/view/ComponentV.js | 46 +++--- .../dom_components/view/ComponentsView.js | 18 +-- 12 files changed, 267 insertions(+), 274 deletions(-) create mode 100644 test/specs/device_manager/index.js delete mode 100644 test/specs/device_manager/main.js diff --git a/test/helper.js b/test/helper.js index 34201b3a5..baef2802f 100644 --- a/test/helper.js +++ b/test/helper.js @@ -30,6 +30,7 @@ global._ = _; global.expect = expect; global.sinon = sinon; global.grapesjs = grapesjs; +global.Backbone = Backbone; window.$ = $; Backbone.$ = $; diff --git a/test/main.js b/test/main.js index 9c9958d24..3d3f24ffa 100644 --- a/test/main.js +++ b/test/main.js @@ -14,5 +14,6 @@ describe('Main', () => { require(`${path}code_manager`); require(`${path}commands`); require(`${path}css_composer`); + require(`${path}device_manager`); require(`${path}dom_components`); }); diff --git a/test/specs/css_composer/e2e/CssComposer.js b/test/specs/css_composer/e2e/CssComposer.js index b06f88f3d..130e4664c 100644 --- a/test/specs/css_composer/e2e/CssComposer.js +++ b/test/specs/css_composer/e2e/CssComposer.js @@ -15,7 +15,7 @@ module.exports = { fixture = $('
'); }); - beforeEach(function(done) { + beforeEach(done => { //this.timeout(5000); gjs = grapesjs.init({ stylePrefix: '', diff --git a/test/specs/device_manager/index.js b/test/specs/device_manager/index.js new file mode 100644 index 000000000..78d4d8bcd --- /dev/null +++ b/test/specs/device_manager/index.js @@ -0,0 +1,67 @@ +const DeviceManager = require('device_manager'); +const DevicesView = require('./view/DevicesView'); + +describe('DeviceManager', () => { + + describe('Main', () => { + + var obj; + var testNameDevice; + var testWidthDevice; + + beforeEach(() => { + testNameDevice = 'Tablet'; + testWidthDevice = '100px'; + obj = new DeviceManager().init(); + }); + + afterEach(() => { + obj = null; + }); + + it('Object exists', () => { + expect(obj).toExist(); + }); + + it('No device inside', () => { + var coll = obj.getAll(); + expect(coll.length).toEqual(0); + }); + + it('Add new device', () => { + var model = obj.add(testNameDevice, testWidthDevice); + expect(obj.getAll().length).toEqual(1); + }); + + it('Added device has correct data', () => { + var model = obj.add(testNameDevice, testWidthDevice); + expect(model.get('name')).toEqual(testNameDevice); + expect(model.get('width')).toEqual(testWidthDevice); + }); + + it('Add device width options', () => { + var model = obj.add(testNameDevice, testWidthDevice, {opt: 'value'}); + expect(model.get('opt')).toEqual('value'); + }); + + it('The name of the device is unique', () => { + var model = obj.add(testNameDevice, testWidthDevice); + var model2 = obj.add(testNameDevice, '2px'); + expect(model).toEqual(model2); + }); + + it('Get device by name', () => { + var model = obj.add(testNameDevice, testWidthDevice); + var model2 = obj.get(testNameDevice); + expect(model).toEqual(model2); + }); + + it('Render devices', () => { + expect(obj.render()).toExist(); + }); + + }); + + DevicesView.run(); + +}); diff --git a/test/specs/device_manager/main.js b/test/specs/device_manager/main.js deleted file mode 100644 index ebb971839..000000000 --- a/test/specs/device_manager/main.js +++ /dev/null @@ -1,70 +0,0 @@ -define(function(require, exports, module){ - 'use strict'; - var DeviceManager = require('DeviceManager'); - var DevicesView = require('undefined'); - - describe('DeviceManager', function() { - - describe('Main', function() { - - var obj; - var testNameDevice; - var testWidthDevice; - - beforeEach(function () { - testNameDevice = 'Tablet'; - testWidthDevice = '100px'; - obj = new DeviceManager().init(); - }); - - afterEach(function () { - delete obj; - }); - - it('Object exists', function() { - obj.should.be.exist; - }); - - it('No device inside', function() { - var coll = obj.getAll(); - coll.length.should.equal(0); - }); - - it('Add new device', function() { - var model = obj.add(testNameDevice, testWidthDevice); - obj.getAll().length.should.equal(1); - }); - - it('Added device has correct data', function() { - var model = obj.add(testNameDevice, testWidthDevice); - model.get('name').should.equal(testNameDevice); - model.get('width').should.equal(testWidthDevice); - }); - - it('Add device width options', function() { - var model = obj.add(testNameDevice, testWidthDevice, {opt: 'value'}); - model.get('opt').should.equal('value'); - }); - - it('The name of the device is unique', function() { - var model = obj.add(testNameDevice, testWidthDevice); - var model2 = obj.add(testNameDevice, '2px'); - model.should.deep.equal(model2); - }); - - it('Get device by name', function() { - var model = obj.add(testNameDevice, testWidthDevice); - var model2 = obj.get(testNameDevice); - model.should.deep.equal(model2); - }); - - it('Render devices', function() { - obj.render().should.be.ok; - }); - - }); - - DevicesView.run(); - - }); -}); \ No newline at end of file diff --git a/test/specs/device_manager/view/DevicesView.js b/test/specs/device_manager/view/DevicesView.js index 1a8a0206c..e2836b0a0 100644 --- a/test/specs/device_manager/view/DevicesView.js +++ b/test/specs/device_manager/view/DevicesView.js @@ -1,83 +1,79 @@ -define(function(require, exports, module){ - 'use strict'; - var DevicesView = require('undefined'); - var Devices = require('DeviceManager/model/Devices'); - - module.exports = { - run : function(){ - describe('DevicesView', function() { - - var $fixtures; - var $fixture; - var model; - var view; - var editorModel; +const DevicesView = require('device_manager/view/DevicesView'); +const Devices = require('device_manager/model/Devices'); + +module.exports = { + run() { + describe('DevicesView', () => { + + var $fixtures; + var $fixture; + var model; + var view; + var editorModel; + + before(() => { + $fixtures = $("#fixtures"); + $fixture = $('
'); + }); - before(function () { - $fixtures = $("#fixtures"); - $fixture = $('
'); - }); + beforeEach(() => { + model = new Devices([]); + view = new DevicesView({ + collection: model + }); + $fixture.empty().appendTo($fixtures); + $fixture.html(view.render().el); + }); - beforeEach(function () { - model = new Devices([]); - view = new DevicesView({ - collection: model - }); - $fixture.empty().appendTo($fixtures); - $fixture.html(view.render().el); - }); + afterEach(() => { + view.collection.reset(); + }); - afterEach(function () { - view.collection.reset(); - }); + after(() => { + $fixture.remove(); + }); - after(function () { - $fixture.remove(); - }); + it("The content is not empty", () => { + expect(view.el.innerHTML).toExist(); + }); - it("The content is not empty", function (){ - view.el.innerHTML.should.be.not.empty; - }); + it("No options without devices", () => { + expect(view.getOptions()).toEqual(''); + }); - it("No options without devices", function (){ - view.getOptions().should.equal(''); - }); + it("Render new button", () => { + view.collection.add({}); + expect(view.$el.html()).toExist(); + }); - it("Render new button", function (){ - view.collection.add({}); - view.$el.html().should.not.be.empty; + describe('With configs', () => { + + beforeEach(() => { + editorModel = new Backbone.Model(); + model = new Devices([ + {name:'test1'}, + {name:'test2'} + ]); + view = new DevicesView({ + collection: model, + config: { em: editorModel } }); + $fixture.empty().appendTo($fixtures); + $fixture.html(view.render().el); + }); - describe('With configs', function() { + it("Update device on select change", () => { + view.$el.find('select').val('test2'); + view.updateDevice(); + expect(view.config.em.get('device')).toEqual('test2'); + }); - beforeEach(function () { - editorModel = new Backbone.Model(); - model = new Devices([ - {name:'test1'}, - {name:'test2'} - ]); - view = new DevicesView({ - collection: model, - config: { em: editorModel } - }); - $fixture.empty().appendTo($fixtures); - $fixture.html(view.render().el); - }); - - it("Update device on select change", function (){ - view.$el.find('select').val('test2'); - view.updateDevice(); - view.config.em.get('device').should.equal('test2'); - }); - - it("Render options", function (){ - view.getOptions().should.equal(''); - }); - - }); + it("Render options", () => { + expect(view.getOptions()).toEqual(''); + }); }); - } - }; -}); \ No newline at end of file + }); + } +}; diff --git a/test/specs/dom_components/index.js b/test/specs/dom_components/index.js index 0e496bbe1..5c35a96cb 100644 --- a/test/specs/dom_components/index.js +++ b/test/specs/dom_components/index.js @@ -6,9 +6,9 @@ const ComponentTextView = require('./view/ComponentTextView'); const ComponentImageView = require('./view/ComponentImageView'); const utils = require('./../test_utils.js'); -describe('DOM Components', function() { +describe('DOM Components', () => { - describe('Main', function() { + describe('Main', () => { var obj; var config; @@ -17,48 +17,46 @@ describe('DOM Components', function() { config: { loadCompsOnRender: 0, }, - get: function(){return;}, - getHtml: function(){return 'testHtml';}, - getComponents: function(){return {test: 1};}, - getCacheLoad: function(){ + get() {return;}, + getHtml() {return 'testHtml';}, + getComponents() {return {test: 1};}, + getCacheLoad() { return storagMock.load(); } }; // Methods - var setSmConfig = function(){ + var setSmConfig = () => { config.stm = storagMock; - config.stm.getConfig = function(){ - return { - storeHtml: 1, - storeComponents: 1, - } - }; + config.stm.getConfig = () => ({ + storeHtml: 1, + storeComponents: 1 + }); }; - var setEm = function(){ + var setEm = () => { config.em = editorModel; } - beforeEach(function () { + beforeEach(() => { config = {}; obj = new DomComponents().init(config); }); - afterEach(function () { + afterEach(() => { obj = null; }); - it('Object exists', function() { + it('Object exists', () => { expect(DomComponents).toExist(); }); - it('storageKey returns array', function() { + it('storageKey returns array', () => { expect(obj.storageKey() instanceof Array).toEqual(true); }); - it('storageKey returns correct composition', function() { + it('storageKey returns correct composition', () => { config.stm = { - getConfig: function(){ + getConfig() { return { storeHtml: 1, storeComponents: 1, @@ -68,7 +66,7 @@ describe('DOM Components', function() { expect(obj.storageKey()).toEqual(['html', 'components']); }); - it('Store data', function() { + it('Store data', () => { setSmConfig(); setEm(); var expected = { @@ -78,32 +76,32 @@ describe('DOM Components', function() { expect(obj.store(1)).toEqual(expected); }); - it('Store and load data', function() { + it('Store and load data', () => { setSmConfig(); setEm(); obj.store(); expect(obj.load()).toEqual({test: 1}); }); - it('Wrapper exists', function() { + it('Wrapper exists', () => { expect(obj.getWrapper()).toExist(); }); - it('No components inside', function() { + it('No components inside', () => { expect(obj.getComponents().length).toEqual(0); }); - it('Add new component', function() { + it('Add new component', () => { var comp = obj.addComponent({}); expect(obj.getComponents().length).toEqual(1); }); - it('Add more components at once', function() { + it('Add more components at once', () => { var comp = obj.addComponent([{},{}]); expect(obj.getComponents().length).toEqual(2); }); - it('Render wrapper', function() { + it('Render wrapper', () => { expect(obj.render()).toExist(); }); }); diff --git a/test/specs/dom_components/model/Component.js b/test/specs/dom_components/model/Component.js index 48f7b0dda..019f2108a 100644 --- a/test/specs/dom_components/model/Component.js +++ b/test/specs/dom_components/model/Component.js @@ -8,14 +8,14 @@ const ComponentVideo = require('dom_components/model/ComponentVideo'); const Components = require('dom_components/model/Components'); module.exports = { - run : function(){ + run() { var obj; var dcomp; var compOpts; - describe('Component', function() { + describe('Component', () => { - beforeEach(function () { + beforeEach(() => { obj = new Component(); dcomp = new DomComponents(); compOpts = { @@ -23,15 +23,15 @@ module.exports = { }; }); - afterEach(function () { + afterEach(() => { obj = null; }); - it('Has no children', function() { + it('Has no children', () => { expect(obj.get('components').length).toEqual(0); }); - it('Clones correctly', function() { + it('Clones correctly', () => { var sAttr = obj.attributes; var cloned = obj.clone(); var eAttr = cloned.attributes; @@ -42,7 +42,7 @@ module.exports = { expect(sAttr.length).toEqual(eAttr.length); }); - it('Clones correctly with traits', function() { + it('Clones correctly with traits', () => { obj.get('traits').at(0).set('value', 'testTitle'); var cloned = obj.clone(); cloned.set('stylable', 0); @@ -51,21 +51,21 @@ module.exports = { expect(obj.get('stylable')).toEqual(true); }); - it('Has expected name', function() { + it('Has expected name', () => { expect(obj.getName()).toEqual('Box'); }); - it('Has expected name 2', function() { + it('Has expected name 2', () => { obj.cid = 'c999'; obj.set('type','testType'); expect(obj.getName()).toEqual('TestType'); }); - it('Component toHTML', function() { + it('Component toHTML', () => { expect(obj.toHTML()).toEqual('
'); }); - it('Component toHTML with attributes', function() { + it('Component toHTML with attributes', () => { obj = new Component({ tagName: 'article', attributes: { @@ -76,40 +76,40 @@ module.exports = { expect(obj.toHTML()).toEqual('
'); }); - it('Component toHTML with classes', function() { + it('Component toHTML with classes', () => { obj = new Component({ tagName: 'article' }); - ['class1', 'class2'].forEach(function(item){ + ['class1', 'class2'].forEach(item => { obj.get('classes').add({name: item}); }); expect(obj.toHTML()).toEqual('
'); }); - it('Component toHTML with children', function() { + it('Component toHTML with children', () => { obj = new Component({tagName: 'article'}, compOpts); obj.get('components').add({tagName: 'span'}); expect(obj.toHTML()).toEqual('
'); }); - it('Component toHTML with more children', function() { + it('Component toHTML with more children', () => { obj = new Component({tagName: 'article'}, compOpts); obj.get('components').add([{tagName: 'span'}, {tagName: 'div'}]); expect(obj.toHTML()).toEqual('
'); }); - it('Component toHTML with no closing tag', function() { + it('Component toHTML with no closing tag', () => { obj = new Component({void: 1}); expect(obj.toHTML()).toEqual('
'); }); - it('Component parse empty div', function() { + it('Component parse empty div', () => { var el = document.createElement('div'); obj = Component.isComponent(el); expect(obj).toEqual({tagName: 'div'}); }); - it('Component parse span', function() { + it('Component parse span', () => { var el = document.createElement('span'); obj = Component.isComponent(el); expect(obj).toEqual({tagName: 'span'}); @@ -117,30 +117,30 @@ module.exports = { }); - describe('Image Component', function() { + describe('Image Component', () => { - beforeEach(function () { + beforeEach(() => { obj = new ComponentImage(); }); - afterEach(function () { + afterEach(() => { obj = null; }); - it('Has src property', function() { + it('Has src property', () => { expect(obj.has('src')).toEqual(true); }); - it('Not droppable', function() { + it('Not droppable', () => { expect(obj.get('droppable')).toEqual(false); }); - it('ComponentImage toHTML', function() { + it('ComponentImage toHTML', () => { obj = new ComponentImage(); expect(obj.toHTML()).toEqual(''); }); - it('Component toHTML with attributes', function() { + it('Component toHTML with attributes', () => { obj = new ComponentImage({ attributes: {'alt': 'AltTest'}, src: 'testPath' @@ -148,19 +148,19 @@ module.exports = { expect(obj.toHTML()).toEqual('AltTest'); }); - it('Refuse not img element', function() { + it('Refuse not img element', () => { var el = document.createElement('div'); obj = ComponentImage.isComponent(el); expect(obj).toEqual(''); }); - it('Component parse img element', function() { + it('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', function() { + it('Component parse img element with src', () => { var el = document.createElement('img'); el.src = 'http://localhost/'; obj = ComponentImage.isComponent(el); @@ -169,25 +169,25 @@ module.exports = { }); - describe('Text Component', function() { + describe('Text Component', () => { - beforeEach(function () { + beforeEach(() => { obj = new ComponentText(); }); - afterEach(function () { + afterEach(() => { obj = null; }); - it('Has content property', function() { + it('Has content property', () => { expect(obj.has('content')).toEqual(true); }); - it('Not droppable', function() { + it('Not droppable', () => { expect(obj.get('droppable')).toEqual(false); }); - it('Component toHTML with attributes', function() { + it('Component toHTML with attributes', () => { obj = new ComponentText({ attributes: {'data-test': 'value'}, content: 'test content' @@ -197,9 +197,9 @@ module.exports = { }); - describe('Link Component', function() { + describe('Link Component', () => { - it('Component parse a element', function() { + it('Component parse a element', () => { var el = document.createElement('a'); obj = ComponentLink.isComponent(el); expect(obj).toEqual({type: 'link'}); @@ -207,16 +207,16 @@ module.exports = { }); - describe('Map Component', function() { + describe('Map Component', () => { - it('Component parse map iframe', function() { + it('Component parse map iframe', () => { var src = 'https://maps.google.com/maps?&q=London,UK&z=11&t=q&output=embed'; var el = $(''); obj = ComponentMap.isComponent(el.get(0)); - expect(obj).toEqual({type: 'map', src: src}); + expect(obj).toEqual({type: 'map', src}); }); - it('Component parse not map iframe', function() { + it('Component parse not map iframe', () => { var el = $(''); obj = ComponentMap.isComponent(el.get(0)); expect(obj).toEqual(''); @@ -224,53 +224,53 @@ module.exports = { }); - describe('Video Component', function() { + describe('Video Component', () => { - it('Component parse video', function() { + it('Component parse video', () => { var src = 'http://localhost/'; var el = $(''); obj = ComponentVideo.isComponent(el.get(0)); - expect(obj).toEqual({type: 'video', src: src}); + expect(obj).toEqual({type: 'video', src}); }); - it('Component parse youtube video iframe', function() { + it('Component parse youtube video iframe', () => { var src = 'http://www.youtube.com/embed/jNQXAC9IVRw?'; var el = $('