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",
"description": "Open source Web Template Editor",
"version": "0.3.8",
"version": "0.3.9",
"author": "Artur Arseniev",
"homepage": "http://grapesjs.com",
"main": [

2
index.html

@ -248,7 +248,7 @@
color: #ffffff;
font-family: Helvetica, serif;
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-position:left top, center center;
background-repeat:repeat-y, no-repeat;

2
package.json

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

4
src/asset_manager/config/config.js

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

73
src/asset_manager/main.js

@ -2,6 +2,9 @@
* * [add](#add)
* * [get](#get)
* * [getAll](#getall)
* * [remove](#remove)
* * [store](#store)
* * [load](#load)
* * [render](#render)
*
* Before using methods you should get first the module from the editor instance, in this way:
@ -12,7 +15,7 @@
*
* @module AssetManager
* @param {Object} config Configurations
* @param {Array<Object>} [config.blocks=[]] Default blocks
* @param {Array<Object>} [config.assets=[]] Default assets
* @example
* ...
* assetManager: {
@ -20,6 +23,8 @@
* {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);
return {
stm: c.stm,
/**
* 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.
@ -59,16 +67,14 @@ define(function(require) {
* // Using objects you could indicate the type and other meta informations
* assetManager.add({
* src: 'http://img.jpg',
* type: 'image',
* //type: 'image', //image is default
* height: 300,
* width: 200,
* });
* assetManager.add([{
* src: 'http://img.jpg',
* type: 'image',
* },{
* src: './path/to/img.png',
* type: 'image',
* }]);
*/
add: function(asset){
@ -96,49 +102,63 @@ define(function(require) {
/**
* Remove asset by URL
* @param {string} id URL of the asset
* @param {string} src URL of the asset
* @return {this}
* @example
* assetManager.remove('http://img.jpg');
*/
remove: function(id){
remove: function(src){
var asset = this.get(src);
this.getAll().remove(asset);
return this;
},
/**
* Store data from the selected storage
* @return {[type]} [description]
* Store assets data to the selected storage
* @return {this}
*/
store: function(){
if(!this.stm)
return;
this.stm.store({
assets: this.getAll().toJSON()
});
return this;
},
/**
* Load data from the selected storage
* @return {[type]} [description]
* Load data from the selected storage. The fetched data will be added to the collection
* @return {this}
*/
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
*
* @return {Object}
* */
getAssets : function(){
return assets;
* Render assets
* @param {Boolean} f Force to render
* @return {HTMLElement}
*/
render: function(f){
if(!this.rendered || f)
this.rendered = am.render().$el.add(fu.render().$el);
return this.rendered;
},
//-------
/**
* Set new target
* @param {Object} m Model
*
* @return void
* */
setTarget : function(m){
setTarget: function(m){
am.collection.target = m;
},
@ -148,19 +168,10 @@ define(function(require) {
*
* @return void
* */
onSelect : function(f){
onSelect: function(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',
'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',
'specs/asset_manager/view/AssetView.js',
'specs/asset_manager/view/AssetImageView.js',

102
test/specs/asset_manager/main.js

@ -1,5 +1,14 @@
define(['AssetManager'],
function(AssetManager) {
var modulePath = './../../../test/specs/asset_manager';
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() {
@ -8,6 +17,17 @@ define(['AssetManager'],
var obj;
var imgObj;
var storage;
var storageId = 'testStorage';
var storageMock = {
store: function(data){
storage = data;
},
load: function(keys){
return storage;
},
};
beforeEach(function () {
imgObj = {
src: 'path/to/image',
@ -64,46 +84,58 @@ define(['AssetManager'],
obj.getAll().length.should.equal(1);
});
/*
it('AssetsView exists and is an instance of Backbone.View', function() {
var obj = new AssetManager();
obj.am.should.be.exist;
obj.am.should.be.an.instanceOf(Backbone.View);
it('Remove asset', function() {
obj.add(imgObj);
obj.remove(imgObj.src);
obj.getAll().length.should.equal(0);
});
it('FileUpload exists and is an instance of Backbone.View', function() {
var obj = new AssetManager();
obj.fu.should.be.exist;
obj.fu.should.be.an.instanceOf(Backbone.View);
it('Render assets', function() {
obj.add(imgObj);
obj.render().should.not.be.empty;
});
it('Target is assigning', function() {
var obj = new AssetManager();
var t = 'target';
obj.setTarget(t);
obj.am.collection.target.should.equal(t);
});
describe('With storage', function() {
var storageManager;
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'],
function(Asset) {
describe('Asset Manager', function() {
return {
run: function(){
describe('Asset', function() {
it('Object exists', function() {
Asset.should.be.exist;
});
describe('Asset', function() {
it('Object exists', function() {
Asset.should.be.exist;
});
it('Has default values', function() {
var obj = new Asset({});
obj.get('type').should.equal("");
obj.get('src').should.equal("");
obj.getExtension().should.be.empty;
obj.getFilename().should.be.empty;
});
it('Has default values', function() {
var obj = new Asset({});
obj.get('type').should.equal("");
obj.get('src').should.equal("");
obj.getExtension().should.be.empty;
obj.getFilename().should.be.empty;
});
it('Test getFilename', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getFilename().should.equal('t.e.s.t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc'});
obj.getFilename().should.equal('1234abc');
});
it('Test getFilename', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getFilename().should.equal('t.e.s.t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc'});
obj.getFilename().should.equal('1234abc');
});
it('Test getExtension', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getExtension().should.equal('t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc.'});
obj.getExtension().should.equal('');
it('Test getExtension', function() {
var obj = new Asset({ type:'image', src: 'ch/eck/t.e.s.t'});
obj.getExtension().should.equal('t');
var obj = new Asset({ type:'image', src: 'ch/eck/1234abc.'});
obj.getExtension().should.equal('');
});
});
});
});
}
}
});

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

@ -1,24 +1,27 @@
define(['AssetManager/model/AssetImage'],
function(AssetImage) {
describe('Asset Manager', function() {
return {
run: function() {
describe('AssetImage', function() {
it('Object exists', function() {
AssetImage.should.be.exist;
});
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;
});
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'],
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'],
function(AssetImageView, AssetImage, Assets) {
describe('Asset Manager', function() {
return {
run: function() {
describe('AssetImageView', function() {
describe('AssetImageView', function() {
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>');
});
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>');
});
beforeEach(function () {
var coll = new Assets();
var model = coll.add({ type:'image', src: '/test' });
this.view = new AssetImageView({
config : {},
model: model
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);
});
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () {
delete this.view;
});
afterEach(function () {
delete this.view;
});
after(function () {
this.$fixture.remove();
});
after(function () {
this.$fixture.remove();
});
it('Object exists', function() {
AssetImageView.should.be.exist;
});
it('Object exists', function() {
AssetImageView.should.be.exist;
});
describe('Asset should be rendered correctly', function() {
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 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 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('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 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 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);
});
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'],
function(AssetView, Asset, Assets) {
describe('Asset Manager', function() {
return {
run: function() {
describe('AssetView', function() {
describe('AssetView', function() {
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>');
});
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="asset-fixture"></div>');
});
beforeEach(function () {
var coll = new Assets();
var model = coll.add({src: 'test'});
this.view = new AssetView({
config : {},
model: model
beforeEach(function () {
var coll = new Assets();
var model = coll.add({src: 'test'});
this.view = new AssetView({
config : {},
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 () {
this.view.remove();
});
afterEach(function () {
this.view.remove();
});
after(function () {
this.$fixture.remove();
});
after(function () {
this.$fixture.remove();
});
it('Object exists', function() {
AssetView.should.be.exist;
});
it('Object exists', function() {
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'],
function(AssetsView, Assets) {
describe('Asset Manager', function() {
return {
run: function() {
describe('AssetsView', function() {
describe('AssetsView', function() {
var obj;
var obj;
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="assets-fixture"></div>');
});
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="assets-fixture"></div>');
});
beforeEach(function () {
this.coll = new Assets([]);
this.view = new AssetsView({
config : {},
collection: this.coll
beforeEach(function () {
this.coll = new Assets([]);
this.view = new AssetsView({
config : {},
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 () {
this.view.collection.reset();
});
afterEach(function () {
this.view.collection.reset();
});
after(function () {
this.$fixture.remove();
});
after(function () {
this.$fixture.remove();
});
it('Object exists', function() {
AssetsView.should.be.exist;
});
it('Object exists', function() {
AssetsView.should.be.exist;
});
it("Collection is empty", function (){
this.view.getAssetsEl().innerHTML.should.be.empty;
});
it("Collection is empty", function (){
this.view.getAssetsEl().innerHTML.should.be.empty;
});
it("Add new asset", function (){
sinon.stub(this.view, "addAsset");
this.coll.add({src: 'test'});
this.view.addAsset.calledOnce.should.equal(true);
});
it("Add new asset", function (){
sinon.stub(this.view, "addAsset");
this.coll.add({src: 'test'});
this.view.addAsset.calledOnce.should.equal(true);
});
it("Render new asset", function (){
this.coll.add({src: 'test'});
this.view.getAssetsEl().innerHTML.should.not.be.empty;
});
it("Render new asset", function (){
this.coll.add({src: 'test'});
this.view.getAssetsEl().innerHTML.should.not.be.empty;
});
it("Render correctly new image asset", function (){
this.coll.add({ type: 'image', src: 'test'});
var asset = this.view.getAssetsEl().firstChild;
asset.tagName.should.equal('DIV');
asset.innerHTML.should.not.be.empty;
});
it("Render correctly new image asset", function (){
this.coll.add({ type: 'image', src: 'test'});
var asset = this.view.getAssetsEl().firstChild;
asset.tagName.should.equal('DIV');
asset.innerHTML.should.not.be.empty;
});
it("Clean collection from asset", function (){
var model = this.coll.add({src: 'test'});
this.coll.remove(model);
this.view.getAssetsEl().innerHTML.should.be.empty;
});
it("Clean collection from asset", function (){
var model = this.coll.add({src: 'test'});
this.coll.remove(model);
this.view.getAssetsEl().innerHTML.should.be.empty;
});
it("Load no assets", function (){
(this.view.load() === null).should.be.true;
});
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("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;
});
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;
});
it("Returns not empty assets element", function (){
obj.getAssetsEl().should.be.ok;
});
it("Returns not empty assets element", function (){
obj.getAssetsEl().should.be.ok;
});
it("Returns not empty url input", function (){
obj.getInputUrl().should.be.ok;
});
it("Returns not empty url input", function (){
obj.getInputUrl().should.be.ok;
});
it("Add image asset from input string", function (){
obj.getInputUrl().value = "test";
obj.addFromStr({
preventDefault: function(){}
it("Add image asset from input string", function (){
obj.getInputUrl().value = "test";
obj.addFromStr({
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'],
function(FileUploader) {
describe('Asset Manager', function() {
return {
run: function() {
describe('File Uploader', function() {
describe('File Uploader', function() {
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="fileupload-fixture"></div>');
});
before(function () {
this.$fixtures = $("#fixtures");
this.$fixture = $('<div class="fileupload-fixture"></div>');
});
beforeEach(function () {
this.view = new FileUploader({ config : {} });
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
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();
});
afterEach(function () {
this.view.remove();
});
after(function () {
this.$fixture.remove();
});
after(function () {
this.$fixture.remove();
});
it('Object exists', function() {
FileUploader.should.be.exist;
});
it('Object exists', function() {
FileUploader.should.be.exist;
});
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
});
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
});
describe('Should be rendered correctly', function() {
describe('Should be rendered correctly', function() {
it('Has title', function() {
this.view.$el.find('#title').should.have.property(0);
});
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('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('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);
});
it('File input is enabled', function() {
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() {
var view = new FileUploader({ config : {
uploadText : 'Test',
} });
view.render();
view.$el.find('#title').html().should.equal('Test');
});
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);
});
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);
});
});
});
});
});
});
}
}
});
Loading…
Cancel
Save