Browse Source

Update tests asset manager

pull/2/merge
Artur Arseniev 9 years ago
parent
commit
6bbd8f8b92
  1. 10
      src/asset_manager/template/assetImage.html
  2. 17
      src/asset_manager/template/assets.html
  3. 5
      src/asset_manager/template/fileUploader.html
  4. 13
      src/asset_manager/view/AssetImageView.js
  5. 21
      src/asset_manager/view/AssetsView.js
  6. 8
      src/asset_manager/view/FileUploader.js
  7. 2
      src/utils/Resizer.js
  8. 2
      test/helper.js
  9. 16
      test/main.js
  10. 265
      test/specs/asset_manager/main.js
  11. 61
      test/specs/asset_manager/model/Asset.js
  12. 43
      test/specs/asset_manager/model/AssetImage.js
  13. 105
      test/specs/asset_manager/model/Assets.js
  14. 163
      test/specs/asset_manager/view/AssetImageView.js
  15. 93
      test/specs/asset_manager/view/AssetView.js
  16. 193
      test/specs/asset_manager/view/AssetsView.js
  17. 157
      test/specs/asset_manager/view/FileUploader.js

10
src/asset_manager/template/assetImage.html

@ -1,10 +0,0 @@
<div id="<%= pfx %>preview-cont">
<div id="<%= pfx %>preview" style="background-image: url(<%= src %>);"></div>
<div id="<%= pfx %>preview-bg" class="<%= ppfx %>checker-bg"></div>
</div>
<div id="<%= pfx %>meta">
<div id="<%= pfx %>name"><%= name %></div>
<div id="<%= pfx %>dimensions"><%= dim %></div>
</div>
<div id="<%= pfx %>close">&Cross;</div>
<div style="clear:both"></div>

17
src/asset_manager/template/assets.html

@ -1,17 +0,0 @@
<div class="<%= pfx %>assets-cont">
<div class="<%= pfx %>assets-header">
<form class="<%= pfx %>add-asset">
<div class="<%= ppfx %>field <%= pfx %>add-field">
<input placeholder="http://path/to/the/image.jpg"/>
</div>
<button class="<%= ppfx %>btn-prim"><%= btnText %></button>
<div style="clear:both"></div>
</form>
<div class="<%= pfx %>dips" style="display:none">
<button class="fa fa-th <%= ppfx %>btnt"></button>
<button class="fa fa-th-list <%= ppfx %>btnt"></button>
</div>
</div>
<div class="<%= pfx %>assets"></div>
<div style="clear:both"></div>
</div>

5
src/asset_manager/template/fileUploader.html

@ -1,5 +0,0 @@
<form>
<div id="<%= pfx %>title"><%= title %></div>
<input type="file" id="<%= uploadId %>" name="file" accept="image/*" <%= disabled ? 'disabled' : '' %> multiple/>
<div style="clear:both;"></div>
</form>

13
src/asset_manager/view/AssetImageView.js

