Browse Source

Fix attribute alteration inside traits

pull/36/head
Artur Arseniev 9 years ago
parent
commit
3a5cf5ca90
  1. 11
      src/demo.js
  2. 4
      src/trait_manager/view/TraitView.js
  3. 3
      test/runner/main.js
  4. 28
      test/specs/trait_manager/main.js
  5. 32
      test/specs/trait_manager/model/TraitsModel.js
  6. 76
      test/specs/trait_manager/view/TraitsView.js

11
src/demo.js

@ -9,14 +9,19 @@ require(['config/require-config'], function() {
noticeOnUnload: 0,
container : '#gjs',
height: '100%',
fromElement: true,
/*
//fromElement: true,
components: [{
style:{
width:'100px',
height:'100px'
},
traits: ['title']
},{
style:{
width:'150px',
height:'100px'
},
traits: [{name:'title', value: "myTitleTest"}]
},{
type: 'image'
},{
@ -24,7 +29,7 @@ require(['config/require-config'], function() {
type: 'link',
content: 'mylink',
}],
*/
storageManager:{ autoload: 0},
commands: {
defaults : [{

4
src/trait_manager/view/TraitView.js

@ -34,11 +34,9 @@ define(['backbone'], function (Backbone) {
onValueChange: function() {
var m = this.model;
var trg = this.target;
var attrs = trg.get('attributes');
var attrs = _.clone(trg.get('attributes'));
attrs[m.get('name')] = m.get('value');
trg.set('attributes', {});
trg.set('attributes', attrs);
console.log(trg);
},
/**

3
test/runner/main.js

@ -16,6 +16,7 @@ require(['../src/config/require-config.js', 'config/config.js'], function() {
'specs/storage_manager/main.js',
'specs/plugin_manager/main.js',
'specs/block_manager/main.js',
'specs/trait_manager/main.js',
'specs/parser/main.js',
'specs/grapesjs/main.js',
'specs/utils/main.js'
@ -26,4 +27,4 @@ require(['../src/config/require-config.js', 'config/config.js'], function() {
mocha.run();
});
});
});

28
test/specs/trait_manager/main.js

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

32
test/specs/trait_manager/model/TraitsModel.js

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

76
test/specs/trait_manager/view/TraitsView.js

@ -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…
Cancel
Save