Browse Source

Add PanelsView tests

pull/36/head
Artur Arseniev 11 years ago
parent
commit
d557e69de0
  1. 20
      src/panels/view/PanelsView.js
  2. 7
      test/specs/panels/main.js
  3. 55
      test/specs/panels/view/PanelsView.js

20
src/panels/view/PanelsView.js

@ -7,12 +7,12 @@ define(['backbone','./PanelView'],
return Backbone.View.extend({ return Backbone.View.extend({
initialize: function(o) { initialize: function(o) {
this.opt = o; this.opt = o || {};
this.config = o.config; this.config = this.opt.config || {};
this.pfx = o.config.stylePrefix; this.pfx = this.config.stylePrefix || '';
this.listenTo( this.collection, 'add', this.addTo ); this.listenTo( this.collection, 'add', this.addTo );
this.listenTo( this.collection, 'reset', this.render ); this.listenTo( this.collection, 'reset', this.render );
this.className = this.pfx + 'panels'; this.className = this.pfx + 'panels';
}, },
/** /**
@ -36,14 +36,14 @@ define(['backbone','./PanelView'],
* @private * @private
* */ * */
addToCollection: function(model, fragmentEl){ addToCollection: function(model, fragmentEl){
var fragment = fragmentEl || null; var fragment = fragmentEl || null;
var viewObject = PanelView; var viewObject = PanelView;
var view = new viewObject({ var view = new viewObject({
model : model, model: model,
config : this.config, config: this.config,
}); });
var rendered = view.render().el; var rendered = view.render().el;
if(fragment){ if(fragment){
fragment.appendChild(rendered); fragment.appendChild(rendered);

7
test/specs/panels/main.js

@ -3,12 +3,14 @@ var modulePath = './../../../test/specs/panels';
define([ define([
'Panels', 'Panels',
modulePath + '/model/PanelModels', modulePath + '/model/PanelModels',
modulePath + '/view/PanelView' modulePath + '/view/PanelView',
modulePath + '/view/PanelsView'
], ],
function( function(
Panels, Panels,
Models, Models,
PanelView PanelView,
PanelsView
) { ) {
describe('Panels', function() { describe('Panels', function() {
@ -102,6 +104,7 @@ define([
Models.run(); Models.run();
PanelView.run(); PanelView.run();
PanelsView.run();
}); });
}); });

55
test/specs/panels/view/PanelsView.js

@ -0,0 +1,55 @@
var path = 'Panels/view/';
define([path + 'PanelsView', 'Panels/model/Panels'],
function(PanelsView, Panels) {
return {
run : function(){
describe('PanelsView', function() {
var $fixtures;
var $fixture;
var model;
var view;
before(function () {
$fixtures = $("#fixtures");
$fixture = $('<div class="cssrules-fixture"></div>');
});
beforeEach(function () {
model = new Panels([]);
view = new PanelsView({
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 panel", function (){
sinon.stub(view, "addToCollection");
view.collection.add({});
view.addToCollection.calledOnce.should.equal(true);
});
it("Render new panel", function (){
view.collection.add({});
view.$el.html().should.not.be.empty;
});
});
}
};
});
Loading…
Cancel
Save