@ -1,5 +1,16 @@
var AssetView = require('./AssetView');
var assetTemplate = require('text!./../template/assetImage.html');
var assetTemplate = `
<div id="<%= pfx %>preview-cont">
<div id="<%= pfx %>preview" style="background-image: url(<%= src %>);"></div>
<div id="<%= pfx %>preview-bg" class="<%= ppfx %>checker-bg"></div>
</div>
<div id="<%= pfx %>meta">
<div id="<%= pfx %>name"><%= name %></div>
<div id="<%= pfx %>dimensions"><%= dim %></div>
</div>
<div id="<%= pfx %>close">&Cross;</div>
<div style="clear:both"></div>
`;
module.exports = AssetView.extend({

21
src/asset_manager/view/AssetsView.js

@ -2,7 +2,26 @@ var Backbone = require('backbone');
var AssetView = require('./AssetView');
var AssetImageView = require('./AssetImageView');
var FileUploader = require('./FileUploader');
var assetsTemplate = require('text!./../template/assets.html');
var assetsTemplate = `
<div class="<%= pfx %>assets-cont">
<div class="<%= pfx %>assets-header">
<form class="<%= pfx %>add-asset">
<div class="<%= ppfx %>field <%= pfx %>add-field">
<input placeholder="http://path/to/the/image.jpg"/>
</div>
<button class="<%= ppfx %>btn-prim"><%= btnText %></button>
<div style="clear:both"></div>
</form>
<div class="<%= pfx %>dips" style="display:none">
<button class="fa fa-th <%= ppfx %>btnt"></button>
<button class="fa fa-th-list <%= ppfx %>btnt"></button>
</div>
</div>
<div class="<%= pfx %>assets"></div>
<div style="clear:both"></div>
</div>
`;
module.exports = Backbone.View.extend({

8
src/asset_manager/view/FileUploader.js

@ -1,5 +1,11 @@
var Backbone = require('backbone');
var fileUploaderTemplate = require('text!./../template/fileUploader.html');
var fileUploaderTemplate = `
<form>
<div id="<%= pfx %>title"><%= title %></div>
<input type="file" id="<%= uploadId %>" name="file" accept="image/*" <%= disabled ? 'disabled' : '' %> multiple/>
<div style="clear:both;"></div>
</form>
`;
module.exports = Backbone.View.extend({

2
src/utils/Resizer.js

@ -21,7 +21,7 @@ var defaults = {
var createHandler = function (name, opts) {
var pfx = opts.prefix || '';
var el = this.document.createElement('i');
var el = document.createElement('i');
el.className = pfx + 'resizer-h ' + pfx + 'resizer-h-' + name;
el.setAttribute('data-' + pfx + 'handler', name);
return el;

2
test/helper.js

@ -1,8 +1,10 @@
import _ from 'underscore';
import { JSDOM } from 'jsdom';
const dom = new JSDOM('<!doctype html><html><body></body></html>');
global.window = dom.window;
global.document = dom.window.document;
global._ = _;
Object.keys(window).forEach((key) => {
if (!(key in global)) {

16
test/main.js

@ -1,13 +1,17 @@
import expect from 'expect';
import sinon from 'sinon';
//import grapesjs from './../src/main.js';
//const grapesjs = require('./../src/main.js');
import grapesjs from './../src';
//import AssetManager from './specs/asset_manager';
describe('Main', function() {
describe('Startup', function() {
it('Main object should be loaded', function() {
var grru = require('./../src');
describe('Main', () => {
describe('Startup', () => {
it('Main object should be loaded', () => {
//Grapes = require('editor/main');
expect(grapesjs).toExist();
});
});
require('./specs/asset_manager/main.js');
});

265
test/specs/asset_manager/main.js

@ -1,136 +1,133 @@
define(function(require, exports, module){
'use strict';
var StorageManager = require('StorageManager');
var AssetManager = require('AssetManager');
var FileUploader = require('undefined');
describe('Asset Manager', function() {
describe('Main', function() {
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',
width: 101,
height: 102,
};
obj = new AssetManager();
obj.init();
var StorageManager = require('storage_manager');
var AssetManager = require('asset_manager');
var FileUploader = require('./view/FileUploader');
describe('Asset Manager', function() {
describe('Main', function() {
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',
width: 101,
height: 102,
};
obj = new AssetManager();
obj.init();
});
afterEach(function () {
obj = null;
});
it('Object exists', function() {
obj.should.be.exist;
});
it('No assets inside', function() {
obj.getAll().length.should.be.empty;
});
it('Add new asset', function() {
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
it('Added asset has correct data', function() {
obj.add(imgObj);
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('Add asset with src', function() {
obj.add(imgObj.src);
var asset = obj.get(imgObj.src);
asset.get('type').should.equal('image');
asset.get('src').should.equal(imgObj.src);
});
it('Add asset with more src', function() {
obj.add([imgObj.src, imgObj.src + '2']);
obj.getAll().length.should.equal(2);
var asset1 = obj.getAll().at(0);
var asset2 = obj.getAll().at(1);
asset1.get('src').should.equal(imgObj.src);
asset2.get('src').should.equal(imgObj.src + '2');
});
it('Src is unique', function() {
obj.add(imgObj);
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
it('Remove asset', function() {
obj.add(imgObj);
obj.remove(imgObj.src);
obj.getAll().length.should.equal(0);
});
it('Render assets', function() {
obj.add(imgObj);
obj.render().should.not.be.empty;
});
describe('With storage', function() {
var storageManager;
beforeEach(function () {
storageManager = new StorageManager().init({
autoload: 0,
type: storageId
})
obj = new AssetManager().init({
stm: storageManager,
});
afterEach(function () {
delete obj;
});
it('Object exists', function() {
obj.should.be.exist;
});
it('No assets inside', function() {
obj.getAll().length.should.be.empty;
});
it('Add new asset', function() {
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
it('Added asset has correct data', function() {
obj.add(imgObj);
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('Add asset with src', function() {
obj.add(imgObj.src);
var asset = obj.get(imgObj.src);
asset.get('type').should.equal('image');
asset.get('src').should.equal(imgObj.src);
});
it('Add asset with more src', function() {
obj.add([imgObj.src, imgObj.src + '2']);
obj.getAll().length.should.equal(2);
var asset1 = obj.getAll().at(0);
var asset2 = obj.getAll().at(1);
asset1.get('src').should.equal(imgObj.src);
asset2.get('src').should.equal(imgObj.src + '2');
});
it('Src is unique', function() {
obj.add(imgObj);
obj.add(imgObj);
obj.getAll().length.should.equal(1);
});
it('Remove asset', function() {
obj.add(imgObj);
obj.remove(imgObj.src);
obj.getAll().length.should.equal(0);
});
it('Render assets', function() {
obj.add(imgObj);
obj.render().should.not.be.empty;
});
describe('With storage', function() {
var storageManager;
beforeEach(function () {
storageManager = new StorageManager().init({
autoload: 0,
type: storageId
})
obj = new AssetManager().init({
stm: storageManager,
});
storageManager.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');
});
});
});
Asset.run();
AssetImage.run();
Assets.run();
AssetView.run();
AssetImageView.run();
AssetsView.run();
FileUploader.run();
});
storageManager.add(storageId, storageMock);
});
afterEach(function () {
storageManager = null;
});
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');
});
});
});
require('./model/Asset').run();
require('./model/AssetImage').run();
require('./model/Assets').run();
require('./view/AssetView').run();
require('./view/AssetImageView').run();
require('./view/AssetsView').run();
require('./view/FileUploader').run();
});

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

@ -1,37 +1,34 @@
define(function(require, exports, module){
'use strict';
var Asset = require('AssetManager/model/Asset');
var Asset = require('asset_manager/model/Asset');
module.exports = {
run: function(){
module.exports = {
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('');
});
});
}
}

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

@ -1,28 +1,25 @@
define(function(require, exports, module){
'use strict';
var AssetImage = require('AssetManager/model/AssetImage');
var AssetImage = require('asset_manager/model/AssetImage');
module.exports = {
run: function() {
module.exports = {
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;
});
});
});
}
};
});
}
};

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

@ -1,54 +1,51 @@
define(function(require, exports, module){
'use strict';
var Assets = require('AssetManager/model/Assets');
module.exports = {
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');
});
});
}
};
});
var Assets = require('asset_manager/model/Assets');
module.exports = {
run: function() {
describe('Assets', function() {
var obj;
beforeEach(function () {
obj = new Assets();
});
afterEach(function () {
obj = null;
});
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');
});
});
}
};

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

@ -1,83 +1,80 @@
define(function(require, exports, module){
'use strict';
var AssetImageView = require('AssetManager/view/AssetImageView');
var AssetImage = require('AssetManager/model/AssetImage');
var Assets = require('AssetManager/model/Assets');
module.exports = {
run: function() {
describe('AssetImageView', function() {
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
});
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () {
delete this.view;
});
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);
});
});
}
};
});
var AssetImageView = require('asset_manager/view/AssetImageView');
var AssetImage = require('asset_manager/model/AssetImage');
var Assets = require('asset_manager/model/Assets');
module.exports = {
run: function() {
describe('AssetImageView', function() {
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
});
this.$fixture.empty().appendTo(this.$fixtures);
this.$fixture.html(this.view.render().el);
});
afterEach(function () {
delete this.view;
});
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);
});
});
}
};

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

