Browse Source

Add model tests to Panels

pull/36/head
Artur Arseniev 10 years ago
parent
commit
bd305d738e
  1. 22
      src/panels/model/Button.js
  2. 19
      src/panels/model/Buttons.js
  3. 8
      test/specs/panels/main.js
  4. 84
      test/specs/panels/model/CssModels.js
  5. 123
      test/specs/panels/model/PanelModels.js

22
src/panels/model/Button.js

@ -1,26 +1,26 @@
define([ 'backbone','require'], define([ 'backbone','require'],
function (Backbone, require) { function (Backbone, require) {
/** /**
* @class Button * @class Button
* */ * */
return Backbone.Model.extend({ return Backbone.Model.extend({
defaults :{ defaults :{
id : '', id: '',
className : '', className: '',
command : '', command: '',
context : '', context: '',
buttons : [], buttons: [],
attributes : {}, attributes: {},
active : false, active: false,
}, },
initialize: function(options) { initialize: function(options) {
if(this.get('buttons').length){ if(this.get('buttons').length){
var Buttons = require('./Buttons'); var Buttons = require('./Buttons');
this.set('buttons', new Buttons(this.get('buttons')) ); this.set('buttons', new Buttons(this.get('buttons')) );
} }
}, },
}); });
}); });

19
src/panels/model/Buttons.js

@ -1,17 +1,17 @@
define([ 'backbone','./Button'], define([ 'backbone','./Button'],
function (Backbone, Button) { function (Backbone, Button) {
/** /**
* @class Buttons * @class Buttons
* */ * */
return Backbone.Collection.extend({ return Backbone.Collection.extend({
model: Button, model: Button,
/** /**
* Deactivate all buttons, except one passed * Deactivate all buttons, except one passed
* @param {Object} except Model to ignore * @param {Object} except Model to ignore
* @param {Boolean} r Recursive flag * @param {Boolean} r Recursive flag
* *
* @return void * @return void
* */ * */
deactivateAllExceptOne: function(except, r){ deactivateAllExceptOne: function(except, r){
@ -23,14 +23,15 @@ define([ 'backbone','./Button'],
} }
}); });
}, },
/** /**
* Deactivate all buttons * Deactivate all buttons
* @param {String} context Context string * @param {String} ctx Context string
* *
* @return void * @return void
* */ * */
deactivateAll: function(context){ deactivateAll: function(ctx){
var context = ctx || '';
this.forEach(function(model, index) { this.forEach(function(model, index) {
if( model.get('context') == context ){ if( model.get('context') == context ){
model.set('active', false); model.set('active', false);
@ -39,6 +40,6 @@ define([ 'backbone','./Button'],
} }
}); });
}, },
}); });
}); });

8
test/specs/panels/main.js

@ -1,10 +1,12 @@
var modulePath = './../../../test/specs/panels'; var modulePath = './../../../test/specs/panels';
define([ define([
'Panels' 'Panels',
modulePath + '/model/PanelModels'
], ],
function( function(
Panels Panels,
Models
) { ) {
describe('Panels', function() { describe('Panels', function() {
@ -96,5 +98,7 @@ define([
}); });
Models.run();
}); });
}); });

84
test/specs/panels/model/CssModels.js

@ -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);
});
});
}
};
});

123
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;
});
});
}
};
});
Loading…
Cancel
Save