Browse Source

Update StyleManager tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
b1776ab6c7
  1. 8
      src/style_manager/main.js
  2. 12
      src/style_manager/model/Sector.js
  3. 16
      src/style_manager/model/Sectors.js
  4. 108
      test/specs/style_manager/main.js

8
src/style_manager/main.js

@ -173,8 +173,10 @@ define(function(require) {
var prop = null; var prop = null;
var sector = this.getSector(sectorId); var sector = this.getSector(sectorId);
if(sector) if(sector){
prop = sectors.get('properties').where({property: name}); prop = sector.get('properties').where({property: name});
prop = prop.length == 1 ? prop[0] : prop;
}
return prop; return prop;
}, },
@ -191,7 +193,7 @@ define(function(require) {
var sector = this.getSector(sectorId); var sector = this.getSector(sectorId);
if(sector) if(sector)
props = sectors.get('properties'); props = sector.get('properties');
return props; return props;
}, },

12
src/style_manager/model/Sector.js

@ -1,5 +1,5 @@
define(['backbone'], define(['backbone', './Properties'],
function(Backbone) { function(Backbone, Properties) {
return Backbone.Model.extend({ return Backbone.Model.extend({
@ -8,7 +8,13 @@ define(['backbone'],
name: '', name: '',
open: true, open: true,
properties : [], properties : [],
} },
initialize: function(opts) {
var o = opts || {};
var props = o.properties || this.get('properties');
this.set('properties', new Properties(props));
},
}); });
}); });

16
src/style_manager/model/Sectors.js

@ -1,21 +1,9 @@
define([ 'backbone','./Sector','./Properties'], define([ 'backbone', './Sector'],
function (Backbone,Sector, Properties) { function (Backbone, Sector) {
return Backbone.Collection.extend({ return Backbone.Collection.extend({
model: Sector, model: Sector,
initialize: function(collection) {
_.each(collection, function(obj){
if(obj.properties instanceof Array){
obj.properties = new Properties(obj.properties);
}
},this);
},
}); });
}); });

108
test/specs/style_manager/main.js

@ -62,6 +62,114 @@ define([
sect1.should.deep.equal(sect2); sect1.should.deep.equal(sect2);
}); });
it('Add property to inexistent sector', function() {
(obj.addProperty('test', {}) == null).should.equal(true);
});
it('Add property', function() {
obj.addSector('test', {});
(obj.addProperty('test', {}) == null).should.equal(false);
obj.getProperties('test').length.should.equal(1);
});
it('Check added property', function() {
obj.addSector('test', {});
var prop = obj.addProperty('test', {
'name': 'test',
});
prop.get('name').should.equal('test');
});
it('Add properties', function() {
obj.addSector('test', {});
obj.addProperty('test', [{}, {}]);
obj.getProperties('test').length.should.equal(2);
});
it('Get property from inexistent sector', function() {
(obj.getProperty('test', 'test-prop') == null).should.equal(true);
});
it("Can't get properties without proper name", function() {
obj.addSector('test', {});
obj.addProperty('test', [{}, {}]);
obj.getProperty('test', 'test-prop').should.be.empty;
});
it("Get property with proper name", function() {
obj.addSector('test', {});
var prop1 = obj.addProperty('test', {property: 'test-prop'});
var prop2 = obj.getProperty('test', 'test-prop');
prop1.should.deep.equal(prop2);
});
it("Get properties with proper name", function() {
obj.addSector('test', {});
var prop1 = obj.addProperty('test',[
{property: 'test-prop'},
{property: 'test-prop'}
]);
obj.getProperty('test', 'test-prop').length.should.equal(2);
});
it('Get inexistent properties', function() {
(obj.getProperties('test') == null).should.equal(true);
(obj.getProperties() == null).should.equal(true);
});
it('Renders correctly', function() {
obj.render().should.be.ok;
});
describe('Init with configuration', function() {
beforeEach(function () {
obj = new StyleManager({
sectors: [{
id: 'dim',
name: 'Dimension',
properties: [{
name: 'Width',
property: 'width',
},{
name: 'Height',
property: 'height',
}],
},{
id: 'pos',
name: 'position',
properties: [{
name: 'Width',
property: 'width',
}],
}],
});
});
afterEach(function () {
delete obj;
});
it('Sectors added', function() {
obj.getSectors().length.should.equal(2);
var sect1 = obj.getSector('dim');
sect1.get('name').should.equal('Dimension');
});
it('Properties added', function() {
var sect1 = obj.getSector('dim');
var sect2 = obj.getSector('pos');
sect1.get('properties').length.should.equal(2);
sect2.get('properties').length.should.equal(1);
});
it('Property is correct', function() {
var prop1 = obj.getProperty('dim', 'width');
prop1.get('name').should.equal('Width');
});
});
}); });
}); });

Loading…
Cancel
Save