mirror of https://github.com/artf/grapesjs.git
6 changed files with 98 additions and 266 deletions
@ -1,82 +0,0 @@ |
|||||
|
|
||||
define(function(require) { |
|
||||
|
|
||||
return { |
|
||||
run : function(){ |
|
||||
describe('E2E tests', function() { |
|
||||
|
|
||||
before(function () { |
|
||||
this.$fixtures = $("#fixtures"); |
|
||||
this.$fixture = $('<div id="csscomposer-fixture"></div>'); |
|
||||
}); |
|
||||
|
|
||||
beforeEach(function () { |
|
||||
this.Grapes = require('editor/main'); |
|
||||
this.gjs = new this.Grapes({ |
|
||||
stylePrefix: '', |
|
||||
storageType: 'none', |
|
||||
storageManager: { storageType: 'none', }, |
|
||||
assetManager: { storageType: 'none', }, |
|
||||
container: 'csscomposer-fixture', |
|
||||
}); |
|
||||
this.cssc = this.gjs.editor.get('CssComposer'); |
|
||||
this.clsm = this.gjs.editor.get('ClassManager'); |
|
||||
this.$fixture.empty().appendTo(this.$fixtures); |
|
||||
this.gjs.render(); |
|
||||
this.rulesSet = [ |
|
||||
{ selectors: [{name: 'test1'}, {name: 'test2'}] }, |
|
||||
{ selectors: [{name: 'test2'}, {name: 'test3'}] }, |
|
||||
{ selectors: [{name: 'test3'}] } |
|
||||
]; |
|
||||
}); |
|
||||
|
|
||||
afterEach(function () { |
|
||||
delete this.Grapes; |
|
||||
delete this.gjs; |
|
||||
delete this.cssc; |
|
||||
delete this.clsm; |
|
||||
}); |
|
||||
|
|
||||
after(function () { |
|
||||
this.$fixture.remove(); |
|
||||
}); |
|
||||
|
|
||||
it('Rules are correctly imported from default property', function() { |
|
||||
var gj = new this.Grapes({ |
|
||||
stylePrefix: '', |
|
||||
storageType: 'none', |
|
||||
storageManager: { storageType: 'none', }, |
|
||||
assetManager: { storageType: 'none', }, |
|
||||
cssComposer: { defaults: this.rulesSet}, |
|
||||
container: 'csscomposer-fixture', |
|
||||
}); |
|
||||
var cssc = gj.editor.get('CssComposer'); |
|
||||
cssc.getRules().length.should.equal(this.rulesSet.length); |
|
||||
var cls = gj.editor.get('ClassManager').getClasses(); |
|
||||
cls.length.should.equal(3); |
|
||||
}); |
|
||||
|
|
||||
|
|
||||
it('New rule adds correctly the class inside classe manager', function() { |
|
||||
var rules = this.cssc.getRules(); |
|
||||
rules.add({ selectors: [{name: 'test1'}] }); |
|
||||
this.clsm.getClasses().at(0).get('name').should.equal('test1'); |
|
||||
}); |
|
||||
|
|
||||
it('New rules are correctly imported inside classe manager', function() { |
|
||||
var rules = this.cssc.getRules(); |
|
||||
this.rulesSet.forEach(function(item){ |
|
||||
rules.add(item); |
|
||||
}); |
|
||||
var cls = this.clsm.getClasses(); |
|
||||
cls.length.should.equal(3); |
|
||||
cls.at(0).get('name').should.equal('test1'); |
|
||||
cls.at(1).get('name').should.equal('test2'); |
|
||||
cls.at(2).get('name').should.equal('test3'); |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
}); |
|
||||
@ -1,114 +0,0 @@ |
|||||
var path = 'CssComposer/view/'; |
|
||||
define([path + 'CssRuleView', 'CssComposer/model/CssRule'], |
|
||||
function(CssRuleView, CssRule) { |
|
||||
|
|
||||
return { |
|
||||
run : function(){ |
|
||||
describe('CssRuleView', function() { |
|
||||
|
|
||||
before(function () { |
|
||||
this.$fixtures = $("#fixtures"); |
|
||||
this.$fixture = $('<div class="cssrule-fixture"></div>'); |
|
||||
}); |
|
||||
|
|
||||
beforeEach(function () { |
|
||||
var m = new CssRule(); |
|
||||
this.view = new CssRuleView({ |
|
||||
model: m |
|
||||
}); |
|
||||
this.$fixture.empty().appendTo(this.$fixtures); |
|
||||
this.$fixture.html(this.view.render().el); |
|
||||
}); |
|
||||
|
|
||||
afterEach(function () { |
|
||||
this.view.model.destroy(); |
|
||||
}); |
|
||||
|
|
||||
after(function () { |
|
||||
this.$fixture.remove(); |
|
||||
}); |
|
||||
|
|
||||
it('Object exists', function() { |
|
||||
CssRuleView.should.be.exist; |
|
||||
}); |
|
||||
|
|
||||
it('Correct behaviour of renderSelectors with single selector', function() { |
|
||||
this.view.model.get('selectors').add({name: 'test'}); |
|
||||
this.view.renderSelectors().should.equal('.test'); |
|
||||
}); |
|
||||
|
|
||||
it('Correct behaviour of renderSelectors with multiple selectors', function() { |
|
||||
this.view.model.get('selectors').add([{name: 'test2'}, {name: 'test1'}]); |
|
||||
this.view.renderSelectors().should.equal('.test2.test1'); |
|
||||
}); |
|
||||
|
|
||||
it('Correct behaviour of renderProperties with single property', function() { |
|
||||
this.view.model.set('style', {'prop': 'value'}); |
|
||||
this.view.renderProperties().should.equal('prop:value;'); |
|
||||
}); |
|
||||
|
|
||||
it('Correct behaviour of renderProperties with multiple properties', function() { |
|
||||
this.view.model.set('style', {'prop2': 'value2', 'prop3': 'value3'}); |
|
||||
this.view.renderProperties().should.equal('prop2:value2;prop3:value3;'); |
|
||||
}); |
|
||||
|
|
||||
it('Empty style inside', function() { |
|
||||
this.$fixture.html().should.equal('<style></style>'); |
|
||||
}); |
|
||||
|
|
||||
it('On update of style always empty as there is no selectors', function() { |
|
||||
this.view.model.set('style', {'prop':'value'}); |
|
||||
this.$fixture.html().should.equal('<style></style>'); |
|
||||
}); |
|
||||
|
|
||||
describe('CssRuleView with selectors', function() { |
|
||||
|
|
||||
beforeEach(function () { |
|
||||
var m = new CssRule({ |
|
||||
selectors: [{name:'test1'}, {name:'test2'}] |
|
||||
}); |
|
||||
this.regView = new CssRuleView({ |
|
||||
model: m |
|
||||
}); |
|
||||
this.regView.render(); |
|
||||
}); |
|
||||
|
|
||||
afterEach(function () { |
|
||||
this.regView.model.destroy(); |
|
||||
}); |
|
||||
|
|
||||
it('Empty with no style', function() { |
|
||||
this.regView.$el.html().should.equal(''); |
|
||||
}); |
|
||||
|
|
||||
it('Not empty on update of style', function() { |
|
||||
this.regView.model.set('style', {'prop':'value'}); |
|
||||
this.regView.$el.html().should.equal('.test1.test2{prop:value;}'); |
|
||||
}); |
|
||||
|
|
||||
it('State correctly rendered', function() { |
|
||||
this.regView.model.set('style', {'prop':'value'}); |
|
||||
this.regView.model.set('state', 'hover'); |
|
||||
this.regView.$el.html().should.equal('.test1.test2:hover{prop:value;}'); |
|
||||
}); |
|
||||
|
|
||||
it('State render changes on update', function() { |
|
||||
this.regView.model.set('style', {'prop':'value'}); |
|
||||
this.regView.model.set('state', 'hover'); |
|
||||
this.regView.model.set('state', ''); |
|
||||
this.regView.$el.html().should.equal('.test1.test2{prop:value;}'); |
|
||||
}); |
|
||||
|
|
||||
it('Empty on clear', function() { |
|
||||
this.regView.model.set('style', {'prop':'value'}); |
|
||||
this.regView.model.set('style', {}); |
|
||||
this.regView.$el.html().should.equal(''); |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
}); |
|
||||
@ -1,54 +0,0 @@ |
|||||
var path = 'CssComposer/view/'; |
|
||||
define([path + 'CssRulesView', 'CssComposer/model/CssRules'], |
|
||||
function(CssRulesView, CssRules) { |
|
||||
|
|
||||
return { |
|
||||
run : function(){ |
|
||||
describe('CssRulesView', function() { |
|
||||
|
|
||||
before(function () { |
|
||||
this.$fixtures = $("#fixtures"); |
|
||||
this.$fixture = $('<div class="cssrules-fixture"></div>'); |
|
||||
}); |
|
||||
|
|
||||
beforeEach(function () { |
|
||||
var col = new CssRules([]); |
|
||||
this.view = new CssRulesView({ |
|
||||
collection: col |
|
||||
}); |
|
||||
this.$fixture.empty().appendTo(this.$fixtures); |
|
||||
this.$fixture.html(this.view.render().el); |
|
||||
}); |
|
||||
|
|
||||
afterEach(function () { |
|
||||
this.view.collection.reset(); |
|
||||
}); |
|
||||
|
|
||||
after(function () { |
|
||||
this.$fixture.remove(); |
|
||||
}); |
|
||||
|
|
||||
it('Object exists', function() { |
|
||||
CssRulesView.should.be.exist; |
|
||||
}); |
|
||||
|
|
||||
it("Collection is empty", function (){ |
|
||||
this.view.$el.html().should.be.empty; |
|
||||
}); |
|
||||
|
|
||||
it("Add new rule", function (){ |
|
||||
sinon.stub(this.view, "addToCollection"); |
|
||||
this.view.collection.add({}); |
|
||||
this.view.addToCollection.calledOnce.should.equal(true); |
|
||||
}); |
|
||||
|
|
||||
it("Render new rule", function (){ |
|
||||
this.view.collection.add({}); |
|
||||
this.view.$el.html().should.not.be.empty; |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
}); |
|
||||
@ -0,0 +1,76 @@ |
|||||
|
var path = 'Panels/view/'; |
||||
|
define([path + 'PanelView', 'Panels/model/Panel'], |
||||
|
function(PanelView, Panel) { |
||||
|
|
||||
|
return { |
||||
|
run : function(){ |
||||
|
|
||||
|
describe('PanelView', function() { |
||||
|
|
||||
|
var $fixtures; |
||||
|
var $fixture; |
||||
|
var model; |
||||
|
var view; |
||||
|
|
||||
|
before(function () { |
||||
|
$fixtures = $("#fixtures"); |
||||
|
$fixture = $('<div class="cssrule-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
model = new Panel(); |
||||
|
view = new PanelView({ |
||||
|
model: model |
||||
|
}); |
||||
|
$fixture.empty().appendTo($fixtures); |
||||
|
$fixture.html(view.render().el); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
view.remove(); |
||||
|
}); |
||||
|
|
||||
|
after(function () { |
||||
|
$fixture.remove(); |
||||
|
}); |
||||
|
|
||||
|
it('Panel empty', function() { |
||||
|
$fixture.html().should.be.equal('<div class="panel"></div>'); |
||||
|
}); |
||||
|
|
||||
|
it('Append content', function() { |
||||
|
model.set('appendContent','test'); |
||||
|
model.set('appendContent','test2'); |
||||
|
view.$el.html().should.be.equal('testtest2'); |
||||
|
}); |
||||
|
|
||||
|
it('Update content', function() { |
||||
|
model.set('content','test'); |
||||
|
model.set('content','test2'); |
||||
|
view.$el.html().should.be.equal('test2'); |
||||
|
}); |
||||
|
|
||||
|
describe('Init with options', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
model = new Panel({ |
||||
|
buttons: [{}] |
||||
|
}); |
||||
|
view = new PanelView({ |
||||
|
model: model |
||||
|
}); |
||||
|
$fixture.empty().appendTo($fixtures); |
||||
|
$fixture.html(view.render().el); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
view.remove(); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
}); |
||||
Loading…
Reference in new issue