From 37a49e762605e1c38fe585d0ea7646b9cb362134 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 30 Apr 2016 15:59:57 +0200 Subject: [PATCH] Add SectorView tests --- src/style_manager/view/PropertiesView.js | 4 +- src/style_manager/view/SectorView.js | 4 +- test/specs/style_manager/main.js | 5 +- test/specs/style_manager/view/SectorView.js | 108 ++++++++++++++++++++ 4 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 test/specs/style_manager/view/SectorView.js diff --git a/src/style_manager/view/PropertiesView.js b/src/style_manager/view/PropertiesView.js index 492a56d91..bce404521 100644 --- a/src/style_manager/view/PropertiesView.js +++ b/src/style_manager/view/PropertiesView.js @@ -8,8 +8,8 @@ define(['backbone','./PropertyView', './PropertyIntegerView', './PropertyRadioVi return Backbone.View.extend({ initialize: function(o) { - this.config = o.config; - this.pfx = this.config.stylePrefix; + this.config = o.config || {}; + this.pfx = this.config.stylePrefix || ''; this.target = o.target || {}; this.propTarget = o.propTarget || {}; this.onChange = o.onChange || {}; diff --git a/src/style_manager/view/SectorView.js b/src/style_manager/view/SectorView.js index 60fc4e608..b9c2cd285 100644 --- a/src/style_manager/view/SectorView.js +++ b/src/style_manager/view/SectorView.js @@ -10,8 +10,8 @@ define(['backbone', './PropertiesView', 'text!./../templates/sector.html'], events:{}, initialize: function(o) { - this.config = o.config; - this.pfx = this.config.stylePrefix; + this.config = o.config || {}; + this.pfx = this.config.stylePrefix || ''; this.target = o.target || {}; this.propTarget = o.propTarget || {}; this.open = this.model.get('open'); diff --git a/test/specs/style_manager/main.js b/test/specs/style_manager/main.js index fa1f9d719..515e7a8f9 100644 --- a/test/specs/style_manager/main.js +++ b/test/specs/style_manager/main.js @@ -3,10 +3,12 @@ var modulePath = './../../../test/specs/style_manager'; define([ 'StyleManager', modulePath + '/model/Models', + modulePath + '/view/SectorView', ], function( StyleManager, - Models + Models, + SectorView ) { describe('StyleManager', function() { @@ -173,6 +175,7 @@ define([ }); Models.run(); + SectorView.run(); }); diff --git a/test/specs/style_manager/view/SectorView.js b/test/specs/style_manager/view/SectorView.js new file mode 100644 index 000000000..48fb33dfb --- /dev/null +++ b/test/specs/style_manager/view/SectorView.js @@ -0,0 +1,108 @@ +var path = 'StyleManager/view/'; +define([path + 'SectorView', 'StyleManager/model/Sector'], + function(SectorView, Sector) { + + return { + run : function(){ + + describe('SectorView', function() { + + var $fixtures; + var $fixture; + var model; + var view; + + before(function () { + $fixtures = $("#fixtures"); + $fixture = $('
'); + }); + + beforeEach(function () { + model = new Sector(); + view = new SectorView({ + model: model + }); + $fixture.empty().appendTo($fixtures); + $fixture.html(view.render().el); + }); + + afterEach(function () { + view.remove(); + }); + + after(function () { + $fixture.remove(); + }); + + it('Rendered correctly', function() { + var sector = view.el; + sector.should.be.ok; + sector.querySelector('.title').should.be.ok; + var props = sector.querySelector('.properties'); + props.should.be.ok; + sector.classList.contains('open').should.equal(true); + props.style.display.should.equal('block'); + }); + + it('No properties', function() { + var props = view.el.querySelector('.properties'); + props.innerHTML.should.equal('
'); + }); + + it('Update on open', function() { + var sector = view.el; + var props = sector.querySelector('.properties'); + model.set('open', false); + sector.classList.contains('open').should.equal(false); + props.style.display.should.equal('none'); + }); + + it('Toggle on click', function() { + var sector = view.el; + view.$el.find('.title').click(); + sector.classList.contains('open').should.equal(false); + }); + + describe('Init with options', function() { + beforeEach(function () { + model = new Sector({ + open: false, + name: 'TestName', + properties: [ + {type:'integer'}, + {type:'integer'}, + {type:'integer'}, + ] + }); + view = new SectorView({ + model: model + }); + $fixture.empty().appendTo($fixtures); + $fixture.html(view.render().el); + }); + + afterEach(function () { + view.remove(); + }); + + it('Rendered correctly', function() { + var sector = view.el; + var props = sector.querySelector('.properties'); + sector.querySelector('.title').innerHTML.should.contain('TestName'); + props.should.be.ok; + sector.classList.contains('open').should.equal(false); + props.style.display.should.equal('none'); + }); + + it('Has properties', function() { + var props = view.el.querySelector('.properties'); + props.children.length.should.equal(4); // Last one is 'clear' element + }); + + }); + + }); + } + }; + +}); \ No newline at end of file