mirror of https://github.com/artf/grapesjs.git
13 changed files with 177 additions and 186 deletions
@ -0,0 +1,70 @@ |
|||
var BlockManager = require('block_manager'); |
|||
var BlocksView = require('./view/BlocksView'); |
|||
|
|||
describe('BlockManager', () => { |
|||
|
|||
describe('Main', () => { |
|||
|
|||
var obj; |
|||
var idTest; |
|||
var optsTest; |
|||
|
|||
beforeEach(() => { |
|||
idTest = 'h1-block'; |
|||
optsTest = { |
|||
label: 'Heading', |
|||
content: '<h1>Test</h1>' |
|||
}; |
|||
obj = new BlockManager().init(); |
|||
}); |
|||
|
|||
afterEach(() => { |
|||
obj = null; |
|||
}); |
|||
|
|||
it('Object exists', () => { |
|||
expect(obj).toExist(); |
|||
}); |
|||
|
|||
it('No blocks inside', () => { |
|||
expect(obj.getAll().length).toEqual(0); |
|||
}); |
|||
|
|||
it('Add new block', () => { |
|||
var model = obj.add(idTest, optsTest); |
|||
expect(obj.getAll().length).toEqual(1); |
|||
}); |
|||
|
|||
it('Added block has correct data', () => { |
|||
var model = obj.add(idTest, optsTest); |
|||
expect(model.get('label')).toEqual(optsTest.label); |
|||
expect(model.get('content')).toEqual(optsTest.content); |
|||
}); |
|||
|
|||
it('Add block with attributes', () => { |
|||
optsTest.attributes = {'class':'test'}; |
|||
var model = obj.add(idTest, optsTest); |
|||
expect(model.get('attributes').class).toEqual('test'); |
|||
}); |
|||
|
|||
it('The id of the block is unique', () => { |
|||
var model = obj.add(idTest, optsTest); |
|||
var model2 = obj.add(idTest, {other: 'test'}); |
|||
expect(model).toEqual(model2); |
|||
}); |
|||
|
|||
it('Get block by id', () => { |
|||
var model = obj.add(idTest, optsTest); |
|||
var model2 = obj.get(idTest); |
|||
expect(model).toEqual(model2); |
|||
}); |
|||
|
|||
it('Render blocks', () => { |
|||
expect(obj.render()).toExist(); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
BlocksView.run(); |
|||
|
|||
}); |
|||
@ -1,74 +0,0 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var BlockManager = require('BlockManager'); |
|||
var BlocksView = require('undefined'); |
|||
|
|||
describe('BlockManager', function() { |
|||
|
|||
describe('Main', function() { |
|||
|
|||
var obj; |
|||
var idTest; |
|||
var optsTest; |
|||
|
|||
beforeEach(function () { |
|||
idTest = 'h1-block'; |
|||
optsTest = { |
|||
label: 'Heading', |
|||
content: '<h1>Test</h1>' |
|||
}; |
|||
obj = new BlockManager().init(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
obj.should.be.exist; |
|||
}); |
|||
|
|||
it('No blocks inside', function() { |
|||
var coll = obj.getAll(); |
|||
coll.length.should.equal(0); |
|||
}); |
|||
|
|||
it('Add new block', function() { |
|||
var model = obj.add(idTest, optsTest); |
|||
obj.getAll().length.should.equal(1); |
|||
}); |
|||
|
|||
it('Added block has correct data', function() { |
|||
var model = obj.add(idTest, optsTest); |
|||
model.get('label').should.equal(optsTest.label); |
|||
model.get('content').should.equal(optsTest.content); |
|||
}); |
|||
|
|||
it('Add block with attributes', function() { |
|||
optsTest.attributes = {'class':'test'}; |
|||
var model = obj.add(idTest, optsTest); |
|||
model.get('attributes').class.should.equal('test'); |
|||
}); |
|||
|
|||
it('The id of the block is unique', function() { |
|||
var model = obj.add(idTest, optsTest); |
|||
var model2 = obj.add(idTest, {other: 'test'}); |
|||
model.should.deep.equal(model2); |
|||
}); |
|||
|
|||
it('Get block by id', function() { |
|||
var model = obj.add(idTest, optsTest); |
|||
var model2 = obj.get(idTest); |
|||
model.should.deep.equal(model2); |
|||
}); |
|||
|
|||
it('Render blocks', function() { |
|||
obj.render().should.be.ok; |
|||
}); |
|||
|
|||
}); |
|||
|
|||
BlocksView.run(); |
|||
|
|||
}); |
|||
}); |
|||
@ -1,91 +1,88 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var BlocksView = require('undefined'); |
|||
var Blocks = require('BlockManager/model/Blocks'); |
|||
|
|||
module.exports = { |
|||
run : function(){ |
|||
describe('BlocksView', function() { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
var editorModel; |
|||
var ppfx; |
|||
|
|||
before(function () { |
|||
$fixtures = $("#fixtures"); |
|||
$fixture = $('<div class="devices-fixture"></div>'); |
|||
}); |
|||
var Backbone = require('backbone'); |
|||
var BlocksView = require('block_manager/view/BlocksView'); |
|||
var Blocks = require('block_manager/model/Blocks'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('BlocksView', () => { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
var editorModel; |
|||
var ppfx; |
|||
|
|||
before(() => { |
|||
$fixtures = $('#fixtures'); |
|||
$fixture = $('<div class="devices-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
model = new Blocks([]); |
|||
view = new BlocksView({ collection: model }); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
beforeEach(() => { |
|||
model = new Blocks([]); |
|||
view = new BlocksView({ collection: model }); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
view.collection.reset(); |
|||
}); |
|||
afterEach(() => { |
|||
view.collection.reset(); |
|||
}); |
|||
|
|||
after(function () { |
|||
$fixture.remove(); |
|||
}); |
|||
after(() => { |
|||
$fixture.remove(); |
|||
}); |
|||
|
|||
it("The container is not empty", function (){ |
|||
view.el.outerHTML.should.be.not.empty; |
|||
}); |
|||
it("The container is not empty", () => { |
|||
expect(view.el.outerHTML).toExist(); |
|||
}); |
|||
|
|||
it("No children inside", function (){ |
|||
view.el.children.length.should.equal(0); |
|||
}); |
|||
it("No children inside", () => { |
|||
expect(view.el.children.length).toEqual(0); |
|||
}); |
|||
|
|||
it("Render children on add", function (){ |
|||
model.add({}); |
|||
view.el.children.length.should.equal(1); |
|||
model.add([{},{}]); |
|||
view.el.children.length.should.equal(3); |
|||
}); |
|||
it("Render children on add", () => { |
|||
model.add({}); |
|||
expect(view.el.children.length).toEqual(1); |
|||
model.add([{},{}]); |
|||
expect(view.el.children.length).toEqual(3); |
|||
}); |
|||
|
|||
it("Destroy children on remove", () => { |
|||
model.add([{},{}]); |
|||
expect(view.el.children.length).toEqual(2); |
|||
model.at(0).destroy(); |
|||
expect(view.el.children.length).toEqual(1); |
|||
}); |
|||
|
|||
it("Destroy children on remove", function (){ |
|||
model.add([{},{}]); |
|||
view.el.children.length.should.equal(2); |
|||
model.at(0).destroy(); |
|||
view.el.children.length.should.equal(1); |
|||
describe('With configs', () => { |
|||
|
|||
beforeEach(() => { |
|||
ppfx = 'pfx-t-'; |
|||
editorModel = new Backbone.Model(); |
|||
model = new Blocks([ |
|||
{name:'test1'}, |
|||
{name:'test2'} |
|||
]); |
|||
view = new BlocksView({ |
|||
collection: model, |
|||
},{ |
|||
pStylePrefix: ppfx |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
describe('With configs', function() { |
|||
|
|||
beforeEach(function () { |
|||
ppfx = 'pfx-t-'; |
|||
editorModel = new Backbone.Model(); |
|||
model = new Blocks([ |
|||
{name:'test1'}, |
|||
{name:'test2'} |
|||
]); |
|||
view = new BlocksView({ |
|||
collection: model, |
|||
},{ |
|||
pStylePrefix: ppfx |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
it("Render children", function (){ |
|||
view.el.children.length.should.equal(2); |
|||
}); |
|||
|
|||
it("Render container", function (){ |
|||
view.el.getAttribute('class').should.equal(ppfx + 'blocks-c'); |
|||
}); |
|||
it("Render children", () => { |
|||
expect(view.el.children.length).toEqual(2); |
|||
}); |
|||
|
|||
}); |
|||
it("Render container", () => { |
|||
expect(view.el.getAttribute('class')).toEqual(ppfx + 'blocks-c'); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
@ -1,21 +1,17 @@ |
|||
define(function () { |
|||
return { |
|||
|
|||
storageMock: function() { |
|||
var db = {}; |
|||
return { |
|||
id: 'testStorage', |
|||
store: function(data){ |
|||
db = data; |
|||
}, |
|||
load: function(keys){ |
|||
return db; |
|||
}, |
|||
getDb: function(){ |
|||
return db; |
|||
}, |
|||
}; |
|||
}, |
|||
|
|||
}; |
|||
}); |
|||
define(() => ({ |
|||
storageMock: function() { |
|||
var db = {}; |
|||
return { |
|||
id: 'testStorage', |
|||
store: function(data){ |
|||
db = data; |
|||
}, |
|||
load: function(keys){ |
|||
return db; |
|||
}, |
|||
getDb: function(){ |
|||
return db; |
|||
}, |
|||
}; |
|||
} |
|||
})); |
|||
|
|||
Loading…
Reference in new issue