Browse Source

Merge branch 'add-more-tests' into dev

pull/11/head
Artur Arseniev 10 years ago
parent
commit
0cc7931a55
  1. 2
      Gruntfile.js
  2. 14
      src/asset_manager/view/AssetView.js
  3. 2
      src/asset_manager/view/FileUploader.js
  4. 46
      src/dom_components/main.js
  5. 13
      src/dom_components/model/Component.js
  6. 4
      test/runner/main.js
  7. 77
      test/specs/asset_manager/view/AssetImageView.js
  8. 42
      test/specs/asset_manager/view/AssetView.js
  9. 77
      test/specs/asset_manager/view/FileUploader.js
  10. 36
      test/specs/components/model/componentModel.js
  11. 58
      test/specs/components/model/components.js
  12. 46
      test/specs/dom_components/main.js
  13. 109
      test/specs/dom_components/model/Component.js
  14. 0
      test/specs/dom_components/view/componentView.js

2
Gruntfile.js

@ -167,7 +167,7 @@ module.exports = function(grunt) {
test: {
files: ['test/specs/**/*.js'],
tasks: ['mocha'],
options: { livereload: true }, //default port 35729
//options: { livereload: true }, //default port 35729
}
},

14
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 );
},
});
});

2
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;

46
src/dom_components/main.js

@ -16,7 +16,7 @@ define(function(require) {
ComponentImageView = require('./view/ComponentImageView'),
ComponentTextView = require('./view/ComponentTextView');
// Set default options
// Set default options
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
@ -34,26 +34,56 @@ define(function(require) {
if(!c.wrapper.style)
c.wrapper.style = {};
c.wrapper.style.position = 'relative';
this.component = new Component(c.wrapper);
var obj = {
model : this.component,
config : c,
model: this.component,
config: c,
};
this.ComponentView = new ComponentView(obj);
this.c = c;
this.ComponentView = new ComponentView(obj);
}
Components.prototype = {
render : function(){
return this.ComponentView.render().$el;
},
/**
* Returns main wrapper which will contain all new components
*
* @return {Object}
*/
getComponent : function(){
return this.component;
},
/**
* Returns main wrapper which will contain all new components
*
* @return {Object}
*/
getWrapper: function(){
return this.getComponent();
},
/**
* Returns children from the wrapper
*
* @return {Object}
*/
getComponents: function(){
return this.getWrapper().get('components');
},
/**
* Render and returns wrapper
*
* @return {Object}
*/
render : function(){
return this.ComponentView.render().el;
},
};
return Components;

13
src/dom_components/model/Component.js

@ -7,7 +7,7 @@ define(['backbone','./Components'],
defaults: {
tagName : 'div',
type : '',
type : '',
editable : false,
removable : true,
movable : true,
@ -18,12 +18,13 @@ define(['backbone','./Components'],
status : '',
previousModel : '',
content : '',
style : {},
attributes : {},
style : {},
attributes : {},
},
initialize: function(options) {
this.defaultC = options.components || [];
initialize: function(o) {
this.config = o || {};
this.defaultC = this.config.components || [];
this.components = new Components(this.defaultC);
this.set('components', this.components);
},
@ -47,7 +48,7 @@ define(['backbone','./Components'],
/**
* Get name of the component
*
* @return string
* @return {String}
* */
getName: function(){
if(!this.name){

4
test/runner/main.js

@ -8,6 +8,10 @@ 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',
'specs/dom_components/main.js',
], function(chai)
{
var should = chai.should(),

77
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 = $('<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 () {
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);
});
});
});
});

42
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 = $('<div class="asset-fixture"></div>');
});
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('');
});
});
});
});

77
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 = $('<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(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);
});
});
});
});
});

36
test/specs/components/model/componentModel.js

@ -1,36 +0,0 @@
define(['componentModel'],
function(componentModel) {
describe('Component', function() {
it('Contiene valori di default', function() {//Has default values
var model = new componentModel({});
var modelComponents = model.components;
model.should.be.ok;
model.get('tagName').should.equal("div");
model.get('classes').should.be.empty;
model.get('css').should.be.empty;
model.get('attributes').should.be.empty;
modelComponents.models.should.be.empty;
});
it('Non ci sono altri componenti all\'interno ', function() {//No other components inside
var model = new componentModel({});
var modelComponents = model.components;
model.should.be.ok;
modelComponents.models.should.be.empty;
});
it('Imposta valori passati', function() {//Sets passed attributes
var model = new componentModel({
tagName : 'span',
classes : ['one','two','three'],
css : { 'one':'vone', 'two':'vtwo', },
attributes : { 'data-one':'vone', 'data-two':'vtwo', },
});
model.should.be.ok;
model.get('tagName').should.equal("span");
model.get('classes').should.have.length(3);
model.get('css').should.have.keys(["one", "two",]);
model.get('attributes').should.have.keys(["data-one", "data-two",]);
});
it('Possibilità di istanziare componenti annidati'); //Possibility to init nested components
});
});

