diff --git a/test/runner/main.js b/test/runner/main.js index 289a0d01a..808fe74f7 100644 --- a/test/runner/main.js +++ b/test/runner/main.js @@ -5,6 +5,9 @@ require(['../src/config/require-config.js', 'config/config.js'], function() { 'specs/main.js', 'specs/asset_manager/main.js', 'specs/asset_manager/model/Asset.js', + 'specs/asset_manager/model/AssetImage.js', + 'specs/asset_manager/model/Assets.js', + 'specs/asset_manager/view/AssetsView.js', ], function(chai) { var should = chai.should(), diff --git a/test/specs/asset_manager/model/AssetImage.js b/test/specs/asset_manager/model/AssetImage.js new file mode 100644 index 000000000..4dfaaeed6 --- /dev/null +++ b/test/specs/asset_manager/model/AssetImage.js @@ -0,0 +1,24 @@ +define(['AssetManager/model/AssetImage'], + function(AssetImage) { + + describe('Asset Manager', function() { + + describe('AssetImage', function() { + it('Object exists', function() { + AssetImage.should.be.exist; + }); + + it('Has default values', function() { + var obj = new AssetImage({}); + obj.get('type').should.equal("image"); + obj.get('src').should.equal(""); + obj.get('unitDim').should.equal("px"); + obj.get('height').should.equal(0); + obj.get('width').should.equal(0); + obj.getExtension().should.be.empty; + obj.getFilename().should.be.empty; + }); + + }); + }); +}); \ No newline at end of file diff --git a/test/specs/asset_manager/model/Assets.js b/test/specs/asset_manager/model/Assets.js new file mode 100644 index 000000000..ff3977c5c --- /dev/null +++ b/test/specs/asset_manager/model/Assets.js @@ -0,0 +1,13 @@ +define(['AssetManager/model/Assets'], + function(Assets) { + + describe('Asset Manager', function() { + + describe('Assets', function() { + it('Object exists', function() { + Assets.should.be.exist; + }); + + }); + }); +}); \ No newline at end of file diff --git a/test/specs/asset_manager/view/AssetsView.js b/test/specs/asset_manager/view/AssetsView.js new file mode 100644 index 000000000..b3e336cb6 --- /dev/null +++ b/test/specs/asset_manager/view/AssetsView.js @@ -0,0 +1,91 @@ +define(['AssetManager/view/AssetsView', 'AssetManager/model/Assets'], + function(AssetsView, Assets) { + + describe('Asset Manager', function() { + + describe('AssetsView', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $('
'); + }); + + beforeEach(function () { + this.coll = new Assets([]); + this.view = new AssetsView({ + config : {}, + collection: this.coll + }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.collection.reset(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + AssetsView.should.be.exist; + }); + + it("Collection is empty", function (){ + this.view.$el.html().should.be.empty; + }); + + it("Add new asset", function (){ + sinon.stub(this.view, "addAsset"); + this.coll.add({}); + this.view.addAsset.calledOnce.should.equal(true); + }); + + it("Render new asset", function (){ + this.coll.add({}); + this.view.$el.html().should.not.be.empty; + }); + + it("Render correctly new asset", function (){ + this.coll.add({}); + var $asset = this.view.$el.children().first(); + $asset.prop("tagName").should.equal('DIV'); + $asset.html().should.be.empty; + }); + + it("Render correctly new image asset", function (){ + this.coll.add({ type: 'image'}); + var $asset = this.view.$el.children().first(); + $asset.prop("tagName").should.equal('DIV'); + $asset.html().should.not.be.empty; + }); + + it("Clean collection from asset", function (){ + var model = this.coll.add({}); + this.coll.remove(model); + this.view.$el.html().should.be.empty; + }); + + it("Load no assets", function (){ + (this.view.load() === null).should.be.true; + }); + + it("Load assets", function (){ + var obj = { test: '1' }; + this.view.storagePrv = { load : function(){} }; + sinon.stub(this.view.storagePrv, "load").returns(obj); + this.view.load().should.equal(obj); + }); + + it("Deselect works", function (){ + this.coll.add([{},{}]); + var $asset = this.view.$el.children().first(); + $asset.attr('class', this.view.pfx + 'highlight'); + this.coll.trigger('deselectAll'); + $asset.attr('class').should.be.empty; + }); + + }); + }); +}); \ No newline at end of file