diff --git a/src/css_composer/view/CssRuleView.js b/src/css_composer/view/CssRuleView.js index 330ad5c13..4a12d695b 100644 --- a/src/css_composer/view/CssRuleView.js +++ b/src/css_composer/view/CssRuleView.js @@ -10,7 +10,6 @@ define(['backbone'], initialize: function(o) { this.config = o.config || {}; this.listenTo(this.model, 'change:style', this.render); - }, /** @@ -41,10 +40,15 @@ define(['backbone'], }, render : function(){ + var block = '', + o = ''; if(!this.selStr) this.selStr = this.renderSelectors(); var prpStr = this.renderProperties(); - this.$el.html(this.selStr + '{' + prpStr + '}'); + if(this.selStr) + block = prpStr !== '' ? '{' + prpStr + '}' : ''; + o = this.selStr && block ? this.selStr + block : ''; + this.$el.html(o); return this; }, diff --git a/test/specs/css_composer/main.js b/test/specs/css_composer/main.js index f296bfd79..2f48724e0 100644 --- a/test/specs/css_composer/main.js +++ b/test/specs/css_composer/main.js @@ -2,12 +2,13 @@ var modulePath = './../../../test/specs/css_composer'; define([ 'CssComposer', - modulePath + '/model/CssModels' + modulePath + '/model/CssModels', + modulePath + '/view/CssRuleView' ], function( CssComposer, Models, - Selectors + CssRuleView ) { describe('Css Composer', function() { @@ -130,6 +131,7 @@ define([ }); Models.run(); + CssRuleView.run(); }); }); \ No newline at end of file diff --git a/test/specs/css_composer/view/CssRuleView.js b/test/specs/css_composer/view/CssRuleView.js new file mode 100644 index 000000000..5cf8245fb --- /dev/null +++ b/test/specs/css_composer/view/CssRuleView.js @@ -0,0 +1,101 @@ +var path = 'CssComposer/view/'; +define([path + 'CssRuleView', 'CssComposer/model/CssRule'], + function(CssRuleView, CssRule) { + + return { + run : function(){ + describe('CssRuleView', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $('
'); + }); + + beforeEach(function () { + var m = new CssRule(); + this.view = new CssRuleView({ + model: m + }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.model.destroy(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + CssRuleView.should.be.exist; + }); + + it('Correct behaviour of renderSelectors with single selector', function() { + this.view.model.get('selectors').add({name: 'test'}); + this.view.renderSelectors().should.equal('.test'); + }); + + it('Correct behaviour of renderSelectors with multiple selectors', function() { + this.view.model.get('selectors').add([{name: 'test2'}, {name: 'test1'}]); + this.view.renderSelectors().should.equal('.test2.test1'); + }); + + it('Correct behaviour of renderProperties with single property', function() { + this.view.model.set('style', {'prop': 'value'}); + this.view.renderProperties().should.equal('prop:value;'); + }); + + it('Correct behaviour of renderProperties with multiple properties', function() { + this.view.model.set('style', {'prop2': 'value2', 'prop3': 'value3'}); + this.view.renderProperties().should.equal('prop2:value2;prop3:value3;'); + }); + + it('Empty style inside', function() { + this.$fixture.html().should.equal(''); + }); + + it('On update of style always empty as there is no selectors', function() { + this.view.model.set('style', {'prop':'value'}); + this.$fixture.html().should.equal(''); + }); + + describe('CssRuleView with selectors', function() { + + beforeEach(function () { + var m = new CssRule({ + selectors: [{name:'test1'}, {name:'test2'}] + }); + this.regView = new CssRuleView({ + model: m + }); + this.regView.render(); + }); + + afterEach(function () { + this.regView.model.destroy(); + }); + + it('Empty with no style', function() { + this.regView.$el.html().should.equal(''); + }); + + it('Not empty on update of style', function() { + this.regView.model.set('style', {'prop':'value'}); + this.regView.$el.html().should.equal('.test1.test2{prop:value;}'); + }); + + it('Empty on clear', function() { + this.regView.model.set('style', {'prop':'value'}); + this.regView.model.set('style', {}); + this.regView.$el.html().should.equal(''); + }); + + }); + + }); + } + }; + +}); \ No newline at end of file diff --git a/test/specs/panel/model/panelModel.js b/test/specs/panel/model/panelModel.js deleted file mode 100644 index e5d1f2591..000000000 --- a/test/specs/panel/model/panelModel.js +++ /dev/null @@ -1,25 +0,0 @@ - -define(['panelModel','appDir/panel_commands/buttons/main'], - function(panelModel, commandsButtonsProvider) { - describe('Panel', function() { - - it('Contiene valori di default', function() { //Has default values - var model = new panelModel({}); - model.should.be.ok; - model.get('name').should.equal(""); - model.get('visible').should.equal(true); - model.get('buttons').should.equal.undefined; - }); - it('Imposta valori passati', function() { //Sets passed attributes - var model = new panelModel({ - name:'command', - visible: false, - buttons: commandsButtonsProvider.createButtons(), - }); - model.should.be.ok; - model.get('name').should.equal("command"); - model.get('visible').should.equal(false); - model.get('buttons').should.have.length(5); - }); - }); - }); \ No newline at end of file diff --git a/test/specs/panel/view/panelView.js b/test/specs/panel/view/panelView.js deleted file mode 100644 index 2c167d2f1..000000000 --- a/test/specs/panel/view/panelView.js +++ /dev/null @@ -1,49 +0,0 @@ - -define(['panelModel', 'panelView', 'Buttons', 'appDir/panel_commands/buttons/main'], - function(panelModel,panelView, Buttons, commandsButtonsProvider) { - describe('PanelView', function() { - before(function () { - this.testPanelName = 'commands'; - this.$fixture = $("
"); - }); - - beforeEach(function () { - this.view = new panelView({ - model: new panelModel({ - name : this.testPanelName, - buttons: commandsButtonsProvider.createButtons(), - }), - eventsQ : { - commands: {createComponent : {}} - }, - }); - this.$fixture.empty().appendTo($("#fixtures")); - this.$fixture.html(this.view.render().el); - }); - afterEach(function () { - //this.view.model.destroy(); - }); - - after(function () { - //this.$fixture.remove(); - }); - describe("Inizializzazione", function () { - it('Render pannello', function() { //Has default values - this.view.should.be.ok; - this.view.$el.attr('id').should.equal(this.testPanelName); - }); - it('Non deve essere vuoto', function() { - this.view.$el.find('.c a').should.have.length.above(0); - }); - it('Nessun elemento deve essere attivo', function() { - this.view.$el.find('.c a.active').should.have.length(0); - }); - }); - describe("Interazione", function(){ - it('Elemento attivo alla richiesta', function(){ - this.view.model.buttons.models[0].toggle(); - this.view.$el.find('.c a.active').should.have.length(1); - }); - }); - }); - }); \ No newline at end of file