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){ |
var Backbone = require('backbone'); |
||||
'use strict'; |
var BlocksView = require('block_manager/view/BlocksView'); |
||||
var BlocksView = require('undefined'); |
var Blocks = require('block_manager/model/Blocks'); |
||||
var Blocks = require('BlockManager/model/Blocks'); |
|
||||
|
module.exports = { |
||||
module.exports = { |
run() { |
||||
run : function(){ |
describe('BlocksView', () => { |
||||
describe('BlocksView', function() { |
|
||||
|
var $fixtures; |
||||
var $fixtures; |
var $fixture; |
||||
var $fixture; |
var model; |
||||
var model; |
var view; |
||||
var view; |
var editorModel; |
||||
var editorModel; |
var ppfx; |
||||
var ppfx; |
|
||||
|
before(() => { |
||||
before(function () { |
$fixtures = $('#fixtures'); |
||||
$fixtures = $("#fixtures"); |
$fixture = $('<div class="devices-fixture"></div>'); |
||||
$fixture = $('<div class="devices-fixture"></div>'); |
}); |
||||
}); |
|
||||
|
|
||||
beforeEach(function () { |
beforeEach(() => { |
||||
model = new Blocks([]); |
model = new Blocks([]); |
||||
view = new BlocksView({ collection: model }); |
view = new BlocksView({ collection: model }); |
||||
$fixture.empty().appendTo($fixtures); |
$fixture.empty().appendTo($fixtures); |
||||
$fixture.html(view.render().el); |
$fixture.html(view.render().el); |
||||
}); |
}); |
||||
|
|
||||
afterEach(function () { |
afterEach(() => { |
||||
view.collection.reset(); |
view.collection.reset(); |
||||
}); |
}); |
||||
|
|
||||
after(function () { |
after(() => { |
||||
$fixture.remove(); |
$fixture.remove(); |
||||
}); |
}); |
||||
|
|
||||
it("The container is not empty", function (){ |
it("The container is not empty", () => { |
||||
view.el.outerHTML.should.be.not.empty; |
expect(view.el.outerHTML).toExist(); |
||||
}); |
}); |
||||
|
|
||||
it("No children inside", function (){ |
it("No children inside", () => { |
||||
view.el.children.length.should.equal(0); |
expect(view.el.children.length).toEqual(0); |
||||
}); |
}); |
||||
|
|
||||
it("Render children on add", function (){ |
it("Render children on add", () => { |
||||
model.add({}); |
model.add({}); |
||||
view.el.children.length.should.equal(1); |
expect(view.el.children.length).toEqual(1); |
||||
model.add([{},{}]); |
model.add([{},{}]); |
||||
view.el.children.length.should.equal(3); |
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 (){ |
describe('With configs', () => { |
||||
model.add([{},{}]); |
|
||||
view.el.children.length.should.equal(2); |
beforeEach(() => { |
||||
model.at(0).destroy(); |
ppfx = 'pfx-t-'; |
||||
view.el.children.length.should.equal(1); |
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() { |
it("Render children", () => { |
||||
|
expect(view.el.children.length).toEqual(2); |
||||
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 container", () => { |
||||
|
expect(view.el.getAttribute('class')).toEqual(ppfx + 'blocks-c'); |
||||
|
}); |
||||
|
|
||||
}); |
}); |
||||
} |
|
||||
}; |
|
||||
|
|
||||
}); |
}); |
||||
|
} |
||||
|
}; |
||||
|
|||||
@ -1,21 +1,17 @@ |
|||||
define(function () { |
define(() => ({ |
||||
return { |
storageMock: function() { |
||||
|
var db = {}; |
||||
storageMock: function() { |
return { |
||||
var db = {}; |
id: 'testStorage', |
||||
return { |
store: function(data){ |
||||
id: 'testStorage', |
db = data; |
||||
store: function(data){ |
}, |
||||
db = data; |
load: function(keys){ |
||||
}, |
return db; |
||||
load: function(keys){ |
}, |
||||
return db; |
getDb: function(){ |
||||
}, |
return db; |
||||
getDb: function(){ |
}, |
||||
return db; |
}; |
||||
}, |
} |
||||
}; |
})); |
||||
}, |
|
||||
|
|
||||
}; |
|
||||
}); |
|
||||
|
|||||
Loading…
Reference in new issue