mirror of https://github.com/artf/grapesjs.git
6 changed files with 147 additions and 7 deletions
@ -0,0 +1,28 @@ |
|||
var modulePath = './../../../test/specs/trait_manager'; |
|||
|
|||
define([ 'TraitManager', |
|||
modulePath + '/model/TraitsModel', |
|||
modulePath + '/view/TraitsView', |
|||
], |
|||
function(TraitManager, TraitsModel, TraitsView) { |
|||
|
|||
describe('TraitManager', function() { |
|||
|
|||
describe('Main', function() { |
|||
|
|||
var obj; |
|||
|
|||
beforeEach(function () { |
|||
obj = new TraitManager().init(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
}); |
|||
|
|||
TraitsModel.run(); |
|||
TraitsView.run(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,32 @@ |
|||
define(['TraitManager/model/Trait', 'DomComponents/model/Component'], |
|||
function(Trait, Component) { |
|||
|
|||
return { |
|||
run: function(){ |
|||
|
|||
describe('TraitModels', function() { |
|||
|
|||
var obj; |
|||
var target; |
|||
var modelName = 'title'; |
|||
|
|||
beforeEach(function () { |
|||
target = new Component(); |
|||
obj = new Trait({ |
|||
name: modelName, |
|||
target: target, |
|||
}); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
Trait.should.be.exist; |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
@ -0,0 +1,76 @@ |
|||
var modulePath = 'TraitManager'; |
|||
define([modulePath+'/view/TraitView', |
|||
modulePath+'/model/Trait', |
|||
'DomComponents/model/Component'], |
|||
function(TraitView, Trait, Component) { |
|||
|
|||
return { |
|||
run: function(){ |
|||
|
|||
describe('TraitView', function() { |
|||
|
|||
var obj; |
|||
var model; |
|||
var modelName = 'title'; |
|||
var target; |
|||
|
|||
beforeEach(function () { |
|||
target = new Component(); |
|||
model = new Trait({ |
|||
name: modelName, |
|||
target: target, |
|||
}); |
|||
obj = new TraitView({ |
|||
model: model, |
|||
}); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
delete model; |
|||
delete target; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
Trait.should.be.exist; |
|||
}); |
|||
|
|||
it('Target has no attributes on init', function() { |
|||
target.get('attributes').should.deep.equal({}); |
|||
}); |
|||
|
|||
it('On update of the value updates the target attributes', function() { |
|||
model.set('value', 'test'); |
|||
var eq = {}; |
|||
eq[modelName] = 'test'; |
|||
target.get('attributes').should.deep.equal(eq); |
|||
}); |
|||
|
|||
it('Updates on different models do not alter other targets', function() { |
|||
var target1 = new Component(); |
|||
var target2 = new Component(); |
|||
var model1 = new Trait({ |
|||
name: modelName, |
|||
target: target1, |
|||
}); |
|||
var model2 = new Trait({ |
|||
name: modelName, |
|||
target: target2, |
|||
}); |
|||
var obj1 = new TraitView({model: model1}); |
|||
var obj2 = new TraitView({model: model2}); |
|||
|
|||
model1.set('value', 'test1'); |
|||
model2.set('value', 'test2'); |
|||
var eq1 = {}; |
|||
eq1[modelName] = 'test1'; |
|||
var eq2 = {}; |
|||
eq2[modelName] = 'test2'; |
|||
target1.get('attributes').should.deep.equal(eq1); |
|||
target2.get('attributes').should.deep.equal(eq2); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
Loading…
Reference in new issue