mirror of https://github.com/artf/grapesjs.git
13 changed files with 350 additions and 64 deletions
@ -0,0 +1,67 @@ |
|||||
|
|
||||
|
define( |
||||
|
function(require) { |
||||
|
|
||||
|
return { |
||||
|
run : function(){ |
||||
|
describe('E2E tests', function() { |
||||
|
|
||||
|
before(function () { |
||||
|
this.$fixtures = $("#fixtures"); |
||||
|
this.$fixture = $('<div id="ClassManager-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
var Grapes = require('editor/main'); |
||||
|
this.gjs = new Grapes({ |
||||
|
storageType: 'none', |
||||
|
storageManager: { |
||||
|
storageType: 'none', |
||||
|
}, |
||||
|
assetManager: { |
||||
|
storageType: 'none', |
||||
|
}, |
||||
|
container: '#ClassManager-fixture', |
||||
|
}); |
||||
|
this.$fixture.empty().appendTo(this.$fixtures); |
||||
|
this.gjs.render(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.gjs; |
||||
|
}); |
||||
|
|
||||
|
after(function () { |
||||
|
this.$fixture.remove(); |
||||
|
}); |
||||
|
|
||||
|
it('Assign correctly new class to component', function() { |
||||
|
var wrp = this.gjs.editor.get('Components').getWrapper().get('components'); |
||||
|
var model = wrp.add({}); |
||||
|
model.get('classes').length.should.equal(0); |
||||
|
|
||||
|
// Init Class Manager and set editor as a target
|
||||
|
var clm = this.gjs.editor.get('ClassManager'); |
||||
|
clm.config.target = this.gjs.editor; |
||||
|
if(clm){ |
||||
|
var $clm = new clm.ClassTagsView({ |
||||
|
collection: new clm.ClassTags([]), |
||||
|
config: clm.config, |
||||
|
}).render(); |
||||
|
this.$fixture.append($clm.el); |
||||
|
} |
||||
|
|
||||
|
// Select element
|
||||
|
this.gjs.editor.set('selectedComponent', model); |
||||
|
|
||||
|
$clm.addNewTag('test'); |
||||
|
model.get('classes').length.should.equal(1); |
||||
|
model.get('classes').at(0).get('name').should.equal('test'); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
}); |
||||
@ -0,0 +1,94 @@ |
|||||
|
var modulePath = './../../../test/specs/class_manager'; |
||||
|
|
||||
|
define([ |
||||
|
'ClassManager', |
||||
|
modulePath + '/model/ClassModels', |
||||
|
modulePath + '/view/ClassTagView', |
||||
|
modulePath + '/e2e/ClassManager' |
||||
|
], |
||||
|
function( |
||||
|
ClassManager, |
||||
|
Models, |
||||
|
ClassTagView, |
||||
|
e2e |
||||
|
) { |
||||
|
|
||||
|
describe('Class Manager', function() { |
||||
|
|
||||
|
describe('Main', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new ClassManager(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Object exists', function() { |
||||
|
ClassManager.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
it('No classes inside', function() { |
||||
|
this.obj.getClasses().length.should.equal(0); |
||||
|
}); |
||||
|
|
||||
|
it('Able to add default classes', function() { |
||||
|
var cm = new ClassManager({ |
||||
|
classes: ['test1', 'test2', 'test3'], |
||||
|
}); |
||||
|
cm.getClasses().length.should.equal(3); |
||||
|
}); |
||||
|
|
||||
|
it('Add new class', function() { |
||||
|
this.obj.addClass('test'); |
||||
|
this.obj.getClasses().length.should.equal(1); |
||||
|
}); |
||||
|
|
||||
|
it('Check name property', function() { |
||||
|
var className = 'test'; |
||||
|
var obj = this.obj.addClass(className); |
||||
|
obj.get('name').should.equal(className); |
||||
|
}); |
||||
|
|
||||
|
it('Add 2 classes', function() { |
||||
|
this.obj.addClass('test'); |
||||
|
this.obj.addClass('test2'); |
||||
|
this.obj.getClasses().length.should.equal(2); |
||||
|
}); |
||||
|
|
||||
|
it('Add 2 same classes', function() { |
||||
|
this.obj.addClass('test'); |
||||
|
this.obj.addClass('test'); |
||||
|
this.obj.getClasses().length.should.equal(1); |
||||
|
}); |
||||
|
|
||||
|
it('Get class', function() { |
||||
|
var className = 'test'; |
||||
|
var obj = this.obj.addClass(className); |
||||
|
(this.obj.getClass(className) === null).should.equal(false); |
||||
|
}); |
||||
|
|
||||
|
it('Get empty class', function() { |
||||
|
(this.obj.getClass('test') === null).should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Get same class', function() { |
||||
|
var className = 'test'; |
||||
|
var obj = this.obj.addClass(className); |
||||
|
var obj2 = this.obj.getClass(className); |
||||
|
obj2.should.deep.equal(obj); |
||||
|
}); |
||||
|
|
||||
|
it('escapeName test', function() { |
||||
|
this.obj.escapeName('@Te sT*').should.equal('-te-st-'); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
Models.run(); |
||||
|
ClassTagView.run(); |
||||
|
e2e.run(); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,39 @@ |
|||||
|
var path = 'ClassManager/model/'; |
||||
|
define([path + 'ClassTag', |
||||
|
path + 'ClassTags'], |
||||
|
function(ClassTag, ClassTags) { |
||||
|
|
||||
|
return { |
||||
|
run : function(){ |
||||
|
describe('ClassTag', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new ClassTag(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Has name property', function() { |
||||
|
this.obj.has('name').should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Has label property', function() { |
||||
|
this.obj.has('label').should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
describe('ClassTags', function() { |
||||
|
|
||||
|
it('Creates collection item correctly', function() { |
||||
|
var c = new ClassTags(); |
||||
|
var m = c.add({}); |
||||
|
m.should.be.an.instanceOf(ClassTag); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
}); |
||||
@ -0,0 +1,72 @@ |
|||||
|
var path = 'ClassManager/view/'; |
||||
|
define([path + 'ClassTagView', 'ClassManager/model/ClassTags'], |
||||
|
function(ClassTagView, ClassTags) { |
||||
|
|
||||
|
return { |
||||
|
run : function(){ |
||||
|
describe('ClassTagView', function() { |
||||
|
|
||||
|
before(function () { |
||||
|
this.$fixtures = $("#fixtures"); |
||||
|
this.$fixture = $('<div class="classtag-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
var coll = new ClassTags(); |
||||
|
this.testLabel = 'TestLabel'; |
||||
|
var model = coll.add({ |
||||
|
name: 'test', |
||||
|
label: this.testLabel, |
||||
|
}); |
||||
|
this.view = new ClassTagView({ |
||||
|
config : {}, |
||||
|
model: model |
||||
|
}); |
||||
|
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() { |
||||
|
ClassTagView.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
it('Not empty', function() { |
||||
|
var $el = this.view.$el; |
||||
|
$el.html().should.not.be.empty; |
||||
|
}); |
||||
|
|
||||
|
it('Not empty', function() { |
||||
|
var $el = this.view.$el; |
||||
|
$el.html().should.contain(this.testLabel); |
||||
|
}); |
||||
|
|
||||
|
describe('Should be rendered correctly', function() { |
||||
|
|
||||
|
it('Has close button', function() { |
||||
|
var $el = this.view.$el; |
||||
|
$el.find('#close').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
it('Could be removed', function() { |
||||
|
var spy = sinon.spy(); |
||||
|
this.view.config.target = { get:function(){} }; |
||||
|
sinon.stub(this.view.config.target, 'get').returns(0); |
||||
|
this.view.$el.find('#close').trigger('click'); |
||||
|
this.$fixture.html().should.be.empty; |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
}); |
||||
Loading…
Reference in new issue