diff --git a/src/css_composer/view/CssRulesView.js b/src/css_composer/view/CssRulesView.js index f08bb24bb..d7b7bbb65 100644 --- a/src/css_composer/view/CssRulesView.js +++ b/src/css_composer/view/CssRulesView.js @@ -6,8 +6,7 @@ define(['backbone','./CssRuleView'], return Backbone.View.extend({ initialize: function(o) { - this.config = o.config; - this.preview = o.preview; + this.config = o.config || {}; this.pfx = this.config.stylePrefix; this.listenTo( this.collection, 'add', this.addTo ); this.listenTo( this.collection, 'reset', this.render ); diff --git a/test/specs/css_composer/main.js b/test/specs/css_composer/main.js index 2f48724e0..13feafd0e 100644 --- a/test/specs/css_composer/main.js +++ b/test/specs/css_composer/main.js @@ -3,12 +3,14 @@ var modulePath = './../../../test/specs/css_composer'; define([ 'CssComposer', modulePath + '/model/CssModels', - modulePath + '/view/CssRuleView' + modulePath + '/view/CssRuleView', + modulePath + '/view/CssRulesView' ], function( CssComposer, Models, - CssRuleView + CssRuleView, + CssRulesView ) { describe('Css Composer', function() { @@ -132,6 +134,7 @@ define([ Models.run(); CssRuleView.run(); + CssRulesView.run(); }); }); \ No newline at end of file diff --git a/test/specs/css_composer/view/CssRulesView.js b/test/specs/css_composer/view/CssRulesView.js new file mode 100644 index 000000000..3bcd33d41 --- /dev/null +++ b/test/specs/css_composer/view/CssRulesView.js @@ -0,0 +1,54 @@ +var path = 'CssComposer/view/'; +define([path + 'CssRulesView', 'CssComposer/model/CssRules'], + function(CssRulesView, CssRules) { + + return { + run : function(){ + describe('CssRulesView', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $('
'); + }); + + beforeEach(function () { + var col = new CssRules([]); + this.view = new CssRulesView({ + collection: col + }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.collection.reset(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + CssRulesView.should.be.exist; + }); + + it("Collection is empty", function (){ + this.view.$el.html().should.be.empty; + }); + + it("Add new rule", function (){ + sinon.stub(this.view, "addToCollection"); + this.view.collection.add({}); + this.view.addToCollection.calledOnce.should.equal(true); + }); + + it("Render new rule", function (){ + this.view.collection.add({}); + this.view.$el.html().should.not.be.empty; + }); + + }); + } + }; + +}); \ No newline at end of file