diff --git a/src/asset_manager/view/AssetView.js b/src/asset_manager/view/AssetView.js index 1658a0d31..8bb17c629 100644 --- a/src/asset_manager/view/AssetView.js +++ b/src/asset_manager/view/AssetView.js @@ -1,17 +1,17 @@ -define(['backbone'], +define(['backbone'], function (Backbone) { - /** + /** * @class AssetView * */ return Backbone.View.extend({ - + initialize: function(o) { - this.options = o; - this.config = o.config || {}; - this.pfx = this.config.stylePrefix; + this.options = o; + this.config = o.config || {}; + this.pfx = this.config.stylePrefix || ''; this.className = this.pfx + 'asset'; this.listenTo( this.model, 'destroy remove', this.remove ); }, - + }); }); diff --git a/src/asset_manager/view/FileUploader.js b/src/asset_manager/view/FileUploader.js index d0d3a1c31..8d7821e4e 100644 --- a/src/asset_manager/view/FileUploader.js +++ b/src/asset_manager/view/FileUploader.js @@ -13,7 +13,7 @@ define(['backbone', 'text!./../template/fileUploader.html'], initialize: function(o) { this.options = o || {}; this.config = o.config || {}; - this.pfx = this.config.stylePrefix; + this.pfx = this.config.stylePrefix || ''; this.target = this.collection || {}; this.uploadId = this.pfx + 'uploadFile'; this.disabled = this.config.disableUpload; diff --git a/test/runner/main.js b/test/runner/main.js index 808fe74f7..a5f261438 100644 --- a/test/runner/main.js +++ b/test/runner/main.js @@ -8,6 +8,9 @@ require(['../src/config/require-config.js', 'config/config.js'], function() { 'specs/asset_manager/model/AssetImage.js', 'specs/asset_manager/model/Assets.js', 'specs/asset_manager/view/AssetsView.js', + 'specs/asset_manager/view/AssetView.js', + 'specs/asset_manager/view/AssetImageView.js', + 'specs/asset_manager/view/FileUploader.js', ], function(chai) { var should = chai.should(), diff --git a/test/specs/asset_manager/view/AssetImageView.js b/test/specs/asset_manager/view/AssetImageView.js new file mode 100644 index 000000000..dc28fd5b3 --- /dev/null +++ b/test/specs/asset_manager/view/AssetImageView.js @@ -0,0 +1,77 @@ +define(['AssetManager/view/AssetImageView', 'AssetManager/model/AssetImage', 'AssetManager/model/Assets'], + function(AssetImageView, AssetImage, Assets) { + + describe('Asset Manager', function() { + + describe('AssetImageView', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $('
'); + }); + + beforeEach(function () { + var coll = new Assets(); + var model = coll.add({ type:'image', src: '/test' }); + this.view = new AssetImageView({ + config : {}, + model: model + }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.model.destroy(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + AssetImageView.should.be.exist; + }); + + describe('Asset should be rendered correctly', function() { + + it('Has preview box', function() { + var $asset = this.view.$el; + $asset.find('#preview').should.have.property(0); + }); + + it('Has meta box', function() { + var $asset = this.view.$el; + $asset.find('#meta').should.have.property(0); + }); + + it('Has close button', function() { + var $asset = this.view.$el; + $asset.find('#close').should.have.property(0); + }); + + }); + + it('Could be selected', function() { + sinon.stub(this.view, 'updateTarget'); + this.view.$el.trigger('click'); + this.view.$el.attr('class').should.contain('highlight'); + this.view.updateTarget.calledOnce.should.equal(true); + }); + + it('Could be chosen', function() { + sinon.stub(this.view, 'updateTarget'); + this.view.$el.trigger('dblclick'); + this.view.updateTarget.calledOnce.should.equal(true); + }); + + it('Could be removed', function() { + var spy = sinon.spy(); + this.view.model.on("remove", spy); + this.view.$el.find('#close').trigger('click'); + spy.called.should.equal(true); + }); + + }); + }); +}); \ No newline at end of file diff --git a/test/specs/asset_manager/view/AssetView.js b/test/specs/asset_manager/view/AssetView.js new file mode 100644 index 000000000..4bf7f4a25 --- /dev/null +++ b/test/specs/asset_manager/view/AssetView.js @@ -0,0 +1,42 @@ +define(['AssetManager/view/AssetView', 'AssetManager/model/Asset', 'AssetManager/model/Assets'], + function(AssetView, Asset, Assets) { + + describe('Asset Manager', function() { + + describe('AssetView', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $(''); + }); + + beforeEach(function () { + var coll = new Assets(); + var model = coll.add({}); + this.view = new AssetView({ + config : {}, + model: model + }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.model.destroy(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + AssetView.should.be.exist; + }); + + it('Has correct prefix', function() { + this.view.pfx.should.equal(''); + }); + + }); + }); +}); \ No newline at end of file diff --git a/test/specs/asset_manager/view/FileUploader.js b/test/specs/asset_manager/view/FileUploader.js new file mode 100644 index 000000000..d9bfec677 --- /dev/null +++ b/test/specs/asset_manager/view/FileUploader.js @@ -0,0 +1,77 @@ +define(['AssetManager/view/FileUploader'], + function(FileUploader) { + + describe('Asset Manager', function() { + + describe('File Uploader', function() { + + before(function () { + this.$fixtures = $("#fixtures"); + this.$fixture = $(''); + }); + + beforeEach(function () { + this.view = new FileUploader({ config : {} }); + this.$fixture.empty().appendTo(this.$fixtures); + this.$fixture.html(this.view.render().el); + }); + + afterEach(function () { + this.view.remove(); + }); + + after(function () { + this.$fixture.remove(); + }); + + it('Object exists', function() { + FileUploader.should.be.exist; + }); + + it('Has correct prefix', function() { + this.view.pfx.should.equal(''); + }); + + describe('Should be rendered correctly', function() { + + it('Has title', function() { + this.view.$el.find('#title').should.have.property(0); + }); + + it('Title is empty', function() { + this.view.$el.find('#title').html().should.equal(''); + }); + + it('Has file input', function() { + this.view.$el.find('input[type=file]').should.have.property(0); + }); + + it('File input is enabled', function() { + this.view.$el.find('input[type=file]').prop('disabled').should.equal(false); + }); + + }); + + describe('Interprets configurations correctly', function() { + + it('Has correct title', function() { + var view = new FileUploader({ config : { + uploadText : 'Test', + } }); + view.render(); + view.$el.find('#title').html().should.equal('Test'); + }); + + it('Could be disabled', function() { + var view = new FileUploader({ config : { + disableUpload: true, + } }); + view.render(); + view.$el.find('input[type=file]').prop('disabled').should.equal(true); + }); + + }); + + }); + }); +}); \ No newline at end of file