58
test/specs/components/model/components.js

@ -1,58 +0,0 @@
define(['Components'],
function(Components) {
describe('Components', function() {
before(function () {
this.collection = new Components();
this.collection.localStorage._clear();
});
after(function () {
this.collection = null;
});
describe('Creazione', function() {
it('Contiene valori di default', function() {//Has default values
this.collection.should.be.ok;
this.collection.should.have.length(0);
});
});
describe('Modifica', function() {
beforeEach(function () {
this.collection.create({
tagName : 'span',
classes : ['one','two','three'],
css : { 'one':'vone', 'two':'vtwo', },
attributes : { 'data-one':'vone', 'data-two':'vtwo', },
});
});
afterEach(function () {
this.collection.localStorage._clear();
this.collection.reset();
});
it('Contiene un singolo componente', function(done) { //Has single object
var collection = this.collection, model;
collection.once("reset", function () {
collection.should.have.length(1);
model = collection.at(0);
model.should.be.ok;
model.get('tagName').should.equal("span");
model.get('classes').should.have.length(3);
model.get('css').should.have.keys(["one", "two",]);
model.get('attributes').should.have.keys(["data-one", "data-two",]);
done();
});
collection.fetch({ reset: true });
});
it("Componenete eliminabile", function (done) { //Can delete a component
var collection = this.collection, model;
collection.should.have.length(1);
collection.once("remove", function () {
collection.should.have.length(0);
done();
});
model = collection.shift();
});
});
});
});

46
test/specs/dom_components/main.js

@ -0,0 +1,46 @@
var modulePath = './../../../test/specs/dom_components';
define([
'DomComponents',
modulePath + '/model/Component'
],
function(DomComponents,
ComponentModels
) {
describe('DOM Components', function() {
describe('Main', function() {
beforeEach(function () {
this.obj = new DomComponents();
});
afterEach(function () {
delete this.obj;
});
it('Object exists', function() {
DomComponents.should.be.exist;
});
it('Wrapper exists', function() {
this.obj.getWrapper().should.not.be.empty;
});
it('No components inside', function() {
this.obj.getComponents().length.should.equal(0);
});
it('Render wrapper', function() {
sinon.stub(this.obj.ComponentView, "render").returns({ el: '' });
this.obj.render();
this.obj.ComponentView.render.calledOnce.should.equal(true);
});
});
ComponentModels.run();
});
});

109
test/specs/dom_components/model/Component.js

@ -0,0 +1,109 @@
define(['DomComponents/model/Component',
'DomComponents/model/ComponentImage',
'DomComponents/model/ComponentText',
'DomComponents/model/Components'],
function(Component, ComponentImage, ComponentText, Components) {
return {
run : function(){
describe('Component', function() {
beforeEach(function () {
this.obj = new Component();
});
afterEach(function () {
delete this.obj;
});
it('Has no children', function() {
this.obj.get('components').length.should.equal(0);
});
it('Clones correctly', function() {
var sAttr = this.obj.attributes;
var cloned = this.obj.clone();
var eAttr = cloned.attributes;
sAttr.components = {};
eAttr.components = {};
sAttr.should.deep.equal(eAttr);
});
it('Has expected name', function() {
this.obj.cid = 'c999';
this.obj.getName().should.equal('Box999');
});
it('Has expected name 2', function() {
this.obj.cid = 'c999';
this.obj.set('type','testType');
this.obj.getName().should.equal('TestTypeBox999');
});
});
describe('Image Component', function() {
beforeEach(function () {
this.obj = new ComponentImage();
});
afterEach(function () {
delete this.obj;
});
it('Has src property', function() {
this.obj.has('src').should.equal(true);
});
it('Not droppable', function() {
this.obj.get('droppable').should.equal(false);
});
});
describe('Text Component', function() {
beforeEach(function () {
this.obj = new ComponentText();
});
afterEach(function () {
delete this.obj;
});
it('Has content property', function() {
this.obj.has('content').should.equal(true);
});
it('Not droppable', function() {
this.obj.get('droppable').should.equal(false);
});
});
describe('Components', function() {
it('Creates component correctly', function() {
var c = new Components();
var m = c.add({});
m.should.be.an.instanceOf(Component);
});
it('Creates image component correctly', function() {
var c = new Components();
var m = c.add({ type: 'image' });
m.should.be.an.instanceOf(ComponentImage);
});
it('Creates text component correctly', function() {
var c = new Components();
var m = c.add({ type: 'text' });
m.should.be.an.instanceOf(ComponentText);
});
});
}
};
});

0
test/specs/components/view/componentView.js → test/specs/dom_components/view/componentView.js

Loading…
Cancel
Save