mirror of https://github.com/artf/grapesjs.git
14 changed files with 409 additions and 117 deletions
@ -1,17 +1,17 @@ |
|||||
define(['backbone'], |
define(['backbone'], |
||||
function (Backbone) { |
function (Backbone) { |
||||
/** |
/** |
||||
* @class AssetView |
* @class AssetView |
||||
* */ |
* */ |
||||
return Backbone.View.extend({ |
return Backbone.View.extend({ |
||||
|
|
||||
initialize: function(o) { |
initialize: function(o) { |
||||
this.options = o; |
this.options = o; |
||||
this.config = o.config || {}; |
this.config = o.config || {}; |
||||
this.pfx = this.config.stylePrefix; |
this.pfx = this.config.stylePrefix || ''; |
||||
this.className = this.pfx + 'asset'; |
this.className = this.pfx + 'asset'; |
||||
this.listenTo( this.model, 'destroy remove', this.remove ); |
this.listenTo( this.model, 'destroy remove', this.remove ); |
||||
}, |
}, |
||||
|
|
||||
}); |
}); |
||||
}); |
}); |
||||
|
|||||
@ -0,0 +1,77 @@ |
|||||
|
define(['AssetManager/view/AssetImageView', 'AssetManager/model/AssetImage', 'AssetManager/model/Assets'], |
||||
|
function(AssetImageView, AssetImage, Assets) { |
||||
|
|
||||
|
describe('Asset Manager', function() { |
||||
|
|
||||
|
describe('AssetImageView', function() { |
||||
|
|
||||
|
before(function () { |
||||
|
this.$fixtures = $("#fixtures"); |
||||
|
this.$fixture = $('<div class="asset-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
var coll = new Assets(); |
||||
|
var model = coll.add({ type:'image', src: '/test' }); |
||||
|
this.view = new AssetImageView({ |
||||
|
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() { |
||||
|
AssetImageView.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
describe('Asset should be rendered correctly', function() { |
||||
|
|
||||
|
it('Has preview box', function() { |
||||
|
var $asset = this.view.$el; |
||||
|
$asset.find('#preview').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
it('Has meta box', function() { |
||||
|
var $asset = this.view.$el; |
||||
|
$asset.find('#meta').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
it('Has close button', function() { |
||||
|
var $asset = this.view.$el; |
||||
|
$asset.find('#close').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
it('Could be selected', function() { |
||||
|
sinon.stub(this.view, 'updateTarget'); |
||||
|
this.view.$el.trigger('click'); |
||||
|
this.view.$el.attr('class').should.contain('highlight'); |
||||
|
this.view.updateTarget.calledOnce.should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Could be chosen', function() { |
||||
|
sinon.stub(this.view, 'updateTarget'); |
||||
|
this.view.$el.trigger('dblclick'); |
||||
|
this.view.updateTarget.calledOnce.should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Could be removed', function() { |
||||
|
var spy = sinon.spy(); |
||||
|
this.view.model.on("remove", spy); |
||||
|
this.view.$el.find('#close').trigger('click'); |
||||
|
spy.called.should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,42 @@ |
|||||
|
define(['AssetManager/view/AssetView', 'AssetManager/model/Asset', 'AssetManager/model/Assets'], |
||||
|
function(AssetView, Asset, Assets) { |
||||
|
|
||||
|
describe('Asset Manager', function() { |
||||
|
|
||||
|
describe('AssetView', function() { |
||||
|
|
||||
|
before(function () { |
||||
|
this.$fixtures = $("#fixtures"); |
||||
|
this.$fixture = $('<div class="asset-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
var coll = new Assets(); |
||||
|
var model = coll.add({}); |
||||
|
this.view = new AssetView({ |
||||
|
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() { |
||||
|
AssetView.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
it('Has correct prefix', function() { |
||||
|
this.view.pfx.should.equal(''); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,77 @@ |
|||||
|
define(['AssetManager/view/FileUploader'], |
||||
|
function(FileUploader) { |
||||
|
|
||||
|
describe('Asset Manager', function() { |
||||
|
|
||||
|
describe('File Uploader', function() { |
||||
|
|
||||
|
before(function () { |
||||
|
this.$fixtures = $("#fixtures"); |
||||
|
this.$fixture = $('<div class="fileupload-fixture"></div>'); |
||||
|
}); |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.view = new FileUploader({ config : {} }); |
||||
|
this.$fixture.empty().appendTo(this.$fixtures); |
||||
|
this.$fixture.html(this.view.render().el); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
this.view.remove(); |
||||
|
}); |
||||
|
|
||||
|
after(function () { |
||||
|
this.$fixture.remove(); |
||||
|
}); |
||||
|
|
||||
|
it('Object exists', function() { |
||||
|
FileUploader.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
it('Has correct prefix', function() { |
||||
|
this.view.pfx.should.equal(''); |
||||
|
}); |
||||
|
|
||||
|
describe('Should be rendered correctly', function() { |
||||
|
|
||||
|
it('Has title', function() { |
||||
|
this.view.$el.find('#title').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
it('Title is empty', function() { |
||||
|
this.view.$el.find('#title').html().should.equal(''); |
||||
|
}); |
||||
|
|
||||
|
it('Has file input', function() { |
||||
|
this.view.$el.find('input[type=file]').should.have.property(0); |
||||
|
}); |
||||
|
|
||||
|
it('File input is enabled', function() { |
||||
|
this.view.$el.find('input[type=file]').prop('disabled').should.equal(false); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
describe('Interprets configurations correctly', function() { |
||||
|
|
||||
|
it('Has correct title', function() { |
||||
|
var view = new FileUploader({ config : { |
||||
|
uploadText : 'Test', |
||||
|
} }); |
||||
|
view.render(); |
||||
|
view.$el.find('#title').html().should.equal('Test'); |
||||
|
}); |
||||
|
|
||||
|
it('Could be disabled', function() { |
||||
|
var view = new FileUploader({ config : { |
||||
|
disableUpload: true, |
||||
|
} }); |
||||
|
view.render(); |
||||
|
view.$el.find('input[type=file]').prop('disabled').should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
@ -1,36 +0,0 @@ |
|||||
define(['componentModel'], |
|
||||
function(componentModel) { |
|
||||
describe('Component', function() { |
|
||||
|
|
||||
it('Contiene valori di default', function() {//Has default values
|
|
||||
var model = new componentModel({}); |
|
||||
var modelComponents = model.components; |
|
||||
model.should.be.ok; |
|
||||
model.get('tagName').should.equal("div"); |
|
||||
model.get('classes').should.be.empty; |
|
||||
model.get('css').should.be.empty; |
|
||||
model.get('attributes').should.be.empty; |
|
||||
modelComponents.models.should.be.empty; |
|
||||
}); |
|
||||
it('Non ci sono altri componenti all\'interno ', function() {//No other components inside
|
|
||||
var model = new componentModel({}); |
|
||||
var modelComponents = model.components; |
|
||||
model.should.be.ok; |
|
||||
modelComponents.models.should.be.empty; |
|
||||
}); |
|
||||
it('Imposta valori passati', function() {//Sets passed attributes
|
|
||||
var model = new componentModel({ |
|
||||
tagName : 'span', |
|
||||
classes : ['one','two','three'], |
|
||||
css : { 'one':'vone', 'two':'vtwo', }, |
|
||||
attributes : { 'data-one':'vone', 'data-two':'vtwo', }, |
|
||||
}); |
|
||||
model.should.be.ok; |
|
||||
model.get('tagName').should.equal("span"); |
|
||||
model.get('classes').should.have.length(3); |
|
||||
model.get('css').should.have.keys(["one", "two",]); |
|
||||
model.get('attributes').should.have.keys(["data-one", "data-two",]); |
|
||||
}); |
|
||||
it('Possibilità di istanziare componenti annidati'); //Possibility to init nested components
|
|
||||
}); |
|
||||
}); |
|
||||
@ -1,58 +0,0 @@ |
|||||
define(['Components'], |
|
||||
function(Components) { |
|
||||
describe('Components', function() { |
|
||||
before(function () { |
|
||||
this.collection = new Components(); |
|
||||
this.collection.localStorage._clear(); |
|
||||
}); |
|
||||
after(function () { |
|
||||
this.collection = null; |
|
||||
}); |
|
||||
describe('Creazione', function() { |
|
||||
it('Contiene valori di default', function() {//Has default values
|
|
||||
this.collection.should.be.ok; |
|
||||
this.collection.should.have.length(0); |
|
||||
}); |
|
||||
}); |
|
||||
describe('Modifica', function() { |
|
||||
beforeEach(function () { |
|
||||
this.collection.create({ |
|
||||
tagName : 'span', |
|
||||
classes : ['one','two','three'], |
|
||||
css : { 'one':'vone', 'two':'vtwo', }, |
|
||||
attributes : { 'data-one':'vone', 'data-two':'vtwo', }, |
|
||||
}); |
|
||||
}); |
|
||||
afterEach(function () { |
|
||||
this.collection.localStorage._clear(); |
|
||||
this.collection.reset(); |
|
||||
}); |
|
||||
it('Contiene un singolo componente', function(done) { //Has single object
|
|
||||
var collection = this.collection, model; |
|
||||
|
|
||||
collection.once("reset", function () { |
|
||||
collection.should.have.length(1); |
|
||||
model = collection.at(0); |
|
||||
model.should.be.ok; |
|
||||
model.get('tagName').should.equal("span"); |
|
||||
model.get('classes').should.have.length(3); |
|
||||
model.get('css').should.have.keys(["one", "two",]); |
|
||||
model.get('attributes').should.have.keys(["data-one", "data-two",]); |
|
||||
done(); |
|
||||
}); |
|
||||
collection.fetch({ reset: true }); |
|
||||
}); |
|
||||
|
|
||||
it("Componenete eliminabile", function (done) { //Can delete a component
|
|
||||
var collection = this.collection, model; |
|
||||
collection.should.have.length(1); |
|
||||
collection.once("remove", function () { |
|
||||
collection.should.have.length(0); |
|
||||
done(); |
|
||||
}); |
|
||||
|
|
||||
model = collection.shift(); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
@ -0,0 +1,46 @@ |
|||||
|
var modulePath = './../../../test/specs/dom_components'; |
||||
|
|
||||
|
define([ |
||||
|
'DomComponents', |
||||
|
modulePath + '/model/Component' |
||||
|
], |
||||
|
function(DomComponents, |
||||
|
ComponentModels |
||||
|
) { |
||||
|
|
||||
|
describe('DOM Components', function() { |
||||
|
|
||||
|
describe('Main', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new DomComponents(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Object exists', function() { |
||||
|
DomComponents.should.be.exist; |
||||
|
}); |
||||
|
|
||||
|
it('Wrapper exists', function() { |
||||
|
this.obj.getWrapper().should.not.be.empty; |
||||
|
}); |
||||
|
|
||||
|
it('No components inside', function() { |
||||
|
this.obj.getComponents().length.should.equal(0); |
||||
|
}); |
||||
|
|
||||
|
it('Render wrapper', function() { |
||||
|
sinon.stub(this.obj.ComponentView, "render").returns({ el: '' }); |
||||
|
this.obj.render(); |
||||
|
this.obj.ComponentView.render.calledOnce.should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
ComponentModels.run(); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,109 @@ |
|||||
|
define(['DomComponents/model/Component', |
||||
|
'DomComponents/model/ComponentImage', |
||||
|
'DomComponents/model/ComponentText', |
||||
|
'DomComponents/model/Components'], |
||||
|
function(Component, ComponentImage, ComponentText, Components) { |
||||
|
|
||||
|
return { |
||||
|
run : function(){ |
||||
|
describe('Component', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new Component(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Has no children', function() { |
||||
|
this.obj.get('components').length.should.equal(0); |
||||
|
}); |
||||
|
|
||||
|
it('Clones correctly', function() { |
||||
|
var sAttr = this.obj.attributes; |
||||
|
var cloned = this.obj.clone(); |
||||
|
var eAttr = cloned.attributes; |
||||
|
sAttr.components = {}; |
||||
|
eAttr.components = {}; |
||||
|
sAttr.should.deep.equal(eAttr); |
||||
|
}); |
||||
|
|
||||
|
it('Has expected name', function() { |
||||
|
this.obj.cid = 'c999'; |
||||
|
this.obj.getName().should.equal('Box999'); |
||||
|
}); |
||||
|
|
||||
|
it('Has expected name 2', function() { |
||||
|
this.obj.cid = 'c999'; |
||||
|
this.obj.set('type','testType'); |
||||
|
this.obj.getName().should.equal('TestTypeBox999'); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
describe('Image Component', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new ComponentImage(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Has src property', function() { |
||||
|
this.obj.has('src').should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Not droppable', function() { |
||||
|
this.obj.get('droppable').should.equal(false); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
describe('Text Component', function() { |
||||
|
|
||||
|
beforeEach(function () { |
||||
|
this.obj = new ComponentText(); |
||||
|
}); |
||||
|
|
||||
|
afterEach(function () { |
||||
|
delete this.obj; |
||||
|
}); |
||||
|
|
||||
|
it('Has content property', function() { |
||||
|
this.obj.has('content').should.equal(true); |
||||
|
}); |
||||
|
|
||||
|
it('Not droppable', function() { |
||||
|
this.obj.get('droppable').should.equal(false); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
|
||||
|
describe('Components', function() { |
||||
|
|
||||
|
it('Creates component correctly', function() { |
||||
|
var c = new Components(); |
||||
|
var m = c.add({}); |
||||
|
m.should.be.an.instanceOf(Component); |
||||
|
}); |
||||
|
|
||||
|
it('Creates image component correctly', function() { |
||||
|
var c = new Components(); |
||||
|
var m = c.add({ type: 'image' }); |
||||
|
m.should.be.an.instanceOf(ComponentImage); |
||||
|
}); |
||||
|
|
||||
|
it('Creates text component correctly', function() { |
||||
|
var c = new Components(); |
||||
|
var m = c.add({ type: 'text' }); |
||||
|
m.should.be.an.instanceOf(ComponentText); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
}); |
||||
Loading…
Reference in new issue