diff --git a/src/panels/model/Button.js b/src/panels/model/Button.js index 0fb822acf..3c91a78af 100644 --- a/src/panels/model/Button.js +++ b/src/panels/model/Button.js @@ -1,26 +1,26 @@ -define([ 'backbone','require'], +define([ 'backbone','require'], function (Backbone, require) { /** * @class Button * */ return Backbone.Model.extend({ - + defaults :{ - id : '', - className : '', - command : '', - context : '', - buttons : [], - attributes : {}, - active : false, + id: '', + className: '', + command: '', + context: '', + buttons: [], + attributes: {}, + active: false, }, - + initialize: function(options) { if(this.get('buttons').length){ var Buttons = require('./Buttons'); this.set('buttons', new Buttons(this.get('buttons')) ); } }, - + }); }); diff --git a/src/panels/model/Buttons.js b/src/panels/model/Buttons.js index 015a4c9b3..e7ee14518 100644 --- a/src/panels/model/Buttons.js +++ b/src/panels/model/Buttons.js @@ -1,17 +1,17 @@ -define([ 'backbone','./Button'], +define([ 'backbone','./Button'], function (Backbone, Button) { /** * @class Buttons * */ return Backbone.Collection.extend({ - + model: Button, - + /** * Deactivate all buttons, except one passed * @param {Object} except Model to ignore * @param {Boolean} r Recursive flag - * + * * @return void * */ deactivateAllExceptOne: function(except, r){ @@ -23,14 +23,15 @@ define([ 'backbone','./Button'], } }); }, - + /** * Deactivate all buttons - * @param {String} context Context string - * + * @param {String} ctx Context string + * * @return void * */ - deactivateAll: function(context){ + deactivateAll: function(ctx){ + var context = ctx || ''; this.forEach(function(model, index) { if( model.get('context') == context ){ model.set('active', false); @@ -39,6 +40,6 @@ define([ 'backbone','./Button'], } }); }, - + }); }); diff --git a/test/specs/panels/main.js b/test/specs/panels/main.js index f85babb71..5fead008f 100644 --- a/test/specs/panels/main.js +++ b/test/specs/panels/main.js @@ -1,10 +1,12 @@ var modulePath = './../../../test/specs/panels'; define([ - 'Panels' + 'Panels', + modulePath + '/model/PanelModels' ], function( - Panels + Panels, + Models ) { describe('Panels', function() { @@ -96,5 +98,7 @@ define([ }); + Models.run(); + }); }); \ No newline at end of file diff --git a/test/specs/panels/model/CssModels.js b/test/specs/panels/model/CssModels.js deleted file mode 100644 index da0cd5c80..000000000 --- a/test/specs/panels/model/CssModels.js +++ /dev/null @@ -1,84 +0,0 @@ -var path = 'CssComposer/model/'; -define([path + 'CssRule', - path + 'CssRules', - path + 'Selectors', - 'ClassManager/model/ClassTag'], - function(CssRule, CssRules, Selectors, ClassTag) { - - return { - run : function(){ - describe('CssRule', function() { - - beforeEach(function () { - this.obj = new CssRule(); - }); - - afterEach(function () { - delete this.obj; - }); - - it('Has selectors property', function() { - this.obj.has('selectors').should.equal(true); - }); - - it('Has style property', function() { - this.obj.has('style').should.equal(true); - }); - - it('Has state property', function() { - this.obj.has('state').should.equal(true); - }); - - it('No default selectors', function() { - this.obj.get('selectors').length.should.equal(0); - }); - - it('Compare returns true with the same selectors', function() { - var s1 = this.obj.get('selectors').add({ name: 'test1' }); - var s2 = this.obj.get('selectors').add({ name: 'test2' }); - this.obj.compare([s1, s2]).should.equal(true); - }); - - it('Compare with different state', function() { - var s1 = this.obj.get('selectors').add({ name: 'test1' }); - var s2 = this.obj.get('selectors').add({ name: 'test2' }); - this.obj.set('state','hover'); - this.obj.compare([s1, s2]).should.equal(false); - this.obj.compare([s1, s2], 'hover').should.equal(true); - }); - - it('Compare with different maxWidth', function() { - var s1 = this.obj.get('selectors').add({ name: 'test1' }); - var s2 = this.obj.get('selectors').add({ name: 'test2' }); - this.obj.set('state','hover'); - this.obj.set('maxWidth','1000'); - this.obj.compare([s1, s2]).should.equal(false); - this.obj.compare([s1, s2], 'hover').should.equal(false); - this.obj.compare([s2, s1], 'hover', '1000').should.equal(true); - }); - - }); - - describe('CssRules', function() { - - it('Creates collection item correctly', function() { - var c = new CssRules(); - var m = c.add({}); - m.should.be.an.instanceOf(CssRule); - }); - - }); - - describe('Selectors', function() { - - it('Creates collection item correctly', function() { - var c = new Selectors(); - var m = c.add({}); - m.should.be.an.instanceOf(ClassTag); - }); - - }); - } - }; - -}); \ No newline at end of file diff --git a/test/specs/panels/model/PanelModels.js b/test/specs/panels/model/PanelModels.js new file mode 100644 index 000000000..b40f1b3d5 --- /dev/null +++ b/test/specs/panels/model/PanelModels.js @@ -0,0 +1,123 @@ +var path = 'Panels/model/'; +define([path + 'Button', + path + 'Buttons', + path + 'Panel', + path + 'Panels'], + function(Button, Buttons, Panel, Panels) { + + return { + run : function(){ + describe('Button', function() { + + var obj; + + beforeEach(function () { + obj = new Button(); + }); + + afterEach(function () { + delete obj; + }); + + it('Has buttons instance', function() { + obj.has('buttons').should.equal(true); + }); + + it('Has no buttons', function() { + obj.get('buttons').length.should.equal(0); + }); + + it('Init with other buttons inside correctly', function() { + obj = new Button({ + buttons: [{}] + }); + obj.get('buttons').should.be.instanceOf(Buttons); + obj.get('buttons').length.should.equal(1); + }); + + }); + + describe('Buttons', function() { + var obj; + + beforeEach(function () { + obj = new Buttons(); + }); + + afterEach(function () { + delete obj; + }); + + it('Deactivates buttons', function() { + obj.add({ active: true }); + obj.deactivateAll(); + obj.at(0).get('active').should.equal(false); + }); + + it('Deactivates buttons with context', function() { + obj.add({ active: true }); + obj.deactivateAll('someContext'); + obj.at(0).get('active').should.equal(true); + }); + + it('Deactivates except one', function() { + var btn = obj.add({ active: true }); + obj.deactivateAllExceptOne(); + obj.at(0).get('active').should.equal(false); + }); + + it('Deactivates except one with model', function() { + var btn = obj.add({ active: true }); + obj.deactivateAllExceptOne(btn); + obj.at(0).get('active').should.equal(true); + }); + + }); + + describe('Panel', function() { + var obj; + + beforeEach(function () { + obj = new Panel(); + }); + + afterEach(function () { + delete obj; + }); + + it('Has buttons instance', function() { + obj.has('buttons').should.equal(true); + obj.get('buttons').should.be.instanceOf(Buttons); + }); + + it('Has no buttons', function() { + obj.get('buttons').length.should.equal(0); + }); + + it('Init with buttons inside correctly', function() { + obj = new Panel({ + buttons: [{}] + }); + obj.get('buttons').should.be.instanceOf(Buttons); + obj.get('buttons').length.should.equal(1); + }); + + }); + + describe('Panels', function() { + var obj; + + beforeEach(function () { + obj = new Panel(); + }); + + afterEach(function () { + delete obj; + }); + + }); + + } + }; + +}); \ No newline at end of file