diff --git a/src/panels/view/ButtonsView.js b/src/panels/view/ButtonsView.js index fec23f7c3..7c4bfa8bb 100644 --- a/src/panels/view/ButtonsView.js +++ b/src/panels/view/ButtonsView.js @@ -1,65 +1,65 @@ -define(['backbone','./ButtonView'], +define(['backbone','./ButtonView'], function (Backbone, ButtonView) { - /** + /** * @class ButtonsView * */ return Backbone.View.extend({ - + initialize: function(o) { - this.opt = o; - this.config = o.config; - this.pfx = o.config.stylePrefix; - this.parentM = o.parentM || null; - this.listenTo( this.collection, 'add', this.addTo ); - this.listenTo( this.collection, 'reset', this.render ); - this.className = this.pfx + 'buttons'; + this.opt = o || {}; + this.config = this.opt.config || {}; + this.pfx = this.config.stylePrefix || ''; + this.parentM = this.opt.parentM || null; + this.listenTo(this.collection, 'add', this.addTo ); + this.listenTo(this.collection, 'reset', this.render ); + this.className = this.pfx + 'buttons'; }, - + /** * Add to collection * @param Object Model - * + * * @return Object * */ addTo: function(model){ this.addToCollection(model); }, - + /** * Add new object to collection * @param Object Model * @param Object Fragment collection - * + * * @return Object Object created * */ addToCollection: function(model, fragmentEl){ var fragment = fragmentEl || null; var viewObject = ButtonView; - + var view = new viewObject({ - model : model, + model : model, config : this.config, parentM : this.parentM }); var rendered = view.render().el; - + if(fragment){ fragment.appendChild(rendered); }else{ this.$el.append(rendered); } - + return rendered; }, - + render: function() { var fragment = document.createDocumentFragment(); this.$el.empty(); - + this.collection.each(function(model){ this.addToCollection(model, fragment); }, this); - + this.$el.append(fragment); this.$el.attr('class', _.result(this, 'className')); return this; diff --git a/test/specs/panels/main.js b/test/specs/panels/main.js index da4a8a557..3c287966e 100644 --- a/test/specs/panels/main.js +++ b/test/specs/panels/main.js @@ -5,14 +5,16 @@ define([ modulePath + '/model/PanelModels', modulePath + '/view/PanelView', modulePath + '/view/PanelsView', - modulePath + '/view/ButtonView' + modulePath + '/view/ButtonView', + modulePath + '/view/ButtonsView' ], function( Panels, Models, PanelView, PanelsView, - ButtonView + ButtonView, + ButtonsView ) { describe('Panels', function() { @@ -108,6 +110,6 @@ define([ PanelView.run(); PanelsView.run(); ButtonView.run(); - + ButtonsView.run(); }); }); \ No newline at end of file diff --git a/test/specs/panels/view/ButtonsView.js b/test/specs/panels/view/ButtonsView.js new file mode 100644 index 000000000..222e9d5c6 --- /dev/null +++ b/test/specs/panels/view/ButtonsView.js @@ -0,0 +1,55 @@ +var path = 'Panels/view/'; +define([path + 'ButtonsView', 'Panels/model/Buttons'], + function(ButtonsView, Buttons) { + + return { + run : function(){ + describe('ButtonsView', function() { + + var $fixtures; + var $fixture; + var model; + var view; + + before(function () { + $fixtures = $("#fixtures"); + $fixture = $('
'); + }); + + beforeEach(function () { + model = new Buttons([]); + view = new ButtonsView({ + collection: model + }); + $fixture.empty().appendTo($fixtures); + $fixture.html(view.render().el); + }); + + afterEach(function () { + view.collection.reset(); + }); + + after(function () { + $fixture.remove(); + }); + + it("Collection is empty", function (){ + view.$el.html().should.be.empty; + }); + + it("Add new button", function (){ + sinon.stub(view, "addToCollection"); + view.collection.add({}); + view.addToCollection.calledOnce.should.equal(true); + }); + + it("Render new button", function (){ + view.collection.add({}); + view.$el.html().should.not.be.empty; + }); + + }); + } + }; + +}); \ No newline at end of file