Browse Source

Add ButtonsView tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
e90687c0bd
  1. 42
      src/panels/view/ButtonsView.js
  2. 8
      test/specs/panels/main.js
  3. 55
      test/specs/panels/view/ButtonsView.js

42
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;

8
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();
});
});

55
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 = $('<div class="cssrules-fixture"></div>');
});
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;
});
});
}
};
});
Loading…
Cancel
Save