mirror of https://github.com/artf/grapesjs.git
5 changed files with 150 additions and 106 deletions
@ -1,26 +1,26 @@ |
|||
define([ 'backbone','require'], |
|||
define([ 'backbone','require'], |
|||
function (Backbone, require) { |
|||
/** |
|||
* @class Button |
|||
* */ |
|||
return Backbone.Model.extend({ |
|||
|
|||
|
|||
defaults :{ |
|||
id : '', |
|||
className : '', |
|||
command : '', |
|||
context : '', |
|||
buttons : [], |
|||
attributes : {}, |
|||
active : false, |
|||
id: '', |
|||
className: '', |
|||
command: '', |
|||
context: '', |
|||
buttons: [], |
|||
attributes: {}, |
|||
active: false, |
|||
}, |
|||
|
|||
|
|||
initialize: function(options) { |
|||
if(this.get('buttons').length){ |
|||
var Buttons = require('./Buttons'); |
|||
this.set('buttons', new Buttons(this.get('buttons')) ); |
|||
} |
|||
}, |
|||
|
|||
|
|||
}); |
|||
}); |
|||
|
|||
@ -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); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
@ -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…
Reference in new issue