Browse Source

Update Asset Manager API

pull/36/head
Artur Arseniev 10 years ago
parent
commit
d005b275ca
  1. 2
      bower.json
  2. 2
      index.html
  3. 2
      package.json
  4. 4
      src/asset_manager/config/config.js
  5. 73
      src/asset_manager/main.js
  6. 3
      test/runner/main.js
  7. 102
      test/specs/asset_manager/main.js
  8. 53
      test/specs/asset_manager/model/Asset.js
  9. 35
      test/specs/asset_manager/model/AssetImage.js
  10. 93
      test/specs/asset_manager/model/Assets.js
  11. 115
      test/specs/asset_manager/view/AssetImageView.js
  12. 59
      test/specs/asset_manager/view/AssetView.js
  13. 159
      test/specs/asset_manager/view/AssetsView.js
  14. 112
      test/specs/asset_manager/view/FileUploader.js

2
bower.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Open source Web Template Editor", "description": "Open source Web Template Editor",
"version": "0.3.8", "version": "0.3.9",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",
"main": [ "main": [

2
index.html

@ -248,7 +248,7 @@
color: #ffffff; color: #ffffff;
font-family: Helvetica, serif; font-family: Helvetica, serif;
font-weight: 100; font-weight: 100;
background-image:url("./img/bg-gr-v.png"), url("./img/work-desk.jpg"); background-image:url("http://grapesjs.com/img/bg-gr-v.png"), url("http://grapesjs.com/img/work-desk.jpg");
background-attachment:scroll, scroll; background-attachment:scroll, scroll;
background-position:left top, center center; background-position:left top, center center;
background-repeat:repeat-y, no-repeat; background-repeat:repeat-y, no-repeat;

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Open source Web Template Editor", "description": "Open source Web Template Editor",
"version": "0.3.8", "version": "0.3.9",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

4
src/asset_manager/config/config.js

@ -4,10 +4,10 @@ define(function () {
autoload: 1, autoload: 1,
// Style prefix // Style prefix
stylePrefix : 'am-', stylePrefix: 'am-',
// Default assets // Default assets
assets : [], assets: [],
// Indicates which storage to use. Available: local | remote // Indicates which storage to use. Available: local | remote
storageType : 'local', storageType : 'local',

73
src/asset_manager/main.js

@ -2,6 +2,9 @@
* * [add](#add) * * [add](#add)
* * [get](#get) * * [get](#get)
* * [getAll](#getall) * * [getAll](#getall)
* * [remove](#remove)
* * [store](#store)
* * [load](#load)
* * [render](#render) * * [render](#render)
* *
* Before using methods you should get first the module from the editor instance, in this way: * Before using methods you should get first the module from the editor instance, in this way:
@ -12,7 +15,7 @@
* *
* @module AssetManager * @module AssetManager
* @param {Object} config Configurations * @param {Object} config Configurations
* @param {Array<Object>} [config.blocks=[]] Default blocks * @param {Array<Object>} [config.assets=[]] Default assets
* @example * @example
* ... * ...
* assetManager: { * assetManager: {
@ -20,6 +23,8 @@
* {src:'path/to/image.png'}, * {src:'path/to/image.png'},
* ... * ...
* ], * ],
* upload: 'http://dropbox/path', // set to false to disable it
* uploadText: 'Drop files here or click to upload',
* } * }
* ... * ...
*/ */
@ -47,6 +52,9 @@ define(function(require) {
var fu = new FileUpload(obj); var fu = new FileUpload(obj);
return { return {
stm: c.stm,
/** /**
* Add new asset/s to the collection. URLs are supposed to be unique * Add new asset/s to the collection. URLs are supposed to be unique
* @param {string|Object|Array<string>|Array<Object>} asset URL strings or an objects representing the resource. * @param {string|Object|Array<string>|Array<Object>} asset URL strings or an objects representing the resource.
@ -59,16 +67,14 @@ define(function(require) {
* // Using objects you could indicate the type and other meta informations * // Using objects you could indicate the type and other meta informations
* assetManager.add({ * assetManager.add({
* src: 'http://img.jpg', * src: 'http://img.jpg',
* type: 'image', * //type: 'image', //image is default
* height: 300, * height: 300,
* width: 200, * width: 200,
* }); * });
* assetManager.add([{ * assetManager.add([{
* src: 'http://img.jpg', * src: 'http://img.jpg',
* type: 'image',
* },{ * },{
* src: './path/to/img.png', * src: './path/to/img.png',
* type: 'image',
* }]); * }]);
*/ */
add: function(asset){ add: function(asset){
@ -96,49 +102,63 @@ define(function(require) {
/** /**
* Remove asset by URL * Remove asset by URL
* @param {string} id URL of the asset * @param {string} src URL of the asset
* @return {this} * @return {this}
* @example * @example
* assetManager.remove('http://img.jpg'); * assetManager.remove('http://img.jpg');
*/ */
remove: function(id){ remove: function(src){
var asset = this.get(src);
this.getAll().remove(asset);
return this; return this;
}, },
/** /**
* Store data from the selected storage * Store assets data to the selected storage
* @return {[type]} [description] * @return {this}
*/ */
store: function(){ store: function(){
if(!this.stm)
return;
this.stm.store({
assets: this.getAll().toJSON()
});
return this;
}, },
/** /**
* Load data from the selected storage * Load data from the selected storage. The fetched data will be added to the collection
* @return {[type]} [description] * @return {this}
*/ */
load: function(){ load: function(){
var name = 'assets';
if(!this.stm)
return;
var data = this.stm.load([name]);
this.getAll().add(data[name] || []);
return this;
}, },
//-------
/** /**
* Get collection of assets * Render assets
* * @param {Boolean} f Force to render
* @return {Object} * @return {HTMLElement}
* */ */
getAssets : function(){ render: function(f){
return assets; if(!this.rendered || f)
this.rendered = am.render().$el.add(fu.render().$el);
return this.rendered;
}, },
//-------
/** /**
* Set new target * Set new target
* @param {Object} m Model * @param {Object} m Model
* *
* @return void * @return void
* */ * */
setTarget : function(m){ setTarget: function(m){
am.collection.target = m; am.collection.target = m;
}, },
@ -148,19 +168,10 @@ define(function(require) {
* *
* @return void * @return void
* */ * */
onSelect : function(f){ onSelect: function(f){
am.collection.onSelect = f; am.collection.onSelect = f;
}, },
/**
* Render
* @param {Boolean} f Force to render
*/
render : function(f){
if(!this.rendered || f)
this.rendered = am.render().$el.add(fu.render().$el);
return this.rendered;
}
}; };
}; };
}); });

3
test/runner/main.js

@ -4,9 +4,6 @@ require(['../src/config/require-config.js', 'config/config.js'], function() {
'sinon', 'sinon',
'specs/main.js', 'specs/main.js',
'specs/asset_manager/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', 'specs/asset_manager/view/AssetsView.js',
'specs/asset_manager/view/AssetView.js', 'specs/asset_manager/view/AssetView.js',
'specs/asset_manager/view/AssetImageView.js', 'specs/asset_manager/view/AssetImageView.js',

102
test/specs/asset_manager/main.js

@ -1,5 +1,14 @@
define(['AssetManager'], var modulePath = './../../../test/specs/asset_manager';
function(AssetManager) {
define(['StorageManager','AssetManager',
modulePath + '/model/Asset',
modulePath + '/model/AssetImage',
modulePath + '/model/Assets',
modulePath + '/view/AssetView',
modulePath + '/view/AssetImageView',
modulePath + '/view/AssetsView',
modulePath + '/view/FileUploader'],
function(StorageManager, AssetManager, Asset, AssetImage, Assets, AssetView, AssetImageView, AssetsView, FileUploader) {
describe('Asset Manager', function() { describe('Asset Manager', function() {
@ -8,6 +17,17 @@ define(['AssetManager'],
var obj; var obj;
var imgObj; var imgObj;
var storage;
var storageId = 'testStorage';
var storageMock = {
store: function(data){
storage = data;
},
load: function(keys){
return storage;
},
};
beforeEach(function () { beforeEach(function () {
imgObj = { imgObj = {
src: 'path/to/image', src: 'path/to/image',
@ -64,46 +84,58 @@ define(['AssetManager'],
obj.getAll().length.should.equal(1); obj.getAll().length.should.equal(1);
}); });
/* it('Remove asset', function() {
it('AssetsView exists and is an instance of Backbone.View', function() { obj.add(imgObj);
var obj = new AssetManager(); obj.remove(imgObj.src);
obj.am.should.be.exist; obj.getAll().length.should.equal(0);
obj.am.should.be.an.instanceOf(Backbone.View);
}); });
it('FileUpload exists and is an instance of Backbone.View', function() { it('Render assets', function() {
var obj = new AssetManager(); obj.add(imgObj);
obj.fu.should.be.exist; obj.render().should.not.be.empty;
obj.fu.should.be.an.instanceOf(Backbone.View);
}); });
it('Target is assigning', function() { describe('With storage', function() {
var obj = new AssetManager();
var t = 'target'; var storageManager;
obj.setTarget(t);
obj.am.collection.target.should.equal(t); beforeEach(function () {
}); storageManager = new StorageManager({
autoload: 0,
type: storageId
})
obj = new AssetManager({
stm: storageManager,
});
obj.stm.add(storageId, storageMock);
});
afterEach(function () {
delete storageManager;
});
it('Store and load data', function() {
obj.add(imgObj);
obj.store();
obj.remove(imgObj.src);
obj.load();
var asset = obj.get(imgObj.src);
asset.get('width').should.equal(imgObj.width);
asset.get('height').should.equal(imgObj.height);
asset.get('type').should.equal('image');
});
it('onSelect callback is assigning', function() {
var obj = new AssetManager();
var cb = function(){
return 'callback';
};
obj.onSelect(cb);
obj.am.collection.onSelect.should.equal(cb);
}); });
it('Render propagates', function() {
var obj = new AssetManager(),
jq = { $el: $('<div>') };
sinon.stub(obj.am, "render").returns(jq);
sinon.stub(obj.fu, "render").returns(jq);
obj.render();
obj.am.render.calledOnce.should.equal(true);
obj.fu.render.calledOnce.should.equal(true);
obj.rendered.should.not.be.empty;
});
*/
}); });
Asset.run();
AssetImage.run();
Assets.run();
AssetView.run();
AssetImageView.run();
AssetsView.run();
FileUploader.run();
}); });
}); });

53
test/specs/asset_manager/model/Asset.js

@ -1,35 +1,36 @@
define(['AssetManager/model/Asset'], define(['AssetManager/model/Asset'],
function(Asset) { function(Asset) {
describe('Asset Manager', function() { return {
run: function(){
describe('Asset', function() { describe('Asset', function() {
it('Object exists', function() { it('Object exists', function() {
Asset.should.be.exist; Asset.should.be.exist;
}); });
it('Has default values', function() { it('Has default values', function() {
var obj = new Asset({}); var obj = new Asset({});
obj.get('type').should.equal(""); obj.get('type').should.equal("");
obj.get('src').should.equal(""); obj.get('src').should.equal("");
obj.getExtension().should.be.empty; obj.getExtension().should.be.empty;
obj.getFilename().should.be.empty; obj.getFilename().should.be.empty;
}); });
it('Test getFilename', function() { it('Test getFilename', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'}); var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getFilename().should.equal('t.e.s.t'); obj.getFilename().should.equal('t.e.s.t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc'}); var obj = new Asset({ type:'image', src: 'ch/eck/1234abc'});
obj.getFilename().should.equal('1234abc'); obj.getFilename().should.equal('1234abc');
}); });
it('Test getExtension', function() { it('Test getExtension', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'}); var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getExtension().should.equal('t'); obj.getExtension().should.equal('t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc.'}); var obj = new Asset({ type:'image', src: 'ch/eck/1234abc.'});
obj.getExtension().should.equal(''); obj.getExtension().should.equal('');
});
}); });
}
}); }
});
}); });

35
test/specs/asset_manager/model/AssetImage.js

@ -1,24 +1,27 @@
define(['AssetManager/model/AssetImage'], define(['AssetManager/model/AssetImage'],
function(AssetImage) { function(AssetImage) {
describe('Asset Manager', function() { return {
run: function() {
describe('AssetImage', function() { describe('AssetImage', function() {
it('Object exists', function() { it('Object exists', function() {
AssetImage.should.be.exist; 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;
});
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;
}); });
}); }
}); };
}); });

93
test/specs/asset_manager/model/Assets.js

@ -1,52 +1,53 @@
define(['AssetManager/model/Assets'], define(['AssetManager/model/Assets'],
function(Assets) { function(Assets) {
describe('Asset Manager', function() { return {
run: function() {
describe('Assets', function() {
var obj;
beforeEach(function () {
obj = new Assets();
});
afterEach(function () {
delete obj;
});
it('Object exists', function() {
obj.should.be.exist;
});
it('Collection is empty', function() {
obj.length.should.equal(0);
});
it("Can't insert assets without src", function() {
obj.add({});
obj.length.should.equal(0);
obj.add([{},{},{}]);
obj.length.should.equal(0);
});
it("Insert assets only with src", function() {
obj.add([{},{src:'test'},{}]);
obj.length.should.equal(1);
});
it('addImg creates new asset', function() {
obj.addImg('/img/path');
obj.length.should.equal(1);
});
it('addImg asset is correct', function() {
obj.addImg('/img/path');
var asset = obj.at(0);
asset.get('type').should.equal('image');
asset.get('src').should.equal('/img/path');
});
describe('Assets', function() {
var obj;
beforeEach(function () {
obj = new Assets();
});
afterEach(function () {
delete obj;
});
it('Object exists', function() {
Assets.should.be.exist;
});
it('Collection is empty', function() {
obj.length.should.equal(0);
});
it("Can't insert assets without src", function() {
obj.add({});
obj.length.should.equal(0);
obj.add([{},{},{}]);
obj.length.should.equal(0);
});
it("Insert assets only with src", function() {
obj.add([{},{src:'test'},{}]);
obj.length.should.equal(1);
});
it('addImg creates new asset', function() {
obj.addImg('/img/path');
obj.length.should.equal(1);
});
it('addImg asset is correct', function() {
obj.addImg('/img/path');
var asset = obj.at(0);
asset.get('type').should.equal('image');
asset.get('src').should.equal('/img/path');
}); });
}
}); };
});
}); });

115
test/specs/asset_manager/view/AssetImageView.js

@ -1,77 +1,80 @@
define(['AssetManager/view/AssetImageView', 'AssetManager/model/AssetImage', 'AssetManager/model/Assets'], define(['AssetManager/view/AssetImageView', 'AssetManager/model/AssetImage', 'AssetManager/model/Assets'],
function(AssetImageView, AssetImage, Assets) { function(AssetImageView, AssetImage, Assets) {
describe('Asset Manager', function() { return {
run: function() {
describe('AssetImageView', function() { describe('AssetImageView', function() {
before(function () { before(function () {
this.$fixtures = $("#fixtures"); this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>'); this.$fixture = $('<div class="asset-fixture"></div>');
}); });
beforeEach(function () { beforeEach(function () {
var coll = new Assets(); var coll = new Assets();
var model = coll.add({ type:'image', src: '/test' }); var model = coll.add({ type:'image', src: '/test' });
this.view = new AssetImageView({ this.view = new AssetImageView({
config : {}, config : {},
model: model model: model
});
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
}); });
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () { afterEach(function () {
delete this.view; delete this.view;
}); });
after(function () { after(function () {
this.$fixture.remove(); this.$fixture.remove();
}); });
it('Object exists', function() { it('Object exists', function() {
AssetImageView.should.be.exist; AssetImageView.should.be.exist;
}); });
describe('Asset should be rendered correctly', function() { describe('Asset should be rendered correctly', function() {
it('Has preview box', function() { it('Has preview box', function() {
var $asset = this.view.$el; var $asset = this.view.$el;
$asset.find('#preview').should.have.property(0); $asset.find('#preview').should.have.property(0);
}); });
it('Has meta box', function() { it('Has meta box', function() {
var $asset = this.view.$el; var $asset = this.view.$el;
$asset.find('#meta').should.have.property(0); $asset.find('#meta').should.have.property(0);
}); });
it('Has close button', function() { it('Has close button', function() {
var $asset = this.view.$el; var $asset = this.view.$el;
$asset.find('#close').should.have.property(0); $asset.find('#close').should.have.property(0);
}); });
}); });
it('Could be selected', function() { it('Could be selected', function() {
sinon.stub(this.view, 'updateTarget'); sinon.stub(this.view, 'updateTarget');
this.view.$el.trigger('click'); this.view.$el.trigger('click');
this.view.$el.attr('class').should.contain('highlight'); this.view.$el.attr('class').should.contain('highlight');
this.view.updateTarget.calledOnce.should.equal(true); this.view.updateTarget.calledOnce.should.equal(true);
}); });
it('Could be chosen', function() { it('Could be chosen', function() {
sinon.stub(this.view, 'updateTarget'); sinon.stub(this.view, 'updateTarget');
this.view.$el.trigger('dblclick'); this.view.$el.trigger('dblclick');
this.view.updateTarget.calledOnce.should.equal(true); 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);
});
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);
}); });
}); }
}); };
}); });

59
test/specs/asset_manager/view/AssetView.js

@ -1,42 +1,45 @@
define(['AssetManager/view/AssetView', 'AssetManager/model/Asset', 'AssetManager/model/Assets'], define(['AssetManager/view/AssetView', 'AssetManager/model/Asset', 'AssetManager/model/Assets'],
function(AssetView, Asset, Assets) { function(AssetView, Asset, Assets) {
describe('Asset Manager', function() { return {
run: function() {
describe('AssetView', function() { describe('AssetView', function() {
before(function () { before(function () {
this.$fixtures = $("#fixtures"); this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>'); this.$fixture = $('<div class="asset-fixture"></div>');
}); });
beforeEach(function () { beforeEach(function () {
var coll = new Assets(); var coll = new Assets();
var model = coll.add({src: 'test'}); var model = coll.add({src: 'test'});
this.view = new AssetView({ this.view = new AssetView({
config : {}, config : {},
model: model model: model
});
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
}); });
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () { afterEach(function () {
this.view.remove(); this.view.remove();
}); });
after(function () { after(function () {
this.$fixture.remove(); this.$fixture.remove();
}); });
it('Object exists', function() { it('Object exists', function() {
AssetView.should.be.exist; AssetView.should.be.exist;
}); });
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
});
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
}); });
}); }
}); }
}); });

159
test/specs/asset_manager/view/AssetsView.js

@ -1,104 +1,107 @@
define(['AssetManager/view/AssetsView', 'AssetManager/model/Assets'], define(['AssetManager/view/AssetsView', 'AssetManager/model/Assets'],
function(AssetsView, Assets) { function(AssetsView, Assets) {
describe('Asset Manager', function() { return {
run: function() {
describe('AssetsView', function() { describe('AssetsView', function() {
var obj; var obj;
before(function () { before(function () {
this.$fixtures = $("#fixtures"); this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="assets-fixture"></div>'); this.$fixture = $('<div class="assets-fixture"></div>');
}); });
beforeEach(function () { beforeEach(function () {
this.coll = new Assets([]); this.coll = new Assets([]);
this.view = new AssetsView({ this.view = new AssetsView({
config : {}, config : {},
collection: this.coll collection: this.coll
});
obj = this.view;
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
}); });
obj = this.view;
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () { afterEach(function () {
this.view.collection.reset(); this.view.collection.reset();
}); });
after(function () { after(function () {
this.$fixture.remove(); this.$fixture.remove();
}); });
it('Object exists', function() { it('Object exists', function() {
AssetsView.should.be.exist; AssetsView.should.be.exist;
}); });
it("Collection is empty", function (){ it("Collection is empty", function (){
this.view.getAssetsEl().innerHTML.should.be.empty; this.view.getAssetsEl().innerHTML.should.be.empty;
}); });
it("Add new asset", function (){ it("Add new asset", function (){
sinon.stub(this.view, "addAsset"); sinon.stub(this.view, "addAsset");
this.coll.add({src: 'test'}); this.coll.add({src: 'test'});
this.view.addAsset.calledOnce.should.equal(true); this.view.addAsset.calledOnce.should.equal(true);
}); });
it("Render new asset", function (){ it("Render new asset", function (){
this.coll.add({src: 'test'}); this.coll.add({src: 'test'});
this.view.getAssetsEl().innerHTML.should.not.be.empty; this.view.getAssetsEl().innerHTML.should.not.be.empty;
}); });
it("Render correctly new image asset", function (){ it("Render correctly new image asset", function (){
this.coll.add({ type: 'image', src: 'test'}); this.coll.add({ type: 'image', src: 'test'});
var asset = this.view.getAssetsEl().firstChild; var asset = this.view.getAssetsEl().firstChild;
asset.tagName.should.equal('DIV'); asset.tagName.should.equal('DIV');
asset.innerHTML.should.not.be.empty; asset.innerHTML.should.not.be.empty;
}); });
it("Clean collection from asset", function (){ it("Clean collection from asset", function (){
var model = this.coll.add({src: 'test'}); var model = this.coll.add({src: 'test'});
this.coll.remove(model); this.coll.remove(model);
this.view.getAssetsEl().innerHTML.should.be.empty; this.view.getAssetsEl().innerHTML.should.be.empty;
}); });
it("Load no assets", function (){ it("Load no assets", function (){
(this.view.load() === null).should.be.true; (this.view.load() === null).should.be.true;
}); });
it("Load assets", function (){ it("Load assets", function (){
var obj = { test: '1' }; var obj = { test: '1' };
this.view.storagePrv = { load : function(){} }; this.view.storagePrv = { load : function(){} };
sinon.stub(this.view.storagePrv, "load").returns(obj); sinon.stub(this.view.storagePrv, "load").returns(obj);
this.view.load().should.equal(obj); this.view.load().should.equal(obj);
}); });
it("Deselect works", function (){ it("Deselect works", function (){
this.coll.add([{},{}]); this.coll.add([{},{}]);
var $asset = this.view.$el.children().first(); var $asset = this.view.$el.children().first();
$asset.attr('class', this.view.pfx + 'highlight'); $asset.attr('class', this.view.pfx + 'highlight');
this.coll.trigger('deselectAll'); this.coll.trigger('deselectAll');
$asset.attr('class').should.be.empty; $asset.attr('class').should.be.empty;
}); });
it("Returns not empty assets element", function (){ it("Returns not empty assets element", function (){
obj.getAssetsEl().should.be.ok; obj.getAssetsEl().should.be.ok;
}); });
it("Returns not empty url input", function (){ it("Returns not empty url input", function (){
obj.getInputUrl().should.be.ok; obj.getInputUrl().should.be.ok;
}); });
it("Add image asset from input string", function (){ it("Add image asset from input string", function (){
obj.getInputUrl().value = "test"; obj.getInputUrl().value = "test";
obj.addFromStr({ obj.addFromStr({
preventDefault: function(){} preventDefault: function(){}
});
var asset = obj.collection.at(0);
asset.get('src').should.equal('test');
}); });
var asset = obj.collection.at(0);
asset.get('src').should.equal('test');
}); });
}); }
}); }
}); });

112
test/specs/asset_manager/view/FileUploader.js

@ -1,77 +1,79 @@
define(['AssetManager/view/FileUploader'], define(['AssetManager/view/FileUploader'],
function(FileUploader) { function(FileUploader) {
describe('Asset Manager', function() { return {
run: function() {
describe('File Uploader', function() { describe('File Uploader', function() {
before(function () { before(function () {
this.$fixtures = $("#fixtures"); this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="fileupload-fixture"></div>'); this.$fixture = $('<div class="fileupload-fixture"></div>');
}); });
beforeEach(function () { beforeEach(function () {
this.view = new FileUploader({ config : {} }); this.view = new FileUploader({ config : {} });
this.$fixture.empty().appendTo(this.$fixtures); this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el); this.$fixture.html(this.view.render().el);
}); });
afterEach(function () { afterEach(function () {
this.view.remove(); this.view.remove();
}); });
after(function () { after(function () {
this.$fixture.remove(); this.$fixture.remove();
}); });
it('Object exists', function() { it('Object exists', function() {
FileUploader.should.be.exist; FileUploader.should.be.exist;
}); });
it('Has correct prefix', function() { it('Has correct prefix', function() {
this.view.pfx.should.equal(''); this.view.pfx.should.equal('');
}); });
describe('Should be rendered correctly', function() { describe('Should be rendered correctly', function() {
it('Has title', function() { it('Has title', function() {
this.view.$el.find('#title').should.have.property(0); this.view.$el.find('#title').should.have.property(0);
}); });
it('Title is empty', function() { it('Title is empty', function() {
this.view.$el.find('#title').html().should.equal(''); this.view.$el.find('#title').html().should.equal('');
}); });
it('Has file input', function() { it('Has file input', function() {
this.view.$el.find('input[type=file]').should.have.property(0); this.view.$el.find('input[type=file]').should.have.property(0);
}); });
it('File input is enabled', function() { it('File input is enabled', function() {
this.view.$el.find('input[type=file]').prop('disabled').should.equal(false); this.view.$el.find('input[type=file]').prop('disabled').should.equal(false);
}); });
}); });
describe('Interprets configurations correctly', function() { describe('Interprets configurations correctly', function() {
it('Has correct title', function() { it('Has correct title', function() {
var view = new FileUploader({ config : { var view = new FileUploader({ config : {
uploadText : 'Test', uploadText : 'Test',
} }); } });
view.render(); view.render();
view.$el.find('#title').html().should.equal('Test'); view.$el.find('#title').html().should.equal('Test');
}); });
it('Could be disabled', function() { it('Could be disabled', function() {
var view = new FileUploader({ config : { var view = new FileUploader({ config : {
disableUpload: true, disableUpload: true,
} }); } });
view.render(); view.render();
view.$el.find('input[type=file]').prop('disabled').should.equal(true); view.$el.find('input[type=file]').prop('disabled').should.equal(true);
}); });
}); });
}); });
}); }
}
}); });
Loading…
Cancel
Save