mirror of https://github.com/artf/grapesjs.git
7 changed files with 541 additions and 556 deletions
@ -1,129 +1,120 @@ |
|||
define((require, exports, module) => { |
|||
'use strict'; |
|||
var GrapesJS = require('GrapesJS'); |
|||
var Selectors = require('SelectorManager/model/Selectors'); |
|||
var ClassTagsView = require('SelectorManager/view/ClassTagsView'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('E2E tests', () => { |
|||
|
|||
/** |
|||
* Create tags viewer |
|||
* @param {Object} ctx |
|||
*/ |
|||
var instClassTagViewer = ctx => { |
|||
var $clm; |
|||
var clm = ctx.gjs.editor.get('SelectorManager'); |
|||
if(clm){ |
|||
$clm = new ClassTagsView({ |
|||
collection: new Selectors([]), |
|||
config: { |
|||
em: ctx.gjs.editor |
|||
}, |
|||
}).render(); |
|||
ctx.$fixture.append($clm.el); |
|||
} |
|||
return $clm; |
|||
}; |
|||
|
|||
before(function () { |
|||
this.$fixtures = $("#fixtures"); |
|||
this.$fixture = $('<div id="SelectorManager-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
this.gjs = GrapesJS.init({ |
|||
stylePrefix: '', |
|||
storageManager: { autoload: 0, type:'none' }, |
|||
assetManager: { |
|||
storageType: 'none', |
|||
}, |
|||
container: '#SelectorManager-fixture', |
|||
}); |
|||
this.$fixture.empty().appendTo(this.$fixtures); |
|||
this.gjs.render(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete this.gjs; |
|||
}); |
|||
|
|||
after(function () { |
|||
this.$fixture.remove(); |
|||
}); |
|||
|
|||
describe('Interaction with Components', () => { |
|||
|
|||
beforeEach(function () { |
|||
this.wrapper = this.gjs.editor.get('DomComponents').getWrapper().get('components'); |
|||
this.$clm = instClassTagViewer(this); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete this.wrapper; |
|||
delete this.$clm; |
|||
}); |
|||
|
|||
it('Assign correctly new class to component', function() { |
|||
var model = this.wrapper.add({}); |
|||
model.get('classes').length.should.equal(0); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
model.get('classes').length.should.equal(1); |
|||
model.get('classes').at(0).get('name').should.equal('test'); |
|||
}); |
|||
|
|||
it('Classes from components are correctly imported inside main container', function() { |
|||
var model = this.wrapper.add([ |
|||
{ classes: ['test11', 'test12', 'test13'] }, |
|||
{ classes: ['test11', 'test22', 'test22'] }, |
|||
]); |
|||
this.gjs.editor.get('SelectorManager').getAll().length.should.equal(4); |
|||
}); |
|||
|
|||
it('Class imported into component is the same model from main container', function() { |
|||
var model = this.wrapper.add({ classes: ['test1'] }); |
|||
var clModel = model.get('classes').at(0); |
|||
var clModel2 = this.gjs.editor.get('SelectorManager').getAll().at(0); |
|||
clModel.should.deep.equal(clModel2); |
|||
}); |
|||
|
|||
it('Can assign only one time the same class on selected component and the class viewer', function() { |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.$clm.addNewTag('test'); |
|||
model.get('classes').length.should.equal(1); |
|||
model.get('classes').at(0).get('name').should.equal('test'); |
|||
this.$clm.collection.length.should.equal(1); |
|||
this.$clm.collection.at(0).get('name').should.equal('test'); |
|||
}); |
|||
|
|||
it('Removing from container removes also from selected component', function() { |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.$clm.getClasses().find('.tag #close').trigger('click') |
|||
model.get('classes').length.should.equal(0); |
|||
}); |
|||
|
|||
it("Trigger correctly event on target with new class add", function() { |
|||
var spy = sinon.spy(); |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.gjs.editor.on("targetClassAdded", spy); |
|||
this.$clm.addNewTag('test'); |
|||
spy.called.should.equal(false); |
|||
this.$clm.addNewTag('test2'); |
|||
spy.called.should.equal(true); |
|||
}); |
|||
|
|||
}); |
|||
const Selectors = require('selector_manager/model/Selectors'); |
|||
const ClassTagsView = require('selector_manager/view/ClassTagsView'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('E2E tests', () => { |
|||
|
|||
var instClassTagViewer = ctx => { |
|||
var $clm; |
|||
var clm = ctx.gjs.editor.get('SelectorManager'); |
|||
if(clm){ |
|||
$clm = new ClassTagsView({ |
|||
collection: new Selectors([]), |
|||
config: { |
|||
em: ctx.gjs.editor |
|||
}, |
|||
}).render(); |
|||
ctx.$fixture.append($clm.el); |
|||
} |
|||
return $clm; |
|||
}; |
|||
|
|||
before(function () { |
|||
this.$fixtures = $("#fixtures"); |
|||
this.$fixture = $('<div id="SelectorManager-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
this.gjs = grapesjs.init({ |
|||
stylePrefix: '', |
|||
storageManager: { autoload: 0, type:'none' }, |
|||
assetManager: { |
|||
storageType: 'none', |
|||
}, |
|||
container: '#SelectorManager-fixture', |
|||
}); |
|||
this.$fixture.empty().appendTo(this.$fixtures); |
|||
this.gjs.render(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete this.gjs; |
|||
}); |
|||
|
|||
after(function () { |
|||
this.$fixture.remove(); |
|||
}); |
|||
|
|||
describe('Interaction with Components', () => { |
|||
|
|||
beforeEach(function () { |
|||
this.wrapper = this.gjs.editor.get('DomComponents').getWrapper().get('components'); |
|||
this.$clm = instClassTagViewer(this); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete this.wrapper; |
|||
delete this.$clm; |
|||
}); |
|||
|
|||
it('Assign correctly new class to component', function() { |
|||
var model = this.wrapper.add({}); |
|||
expect(model.get('classes').length).toEqual(0); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
expect(model.get('classes').length).toEqual(1); |
|||
expect(model.get('classes').at(0).get('name')).toEqual('test'); |
|||
}); |
|||
|
|||
it('Classes from components are correctly imported inside main container', function() { |
|||
var model = this.wrapper.add([ |
|||
{ classes: ['test11', 'test12', 'test13'] }, |
|||
{ classes: ['test11', 'test22', 'test22'] }, |
|||
]); |
|||
expect(this.gjs.editor.get('SelectorManager').getAll().length).toEqual(4); |
|||
}); |
|||
|
|||
it('Class imported into component is the same model from main container', function() { |
|||
var model = this.wrapper.add({ classes: ['test1'] }); |
|||
var clModel = model.get('classes').at(0); |
|||
var clModel2 = this.gjs.editor.get('SelectorManager').getAll().at(0); |
|||
expect(clModel).toEqual(clModel2); |
|||
}); |
|||
|
|||
it('Can assign only one time the same class on selected component and the class viewer', function() { |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.$clm.addNewTag('test'); |
|||
expect(model.get('classes').length).toEqual(1); |
|||
expect(model.get('classes').at(0).get('name')).toEqual('test'); |
|||
expect(this.$clm.collection.length).toEqual(1); |
|||
expect(this.$clm.collection.at(0).get('name')).toEqual('test'); |
|||
}); |
|||
|
|||
it('Removing from container removes also from selected component', function() { |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.$clm.getClasses().find('.tag #close').trigger('click') |
|||
expect(model.get('classes').length).toEqual(0); |
|||
}); |
|||
|
|||
it("Trigger correctly event on target with new class add", function() { |
|||
var spy = sinon.spy(); |
|||
var model = this.wrapper.add({}); |
|||
this.gjs.editor.set('selectedComponent', model); |
|||
this.$clm.addNewTag('test'); |
|||
this.gjs.editor.on("targetClassAdded", spy); |
|||
this.$clm.addNewTag('test'); |
|||
expect(spy.called).toEqual(false); |
|||
this.$clm.addNewTag('test2'); |
|||
expect(spy.called).toEqual(true); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
@ -0,0 +1,82 @@ |
|||
var SelectorManager = require('selector_manager'); |
|||
var Models = require('./model/SelectorModels'); |
|||
var ClassTagView = require('./view/ClassTagView'); |
|||
var ClassTagsView = require('./view/ClassTagsView'); |
|||
var e2e = require('./e2e/ClassManager'); |
|||
|
|||
describe('SelectorManager', () => { |
|||
|
|||
describe('Main', () => { |
|||
|
|||
var obj; |
|||
|
|||
beforeEach(() => { |
|||
obj = new SelectorManager().init(); |
|||
}); |
|||
|
|||
afterEach(() => { |
|||
obj = null; |
|||
}); |
|||
|
|||
it('Object exists', () => { |
|||
expect(obj).toExist(); |
|||
}); |
|||
|
|||
it('No selectors inside', () => { |
|||
expect(obj.getAll().length).toEqual(0); |
|||
}); |
|||
|
|||
it('Able to add default selectors', () => { |
|||
var cm = new SelectorManager().init({ |
|||
selectors: ['test1', 'test2', 'test3'], |
|||
}); |
|||
expect(cm.getAll().length).toEqual(3); |
|||
}); |
|||
|
|||
it('Add new selector', () => { |
|||
obj.add('test'); |
|||
expect(obj.getAll().length).toEqual(1); |
|||
}); |
|||
|
|||
it('Default new selector is a class type', () => { |
|||
obj.add('test'); |
|||
expect(obj.get('test').get('type')).toEqual('class'); |
|||
}); |
|||
|
|||
it('Check name property', () => { |
|||
var name = 'test'; |
|||
var sel = obj.add(name); |
|||
expect(sel.get('name')).toEqual(name); |
|||
expect(sel.get('label')).toEqual(name); |
|||
}); |
|||
|
|||
it('Add 2 selectors', () => { |
|||
obj.add('test'); |
|||
obj.add('test2'); |
|||
expect(obj.getAll().length).toEqual(2); |
|||
}); |
|||
|
|||
it('Adding 2 selectors with the same name is not possible', () => { |
|||
obj.add('test'); |
|||
obj.add('test'); |
|||
expect(obj.getAll().length).toEqual(1); |
|||
}); |
|||
|
|||
it('Get selector', () => { |
|||
var name = 'test'; |
|||
var sel = obj.add(name); |
|||
expect(obj.get(name)).toEqual(sel); |
|||
}); |
|||
|
|||
it('Get empty class', () => { |
|||
expect(obj.get('test')).toEqual(undefined); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
Models.run(); |
|||
ClassTagView.run(); |
|||
ClassTagsView.run(); |
|||
e2e.run(); |
|||
|
|||
}); |
|||
@ -1,82 +0,0 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var SelectorManager = require('SelectorManager'); |
|||
var e2e = require('undefined'); |
|||
|
|||
describe('SelectorManager', function() { |
|||
|
|||
describe('Main', function() { |
|||
|
|||
var obj; |
|||
|
|||
beforeEach(function () { |
|||
obj = new SelectorManager().init(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj; |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
obj.should.be.exist; |
|||
}); |
|||
|
|||
it('No selectors inside', function() { |
|||
obj.getAll().length.should.equal(0); |
|||
}); |
|||
|
|||
it('Able to add default selectors', function() { |
|||
var cm = new SelectorManager().init({ |
|||
selectors: ['test1', 'test2', 'test3'], |
|||
}); |
|||
cm.getAll().length.should.equal(3); |
|||
}); |
|||
|
|||
it('Add new selector', function() { |
|||
obj.add('test'); |
|||
obj.getAll().length.should.equal(1); |
|||
}); |
|||
|
|||
it('Default new selector is a class type', function() { |
|||
obj.add('test'); |
|||
obj.get('test').get('type').should.equal('class'); |
|||
}); |
|||
|
|||
it('Check name property', function() { |
|||
var name = 'test'; |
|||
var sel = obj.add(name); |
|||
sel.get('name').should.equal(name); |
|||
sel.get('label').should.equal(name); |
|||
}); |
|||
|
|||
it('Add 2 selectors', function() { |
|||
obj.add('test'); |
|||
obj.add('test2'); |
|||
obj.getAll().length.should.equal(2); |
|||
}); |
|||
|
|||
it('Adding 2 selectors with the same name is not possible', function() { |
|||
obj.add('test'); |
|||
obj.add('test'); |
|||
obj.getAll().length.should.equal(1); |
|||
}); |
|||
|
|||
it('Get selector', function() { |
|||
var name = 'test'; |
|||
var sel = obj.add(name); |
|||
obj.get(name).should.deep.equal(sel); |
|||
}); |
|||
|
|||
it('Get empty class', function() { |
|||
(obj.get('test') === undefined).should.equal(true); |
|||
}); |
|||
|
|||
}); |
|||
|
|||
Models.run(); |
|||
ClassTagView.run(); |
|||
ClassTagsView.run(); |
|||
e2e.run(); |
|||
|
|||
}); |
|||
}); |
|||
@ -1,52 +1,50 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var Selectors = require('undefined'); |
|||
const Selector = require('selector_manager/model/Selector'); |
|||
const Selectors = require('selector_manager/model/Selectors'); |
|||
|
|||
module.exports = { |
|||
run : function(){ |
|||
describe('Selector', function() { |
|||
module.exports = { |
|||
run() { |
|||
describe('Selector', () => { |
|||
var obj; |
|||
|
|||
beforeEach(function () { |
|||
this.obj = new Selector(); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete this.obj; |
|||
}); |
|||
|
|||
it('Has name property', function() { |
|||
this.obj.has('name').should.equal(true); |
|||
}); |
|||
beforeEach(() => { |
|||
obj = new Selector(); |
|||
}); |
|||
|
|||
it('Has label property', function() { |
|||
this.obj.has('label').should.equal(true); |
|||
}); |
|||
afterEach(() => { |
|||
obj = null; |
|||
}); |
|||
|
|||
it('Has active property', function() { |
|||
this.obj.has('active').should.equal(true); |
|||
}); |
|||
it('Has name property', () => { |
|||
expect(obj.has('name')).toEqual(true); |
|||
}); |
|||
|
|||
it('escapeName test', function() { |
|||
this.obj.escapeName('@Te sT*').should.equal('-Te-sT-'); |
|||
}); |
|||
it('Has label property', () => { |
|||
expect(obj.has('label')).toEqual(true); |
|||
}); |
|||
|
|||
it('Name is corrected at instantiation', function() { |
|||
this.obj = new Selector({ name: '@Te sT*'}); |
|||
this.obj.get('name').should.equal('-Te-sT-'); |
|||
}); |
|||
it('Has active property', () => { |
|||
expect(obj.has('active')).toEqual(true); |
|||
}); |
|||
|
|||
it('escapeName test', () => { |
|||
expect(obj.escapeName('@Te sT*')).toEqual('-Te-sT-'); |
|||
}); |
|||
|
|||
it('Name is corrected at instantiation', () => { |
|||
obj = new Selector({ name: '@Te sT*'}); |
|||
expect(obj.get('name')).toEqual('-Te-sT-'); |
|||
}); |
|||
describe('Selectors', function() { |
|||
|
|||
it('Creates collection item correctly', function() { |
|||
var c = new Selectors(); |
|||
var m = c.add({}); |
|||
m.should.be.an.instanceOf(Selector); |
|||
}); |
|||
|
|||
}); |
|||
describe('Selectors', () => { |
|||
|
|||
it('Creates collection item correctly', () => { |
|||
var c = new Selectors(); |
|||
var m = c.add({}); |
|||
expect(m instanceof Selector).toEqual(true); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
@ -1,133 +1,129 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var ClassTagView = require('undefined'); |
|||
var Selectors = require('SelectorManager/model/Selectors'); |
|||
|
|||
module.exports = { |
|||
run : function(){ |
|||
describe('ClassTagView', function() { |
|||
|
|||
var obj; |
|||
var fixture; |
|||
var fixtures; |
|||
var testLabel; |
|||
var coll; |
|||
|
|||
before(function () { |
|||
fixtures = $("#fixtures"); |
|||
fixture = $('<div class="classtag-fixture"></div>'); |
|||
}); |
|||
const ClassTagView = require('selector_manager/view/ClassTagView'); |
|||
const Selectors = require('selector_manager/model/Selectors'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('ClassTagView', () => { |
|||
|
|||
var obj; |
|||
var fixture; |
|||
var fixtures; |
|||
var testLabel; |
|||
var coll; |
|||
|
|||
before(() => { |
|||
fixtures = $("#fixtures"); |
|||
fixture = $('<div class="classtag-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
coll = new Selectors(); |
|||
testLabel = 'TestLabel'; |
|||
var model = coll.add({ |
|||
name: 'test', |
|||
label: testLabel, |
|||
}); |
|||
obj = new ClassTagView({ |
|||
config : {}, |
|||
model: model, |
|||
coll: coll |
|||
}); |
|||
obj.target = { get:function(){} }; |
|||
_.extend(obj.target, Backbone.Events); |
|||
fixture.empty().appendTo(fixtures); |
|||
fixture.html(obj.render().el); |
|||
}); |
|||
beforeEach(() => { |
|||
coll = new Selectors(); |
|||
testLabel = 'TestLabel'; |
|||
var model = coll.add({ |
|||
name: 'test', |
|||
label: testLabel, |
|||
}); |
|||
obj = new ClassTagView({ |
|||
config : {}, |
|||
model, |
|||
coll |
|||
}); |
|||
obj.target = { get() {} }; |
|||
_.extend(obj.target, Backbone.Events); |
|||
fixture.empty().appendTo(fixtures); |
|||
fixture.html(obj.render().el); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete obj.model; |
|||
}); |
|||
afterEach(() => { |
|||
obj.model = null; |
|||
}); |
|||
|
|||
after(function () { |
|||
fixture.remove(); |
|||
}); |
|||
after(() => { |
|||
fixture.remove(); |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
ClassTagView.should.be.exist; |
|||
}); |
|||
it('Object exists', () => { |
|||
expect(ClassTagView).toExist(); |
|||
}); |
|||
|
|||
it('Not empty', () => { |
|||
var $el = obj.$el; |
|||
expect($el.html()).toExist(); |
|||
}); |
|||
|
|||
it('Not empty', () => { |
|||
var $el = obj.$el; |
|||
expect($el.html()).toContain(testLabel); |
|||
}); |
|||
|
|||
describe('Should be rendered correctly', () => { |
|||
|
|||
it('Not empty', function() { |
|||
it('Has close button', () => { |
|||
var $el = obj.$el; |
|||
$el.html().should.not.be.empty; |
|||
expect($el.find('#close')[0]).toExist(); |
|||
}); |
|||
|
|||
it('Not empty', function() { |
|||
it('Has checkbox', () => { |
|||
var $el = obj.$el; |
|||
$el.html().should.contain(testLabel); |
|||
expect($el.find('#checkbox')[0]).toExist(); |
|||
}); |
|||
|
|||
describe('Should be rendered correctly', function() { |
|||
|
|||
it('Has close button', function() { |
|||
var $el = obj.$el; |
|||
$el.find('#close').should.have.property(0); |
|||
}); |
|||
it('Has checkbox', function() { |
|||
var $el = obj.$el; |
|||
$el.find('#checkbox').should.have.property(0); |
|||
}); |
|||
it('Has label', function() { |
|||
var $el = obj.$el; |
|||
$el.find('#tag-label').should.have.property(0); |
|||
}); |
|||
|
|||
it('Has label', () => { |
|||
var $el = obj.$el; |
|||
expect($el.find('#tag-label')[0]).toExist(); |
|||
}); |
|||
|
|||
it('Could be removed', function() { |
|||
var spy = sinon.spy(); |
|||
obj.config.target = { get:function(){} }; |
|||
sinon.stub(obj.config.target, 'get').returns(0); |
|||
obj.$el.find('#close').trigger('click'); |
|||
fixture.html().should.be.empty; |
|||
}); |
|||
}); |
|||
|
|||
it('On remove triggers event', function() { |
|||
var spy = sinon.spy(); |
|||
sinon.stub(obj.target, 'get').returns(0); |
|||
obj.target.on("targetClassRemoved", spy); |
|||
obj.$el.find('#close').trigger('click'); |
|||
spy.called.should.equal(true); |
|||
}); |
|||
it('Could be removed', () => { |
|||
var spy = sinon.spy(); |
|||
obj.config.target = { get() {} }; |
|||
sinon.stub(obj.config.target, 'get').returns(0); |
|||
obj.$el.find('#close').trigger('click'); |
|||
expect(fixture.html()).toNotExist(); |
|||
}); |
|||
|
|||
it('Checkbox toggles status', function() { |
|||
var spy = sinon.spy(); |
|||
obj.model.on("change:active", spy); |
|||
obj.model.set('active', true); |
|||
obj.$el.find('#checkbox').trigger('click'); |
|||
obj.model.get('active').should.equal(false); |
|||
spy.called.should.equal(true); |
|||
}); |
|||
it('On remove triggers event', () => { |
|||
var spy = sinon.spy(); |
|||
sinon.stub(obj.target, 'get').returns(0); |
|||
obj.target.on("targetClassRemoved", spy); |
|||
obj.$el.find('#close').trigger('click'); |
|||
expect(spy.called).toEqual(true); |
|||
}); |
|||
|
|||
it('On toggle triggers event', function() { |
|||
var spy = sinon.spy(); |
|||
sinon.stub(obj.target, 'get').returns(0); |
|||
obj.target.on("targetClassUpdated", spy); |
|||
obj.$el.find('#checkbox').trigger('click'); |
|||
spy.called.should.equal(true); |
|||
}); |
|||
it('Checkbox toggles status', () => { |
|||
var spy = sinon.spy(); |
|||
obj.model.on("change:active", spy); |
|||
obj.model.set('active', true); |
|||
obj.$el.find('#checkbox').trigger('click'); |
|||
expect(obj.model.get('active')).toEqual(false); |
|||
expect(spy.called).toEqual(true); |
|||
}); |
|||
|
|||
it('Label input is disabled', function() { |
|||
var inputProp = obj.inputProp; |
|||
obj.$labelInput.prop(inputProp).should.equal(true); |
|||
}); |
|||
it('On toggle triggers event', () => { |
|||
var spy = sinon.spy(); |
|||
sinon.stub(obj.target, 'get').returns(0); |
|||
obj.target.on("targetClassUpdated", spy); |
|||
obj.$el.find('#checkbox').trigger('click'); |
|||
expect(spy.called).toEqual(true); |
|||
}); |
|||
|
|||
it('On double click label input is enable', function() { |
|||
var inputProp = obj.inputProp; |
|||
obj.$el.find('#tag-label').trigger('dblclick'); |
|||
obj.$labelInput.prop(inputProp).should.equal(false); |
|||
}); |
|||
it('Label input is disabled', () => { |
|||
var inputProp = obj.inputProp; |
|||
expect(obj.$labelInput.prop(inputProp)).toEqual(true); |
|||
}); |
|||
|
|||
it('On blur label input turns back disabled', function() { |
|||
var inputProp = obj.inputProp; |
|||
obj.$el.find('#tag-label').trigger('dblclick'); |
|||
obj.endEditTag(); |
|||
obj.$labelInput.prop(inputProp).should.equal(true); |
|||
}); |
|||
it('On double click label input is enable', () => { |
|||
var inputProp = obj.inputProp; |
|||
obj.$el.find('#tag-label').trigger('dblclick'); |
|||
expect(obj.$labelInput.prop(inputProp)).toEqual(false); |
|||
}); |
|||
|
|||
it('On blur label input turns back disabled', () => { |
|||
var inputProp = obj.inputProp; |
|||
obj.$el.find('#tag-label').trigger('dblclick'); |
|||
obj.endEditTag(); |
|||
expect(obj.$labelInput.prop(inputProp)).toEqual(true); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
@ -1,196 +1,195 @@ |
|||
define(function(require, exports, module){ |
|||
'use strict'; |
|||
var ClassTagsView = require('undefined'); |
|||
var Selectors = require('SelectorManager/model/Selectors'); |
|||
|
|||
module.exports = { |
|||
run : function(){ |
|||
describe('ClassTagsView', function() { |
|||
|
|||
var view; |
|||
var fixture; |
|||
var fixtures; |
|||
var testLabel; |
|||
var coll; |
|||
var target; |
|||
|
|||
before(function () { |
|||
fixtures = $("#fixtures"); |
|||
fixture = $('<div class="classtag-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
target = { get: function(){} }; |
|||
coll = new Selectors(); |
|||
_.extend(target, Backbone.Events); |
|||
|
|||
view = new ClassTagsView({ |
|||
config : { em: target }, |
|||
collection: coll |
|||
}); |
|||
|
|||
this.targetStub = { |
|||
add: function(v){ return {name: v}; } |
|||
}; |
|||
|
|||
this.compTargetStub = { |
|||
get: function(){ return { add: function(){} }} |
|||
}; |
|||
|
|||
fixture.empty().appendTo(fixtures); |
|||
fixture.html(view.render().el); |
|||
this.btnAdd = view.$el.find('#' + view.addBtnId); |
|||
this.input = view.$el.find('input#' + view.newInputId); |
|||
this.$tags = fixture.find('#tags-c'); |
|||
this.$states = fixture.find('#states'); |
|||
this.$statesC = fixture.find('#input-c'); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
delete view.collection; |
|||
}); |
|||
|
|||
after(function () { |
|||
fixture.remove(); |
|||
}); |
|||
|
|||
it('Object exists', function() { |
|||
ClassTagsView.should.be.exist; |
|||
}); |
|||
|
|||
it('Not tags inside', function() { |
|||
this.$tags.html().should.equal(''); |
|||
}); |
|||
|
|||
it('Add new tag triggers correct method', function() { |
|||
sinon.stub(view, "addToClasses"); |
|||
coll.add({ name: 'test' }); |
|||
view.addToClasses.calledOnce.should.equal(true); |
|||
}); |
|||
|
|||
it('Start new tag creation', function() { |
|||
this.btnAdd.click(); |
|||
(this.btnAdd.css('display') == 'none').should.equal(true); |
|||
(this.input.css('display') !== 'none').should.equal(true); |
|||
}); |
|||
|
|||
it('Stop tag creation', function() { |
|||
this.btnAdd.click(); |
|||
this.input.val('test') |
|||
this.input.blur(); |
|||
(this.btnAdd.css('display') !== 'none').should.equal(true); |
|||
(this.input.css('display') == 'none').should.equal(true); |
|||
this.input.val().should.equal(''); |
|||
}); |
|||
|
|||
it('Check keyup of ESC on input', function() { |
|||
this.btnAdd.click(); |
|||
sinon.stub(view, "addNewTag"); |
|||
this.input.trigger({ |
|||
type: 'keyup', |
|||
keyCode: 13 |
|||
}); |
|||
view.addNewTag.calledOnce.should.equal(true); |
|||
}); |
|||
|
|||
it('Check keyup on ENTER on input', function() { |
|||
this.btnAdd.click(); |
|||
sinon.stub(view, "endNewTag"); |
|||
this.input.trigger({ |
|||
type: 'keyup', |
|||
keyCode: 27 |
|||
}); |
|||
view.endNewTag.calledOnce.should.equal(true); |
|||
}); |
|||
|
|||
it('Collection changes on update of target', function() { |
|||
coll.add({ name: 'test' }); |
|||
target.trigger('change:selectedComponent'); |
|||
coll.length.should.equal(0); |
|||
}); |
|||
|
|||
it('Collection reacts on reset', function() { |
|||
coll.add([{ name: 'test1' }, { name: 'test2' }]); |
|||
sinon.stub(view, "addToClasses"); |
|||
coll.trigger('reset'); |
|||
view.addToClasses.calledTwice.should.equal(true); |
|||
}); |
|||
|
|||
it("Don't accept empty tags", function() { |
|||
view.addNewTag(''); |
|||
this.$tags.html().should.equal(''); |
|||
}); |
|||
|
|||
it("Accept new tags", function() { |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test2'); |
|||
this.$tags.children().length.should.equal(2); |
|||
}); |
|||
|
|||
it("New tag correctly added", function() { |
|||
coll.add({ label: 'test' }); |
|||
this.$tags.children().first().find('#tag-label input').val().should.equal('test'); |
|||
}); |
|||
|
|||
it("States are hidden in case no tags", function() { |
|||
view.updateStateVis(); |
|||
this.$statesC.css('display').should.equal('none'); |
|||
}); |
|||
|
|||
it("States are visible in case of more tags inside", function() { |
|||
coll.add({ label: 'test' }); |
|||
view.updateStateVis(); |
|||
this.$statesC.css('display').should.equal('block'); |
|||
}); |
|||
|
|||
it("Update state visibility on new tag", function() { |
|||
sinon.stub(view, "updateStateVis"); |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
view.updateStateVis.called.should.equal(true); |
|||
}); |
|||
|
|||
it("Update state visibility on removing of the tag", function() { |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
sinon.stub(view, "updateStateVis"); |
|||
coll.remove(coll.at(0)); |
|||
view.updateStateVis.calledOnce.should.equal(true); |
|||
}); |
|||
|
|||
it("Output correctly state options", function() { |
|||
var view = new ClassTagsView({ |
|||
config : { |
|||
em: target, |
|||
states: [ { name: 'testName', label: 'testLabel' } ], |
|||
}, |
|||
collection: coll |
|||
}); |
|||
view.getStateOptions().should.equal('<option value="testName">testLabel</option>'); |
|||
}); |
|||
|
|||
describe('Should be rendered correctly', function() { |
|||
it('Has label', function() { |
|||
view.$el.find('#label').should.have.property(0); |
|||
}); |
|||
it('Has tags container', function() { |
|||
view.$el.find('#tags-c').should.have.property(0); |
|||
}); |
|||
it('Has add button', function() { |
|||
view.$el.find('#add-tag').should.have.property(0); |
|||
}); |
|||
it('Has states input', function() { |
|||
view.$el.find('#states').should.have.property(0); |
|||
}); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
const ClassTagsView = require('selector_manager/view/ClassTagsView'); |
|||
const Selectors = require('selector_manager/model/Selectors'); |
|||
|
|||
module.exports = { |
|||
run() { |
|||
describe('ClassTagsView', () => { |
|||
|
|||
var view; |
|||
var fixture; |
|||
var fixtures; |
|||
var testLabel; |
|||
var coll; |
|||
var target; |
|||
|
|||
before(() => { |
|||
fixtures = $("#fixtures"); |
|||
fixture = $('<div class="classtag-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
target = { get() {} }; |
|||
coll = new Selectors(); |
|||
_.extend(target, Backbone.Events); |
|||
|
|||
view = new ClassTagsView({ |
|||
config : { em: target }, |
|||
collection: coll |
|||
}); |
|||
|
|||
this.targetStub = { |
|||
add(v) { return {name: v}; } |
|||
}; |
|||
|
|||
this.compTargetStub = { |
|||
get() { return { add() {} };} |
|||
}; |
|||
|
|||
fixture.empty().appendTo(fixtures); |
|||
fixture.html(view.render().el); |
|||
this.btnAdd = view.$el.find('#' + view.addBtnId); |
|||
this.input = view.$el.find('input#' + view.newInputId); |
|||
this.$tags = fixture.find('#tags-c'); |
|||
this.$states = fixture.find('#states'); |
|||
this.$statesC = fixture.find('#input-c'); |
|||
}); |
|||
|
|||
afterEach(() => { |
|||
delete view.collection; |
|||
}); |
|||
|
|||
after(() => { |
|||
fixture.remove(); |
|||
}); |
|||
|
|||
it('Object exists', () => { |
|||
expect(ClassTagsView).toExist(); |
|||
}); |
|||
|
|||
it('Not tags inside', function() { |
|||
expect(this.$tags.html()).toEqual(''); |
|||
}); |
|||
|
|||
it('Add new tag triggers correct method', () => { |
|||
sinon.stub(view, "addToClasses"); |
|||
coll.add({ name: 'test' }); |
|||
expect(view.addToClasses.calledOnce).toEqual(true); |
|||
}); |
|||
|
|||
it('Start new tag creation', function() { |
|||
this.btnAdd.click(); |
|||
expect(this.btnAdd.css('display')).toEqual('none'); |
|||
expect(this.input.css('display')).toNotEqual('none'); |
|||
}); |
|||
|
|||
it.skip('Stop tag creation', function() { |
|||
this.btnAdd.click(); |
|||
this.input.val('test') |
|||
this.input.blur(); |
|||
//(this.btnAdd.css('display') !== 'none').should.equal(true);
|
|||
//(this.input.css('display') == 'none').should.equal(true);
|
|||
//this.input.val().should.equal('');
|
|||
expect(this.btnAdd.css('display')).toNotEqual('none'); |
|||
expect(this.input.css('display')).toEqual('none'); |
|||
expect(this.input.val()).toEqual(''); |
|||
}); |
|||
|
|||
it('Check keyup of ESC on input', function() { |
|||
this.btnAdd.click(); |
|||
sinon.stub(view, "addNewTag"); |
|||
this.input.trigger({ |
|||
type: 'keyup', |
|||
keyCode: 13 |
|||
}); |
|||
expect(view.addNewTag.calledOnce).toEqual(true); |
|||
}); |
|||
|
|||
it('Check keyup on ENTER on input', function() { |
|||
this.btnAdd.click(); |
|||
sinon.stub(view, "endNewTag"); |
|||
this.input.trigger({ |
|||
type: 'keyup', |
|||
keyCode: 27 |
|||
}); |
|||
expect(view.endNewTag.calledOnce).toEqual(true); |
|||
}); |
|||
|
|||
it('Collection changes on update of target', () => { |
|||
coll.add({ name: 'test' }); |
|||
target.trigger('change:selectedComponent'); |
|||
expect(coll.length).toEqual(0); |
|||
}); |
|||
|
|||
it('Collection reacts on reset', () => { |
|||
coll.add([{ name: 'test1' }, { name: 'test2' }]); |
|||
sinon.stub(view, "addToClasses"); |
|||
coll.trigger('reset'); |
|||
expect(view.addToClasses.calledTwice).toEqual(true); |
|||
}); |
|||
|
|||
it("Don't accept empty tags", function() { |
|||
view.addNewTag(''); |
|||
expect(this.$tags.html()).toEqual(''); |
|||
}); |
|||
|
|||
it("Accept new tags", function() { |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test2'); |
|||
expect(this.$tags.children().length).toEqual(2); |
|||
}); |
|||
|
|||
it("New tag correctly added", function() { |
|||
coll.add({ label: 'test' }); |
|||
expect(this.$tags.children().first().find('#tag-label input').val()).toEqual('test'); |
|||
}); |
|||
|
|||
it("States are hidden in case no tags", function() { |
|||
view.updateStateVis(); |
|||
expect(this.$statesC.css('display')).toEqual('none'); |
|||
}); |
|||
|
|||
it("States are visible in case of more tags inside", function() { |
|||
coll.add({ label: 'test' }); |
|||
view.updateStateVis(); |
|||
expect(this.$statesC.css('display')).toEqual('block'); |
|||
}); |
|||
|
|||
it("Update state visibility on new tag", function() { |
|||
sinon.stub(view, "updateStateVis"); |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
expect(view.updateStateVis.called).toEqual(true); |
|||
}); |
|||
|
|||
it("Update state visibility on removing of the tag", function() { |
|||
sinon.stub(target, "get").returns(this.targetStub); |
|||
view.compTarget = this.compTargetStub; |
|||
view.addNewTag('test'); |
|||
sinon.stub(view, "updateStateVis"); |
|||
coll.remove(coll.at(0)); |
|||
expect(view.updateStateVis.calledOnce).toEqual(true); |
|||
}); |
|||
|
|||
it("Output correctly state options", () => { |
|||
var view = new ClassTagsView({ |
|||
config : { |
|||
em: target, |
|||
states: [ { name: 'testName', label: 'testLabel' } ], |
|||
}, |
|||
collection: coll |
|||
}); |
|||
expect(view.getStateOptions()).toEqual('<option value="testName">testLabel</option>'); |
|||
}); |
|||
|
|||
describe('Should be rendered correctly', () => { |
|||
it('Has label', () => { |
|||
expect(view.$el.find('#label')[0]).toExist(); |
|||
}); |
|||
it('Has tags container', () => { |
|||
expect(view.$el.find('#tags-c')[0]).toExist(); |
|||
}); |
|||
it('Has add button', () => { |
|||
expect(view.$el.find('#add-tag')[0]).toExist(); |
|||
}); |
|||
it('Has states input', () => { |
|||
expect(view.$el.find('#states')[0]).toExist(); |
|||
}); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
Loading…
Reference in new issue