mirror of https://github.com/artf/grapesjs.git
4 changed files with 139 additions and 19 deletions
@ -0,0 +1,59 @@ |
|||
var path = 'DomComponents/view/'; |
|||
define([path + 'ComponentTextView', 'DomComponents/model/Component'], |
|||
function(ComponentTextView, Component) { |
|||
|
|||
return { |
|||
run : function(){ |
|||
|
|||
describe('ComponentTextView', function() { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
var hClass = 'hc-state'; |
|||
|
|||
before(function () { |
|||
$fixtures = $("#fixtures"); |
|||
$fixture = $('<div class="components-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
model = new Component(); |
|||
view = new ComponentTextView({ |
|||
model: model |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
view.remove(); |
|||
}); |
|||
|
|||
after(function () { |
|||
$fixture.remove(); |
|||
}); |
|||
|
|||
it('Component empty', function() { |
|||
$fixture.html().should.equal('<div></div>'); |
|||
}); |
|||
|
|||
it('Input content is stored in model', function() { |
|||
view.enableEditing(); |
|||
view.el.innerHTML = 'test'; |
|||
view.disableEditing(); |
|||
model.get('content').should.equal('test'); |
|||
}); |
|||
|
|||
it('Init with content', function() { |
|||
model = new Component({ content: 'test' }); |
|||
view = new ComponentTextView({ model: model }); |
|||
view.render().el.innerHTML.should.equal('test'); |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
@ -0,0 +1,55 @@ |
|||
var path = 'DomComponents/view/'; |
|||
define([path + 'ComponentsView', 'DomComponents/model/Components'], |
|||
function(ComponentsView, Components) { |
|||
|
|||
return { |
|||
run : function(){ |
|||
describe('ComponentsView', function() { |
|||
|
|||
var $fixtures; |
|||
var $fixture; |
|||
var model; |
|||
var view; |
|||
|
|||
before(function () { |
|||
$fixtures = $("#fixtures"); |
|||
$fixture = $('<div class="components-fixture"></div>'); |
|||
}); |
|||
|
|||
beforeEach(function () { |
|||
model = new Components([]); |
|||
view = new ComponentsView({ |
|||
collection: model |
|||
}); |
|||
$fixture.empty().appendTo($fixtures); |
|||
$fixture.html(view.render().el); |
|||
}); |
|||
|
|||
afterEach(function () { |
|||
view.collection.reset(); |
|||
}); |
|||
|
|||
after(function () { |
|||
$fixture.remove(); |
|||
}); |
|||
|
|||
it("Collection is empty", function (){ |
|||
view.$el.html().should.be.empty; |
|||
}); |
|||
|
|||
it("Add new component", function (){ |
|||
sinon.stub(view, "addToCollection"); |
|||
view.collection.add({}); |
|||
view.addToCollection.calledOnce.should.equal(true); |
|||
}); |
|||
|
|||
it("Render new component", function (){ |
|||
view.collection.add({}); |
|||
view.$el.html().should.not.be.empty; |
|||
}); |
|||
|
|||
}); |
|||
} |
|||
}; |
|||
|
|||
}); |
|||
Loading…
Reference in new issue