mirror of https://github.com/artf/grapesjs.git
12 changed files with 267 additions and 274 deletions
@ -0,0 +1,67 @@ |
|||
const DeviceManager = require('device_manager'); |
|||
const DevicesView = require('./view/DevicesView'); |
|||
|
|||
describe('DeviceManager', () => { |
|||
|
|||
describe('Main', () => { |
|||
|
|||
var obj; |
|||
var testNameDevice; |
|||
var testWidthDevice; |
|||
|
|||
beforeEach(() => { |
|||
testNameDevice = 'Tablet'; |
|||
testWidthDevice = '100px'; |
|||
obj = new DeviceManager().init(); |
|||
}); |
|||
|
|||
afterEach(() => { |
|||
obj = null; |
|||
}); |
|||
|
|||
it('Object exists', () => { |
|||
expect(obj).toExist(); |
|||
}); |
|||
|
|||
it('No device inside', () => { |
|||
var coll = obj.getAll(); |
|||
expect(coll.length).toEqual(0); |
|||
}); |
|||
|
|||
it('Add new device', () => { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
expect(obj.getAll().length).toEqual(1); |
|||
}); |
|||
|
|||
it('Added device has correct data', () => { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
expect(model.get('name')).toEqual(testNameDevice); |
|||
expect(model.get('width')).toEqual(testWidthDevice); |
|||
}); |
|||
|
|||
it('Add device width options', () => { |
|||
var model = obj.add(testNameDevice, testWidthDevice, {opt: 'value'}); |
|||
expect(model.get('opt')).toEqual('value'); |
|||
}); |
|||
|
|||
it('The name of the device is unique', () => { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
var model2 = obj.add(testNameDevice, '2px'); |
|||
expect(model).toEqual(model2); |
|||
}); |
|||
|
|||
it('Get device by name', () => { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
var model2 = obj.get(testNameDevice); |
|||
expect(model).toEqual(model2); |
|||
}); |
|||
|
|||
it('Render devices', () => { |
|||
expect(obj.render()).toExist(); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
DevicesView.run(); |
|||
|
|||
}); |
|||
@ -1,70 +0,0 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var DeviceManager = require('DeviceManager'); |
|||
var DevicesView = require('undefined'); |
|||
|
|||
describe('DeviceManager', function() { |
|||
|
|||
describe('Main', function() { |
|||
|
|||
var obj; |
|||
var testNameDevice; |
|||
var testWidthDevice; |
|||
|
|||
beforeEach(function () { |
|||
testNameDevice = 'Tablet'; |
|||
testWidthDevice = '100px'; |
|||
obj = new DeviceManager().init(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
obj.should.be.exist; |
|||
}); |
|||
|
|||
it('No device inside', function() { |
|||
var coll = obj.getAll(); |
|||
coll.length.should.equal(0); |
|||
}); |
|||
|
|||
it('Add new device', function() { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
obj.getAll().length.should.equal(1); |
|||
}); |
|||
|
|||
it('Added device has correct data', function() { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
model.get('name').should.equal(testNameDevice); |
|||
model.get('width').should.equal(testWidthDevice); |
|||
}); |
|||
|
|||
it('Add device width options', function() { |
|||
var model = obj.add(testNameDevice, testWidthDevice, {opt: 'value'}); |
|||
model.get('opt').should.equal('value'); |
|||
}); |
|||
|
|||
it('The name of the device is unique', function() { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
var model2 = obj.add(testNameDevice, '2px'); |
|||
model.should.deep.equal(model2); |
|||
}); |
|||
|
|||
it('Get device by name', function() { |
|||
var model = obj.add(testNameDevice, testWidthDevice); |
|||
var model2 = obj.get(testNameDevice); |
|||
model.should.deep.equal(model2); |
|||
}); |
|||
|
|||
it('Render devices', function() { |
|||
obj.render().should.be.ok; |
|||
}); |
|||
|
|||
}); |
|||
|
|||
DevicesView.run(); |
|||
|
|||
}); |
|||
}); |
|||
@ -1,83 +1,79 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var DevicesView = require('undefined'); |
|||
var Devices = require('DeviceManager/model/Devices'); |
|||
|
|||
module.exports = { |
|||
run : function(){ |
|||
describe('DevicesView', function() { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
var editorModel; |
|||
const DevicesView = require('device_manager/view/DevicesView'); |
|||
const Devices = require('device_manager/model/Devices'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('DevicesView', () => { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
var editorModel; |
|||
|
|||
before(() => { |
|||
$fixtures = $("#fixtures"); |
|||
$fixture = $('<div class="devices-fixture"></div>'); |
|||
}); |
|||
|
|||
before(function () { |
|||
$fixtures = $("#fixtures"); |
|||
$fixture = $('<div class="devices-fixture"></div>'); |
|||
}); |
|||
beforeEach(() => { |
|||
model = new Devices([]); |
|||
view = new DevicesView({ |
|||
collection: model |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
model = new Devices([]); |
|||
view = new DevicesView({ |
|||
collection: model |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
afterEach(() => { |
|||
view.collection.reset(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
view.collection.reset(); |
|||
}); |
|||
after(() => { |
|||
$fixture.remove(); |
|||
}); |
|||
|
|||
after(function () { |
|||
$fixture.remove(); |
|||
}); |
|||
it("The content is not empty", () => { |
|||
expect(view.el.innerHTML).toExist(); |
|||
}); |
|||
|
|||
it("The content is not empty", function (){ |
|||
view.el.innerHTML.should.be.not.empty; |
|||
}); |
|||
it("No options without devices", () => { |
|||
expect(view.getOptions()).toEqual(''); |
|||
}); |
|||
|
|||
it("No options without devices", function (){ |
|||
view.getOptions().should.equal(''); |
|||
}); |
|||
it("Render new button", () => { |
|||
view.collection.add({}); |
|||
expect(view.$el.html()).toExist(); |
|||
}); |
|||
|
|||
it("Render new button", function (){ |
|||
view.collection.add({}); |
|||
view.$el.html().should.not.be.empty; |
|||
describe('With configs', () => { |
|||
|
|||
beforeEach(() => { |
|||
editorModel = new Backbone.Model(); |
|||
model = new Devices([ |
|||
{name:'test1'}, |
|||
{name:'test2'} |
|||
]); |
|||
view = new DevicesView({ |
|||
collection: model, |
|||
config: { em: editorModel } |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
describe('With configs', function() { |
|||
it("Update device on select change", () => { |
|||
view.$el.find('select').val('test2'); |
|||
view.updateDevice(); |
|||
expect(view.config.em.get('device')).toEqual('test2'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
editorModel = new Backbone.Model(); |
|||
model = new Devices([ |
|||
{name:'test1'}, |
|||
{name:'test2'} |
|||
]); |
|||
view = new DevicesView({ |
|||
collection: model, |
|||
config: { em: editorModel } |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
it("Update device on select change", function (){ |
|||
view.$el.find('select').val('test2'); |
|||
view.updateDevice(); |
|||
view.config.em.get('device').should.equal('test2'); |
|||
}); |
|||
|
|||
it("Render options", function (){ |
|||
view.getOptions().should.equal('<option value="test1">test1</option><option value="test2">test2</option>'); |
|||
}); |
|||
|
|||
}); |
|||
it("Render options", () => { |
|||
expect(view.getOptions()).toEqual('<option value="test1">test1</option><option value="test2">test2</option>'); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
Loading…
Reference in new issue