@ -1,48 +1,45 @@
define(function(require, exports, module){
'use strict';
var AssetView = require('AssetManager/view/AssetView');
var Asset = require('AssetManager/model/Asset');
var Assets = require('AssetManager/model/Assets');
module.exports = {
run: function() {
describe('AssetView', function() {
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
});
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() {
AssetView.should.be.exist;
});
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
});
});
}
}
});
var AssetView = require('asset_manager/view/AssetView');
var Asset = require('asset_manager/model/Asset');
var Assets = require('asset_manager/model/Assets');
module.exports = {
run: function() {
describe('AssetView', function() {
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
});
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() {
AssetView.should.be.exist;
});
it('Has correct prefix', function() {
this.view.pfx.should.equal('');
});
});
}
}

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

@ -1,98 +1,95 @@
define(function(require, exports, module){
'use strict';
var AssetsView = require('AssetManager/view/AssetsView');
var Assets = require('AssetManager/model/Assets');
module.exports = {
run: function() {
describe('AssetsView', function() {
var obj;
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
});
obj = this.view;
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.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("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("Clean collection from asset", function (){
var model = this.coll.add({src: 'test'});
this.coll.remove(model);
this.view.getAssetsEl().innerHTML.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 url input", function (){
obj.getInputUrl().should.be.ok;
});
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 AssetsView = require('asset_manager/view/AssetsView');
var Assets = require('asset_manager/model/Assets');
module.exports = {
run: function() {
describe('AssetsView', function() {
var obj;
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
});
obj = this.view;
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.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("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("Clean collection from asset", function (){
var model = this.coll.add({src: 'test'});
this.coll.remove(model);
this.view.getAssetsEl().innerHTML.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 url input", function (){
obj.getInputUrl().should.be.ok;
});
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');
});
});
}
}

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

@ -1,80 +1,77 @@
define(function(require, exports, module){
'use strict';
var FileUploader = require('AssetManager/view/FileUploader');
module.exports = {
run: function() {
describe('File Uploader', function() {
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);
});
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(true);
});
});
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);
});
});
});
}
}
});
var FileUploader = require('asset_manager/view/FileUploader');
module.exports = {
run: function() {
describe('File Uploader', function() {
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);
});
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(true);
});
});
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);
});
});
});
}
}

Loading…
Cancel
Save