Browse Source

Fix tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
0349fe3700
  1. 24
      src/dom_components/model/Component.js
  2. 3
      src/trait_manager/model/TraitFactory.js
  3. 3
      src/trait_manager/model/Traits.js
  4. 44
      test/specs/dom_components/model/Component.js

24
src/dom_components/model/Component.js

@ -47,7 +47,7 @@ define(['backbone','./Components', 'SelectorManager/model/Selectors', 'TraitMana
* @return {Array}
* @private
*/
normalizeClasses: function(arr){
normalizeClasses: function(arr) {
var res = [];
if(!this.sm.get)
@ -75,21 +75,27 @@ define(['backbone','./Components', 'SelectorManager/model/Selectors', 'TraitMana
* Override original clone method
* @private
*/
clone: function()
{
clone: function() {
var attr = _.clone(this.attributes),
comp = this.get('components'),
traits = this.get('traits'),
cls = this.get('classes');
attr.components = [];
attr.classes = [];
attr.classes = [];
attr.traits = [];
if(comp.length){
comp.each(function(md,i){
attr.components[i] = md.clone();
comp.each(function(md,i) {
attr.components[i] = md.clone();
});
}
if(traits.length){
traits.each(function(md, i) {
attr.traits[i] = md.clone();
});
}
if(cls.length){
cls.each(function(md,i){
attr.classes[i] = md.get('name');
cls.each(function(md,i) {
attr.classes[i] = md.get('name');
});
}
attr.status = '';
@ -102,7 +108,7 @@ define(['backbone','./Components', 'SelectorManager/model/Selectors', 'TraitMana
* @return {String}
* @private
* */
getName: function(){
getName: function() {
if(!this.name){
var id = this.cid.replace(/\D/g,''),
type = this.get('type');

3
src/trait_manager/model/TraitFactory.js

@ -15,11 +15,10 @@ define(['backbone'],
if(typeof props === 'string')
props = [props];
for (var i = 0, len = props.length; i < len; i++) {
for (var i = 0; i < props.length; i++) {
var obj = {};
var prop = props[i];
obj.name = prop;
objs.push(obj);
}

3
src/trait_manager/model/Traits.js

@ -15,7 +15,8 @@ define(['backbone','./Trait', './TraitFactory'],
if(typeof models === 'string')
models = [models];
for(var i = 0, len = models.length; i < len; i++){
var model = TraitFactory.build(models[i])[0];
var str = models[i];
var model = typeof str === 'string' ? TraitFactory.build(str)[0] : str;
model.target = this.target;
models[i] = model;
}

44
test/specs/dom_components/model/Component.js

@ -6,38 +6,42 @@ define(['DomComponents/model/Component',
return {
run : function(){
var obj;
describe('Component', function() {
beforeEach(function () {
this.obj = new Component();
obj = new Component();
});
afterEach(function () {
delete this.obj;
delete obj;
});
it('Has no children', function() {
this.obj.get('components').length.should.equal(0);
obj.get('components').length.should.equal(0);
});
it('Clones correctly', function() {
var sAttr = this.obj.attributes;
var cloned = this.obj.clone();
var sAttr = obj.attributes;
var cloned = obj.clone();
var eAttr = cloned.attributes;
sAttr.components = {};
eAttr.components = {};
sAttr.components = {};
eAttr.traits = {};
sAttr.traits = {};
sAttr.should.deep.equal(eAttr);
});
it('Has expected name', function() {
this.obj.cid = 'c999';
this.obj.getName().should.equal('Box 999');
obj.cid = 'c999';
obj.getName().should.equal('Box 999');
});
it('Has expected name 2', function() {
this.obj.cid = 'c999';
this.obj.set('type','testType');
this.obj.getName().should.equal('TestType 999');
obj.cid = 'c999';
obj.set('type','testType');
obj.getName().should.equal('TestType 999');
});
});
@ -45,19 +49,19 @@ define(['DomComponents/model/Component',
describe('Image Component', function() {
beforeEach(function () {
this.obj = new ComponentImage();
obj = new ComponentImage();
});
afterEach(function () {
delete this.obj;
delete obj;
});
it('Has src property', function() {
this.obj.has('src').should.equal(true);
obj.has('src').should.equal(true);
});
it('Not droppable', function() {
this.obj.get('droppable').should.equal(false);
obj.get('droppable').should.equal(false);
});
});
@ -65,19 +69,19 @@ define(['DomComponents/model/Component',
describe('Text Component', function() {
beforeEach(function () {
this.obj = new ComponentText();
obj = new ComponentText();
});
afterEach(function () {
delete this.obj;
delete obj;
});
it('Has content property', function() {
this.obj.has('content').should.equal(true);
obj.has('content').should.equal(true);
});
it('Not droppable', function() {
this.obj.get('droppable').should.equal(false);
obj.get('droppable').should.equal(false);
});
});
@ -106,4 +110,4 @@ define(['DomComponents/model/Component',
}
};
});
});

Loading…
Cancel
Save