Browse Source

Update tests

pull/36/head
Artur Arseniev 10 years ago
parent
commit
784f59f4bb
  1. 2
      src/dom_components/main.js
  2. 39
      test/specs/code_manager/model/CodeModels.js
  3. 28
      test/specs/dom_components/model/Component.js
  4. 17
      test/specs/dom_components/view/ComponentV.js
  5. 17
      test/specs/dom_components/view/ComponentsView.js

2
src/dom_components/main.js

@ -70,6 +70,8 @@ define(function(require) {
return { return {
componentTypes: defaultTypes,
/** /**
* Name of the module * Name of the module
* @type {String} * @type {String}

39
test/specs/code_manager/model/CodeModels.js

@ -1,15 +1,22 @@
var path = 'CodeManager/model/'; var path = 'CodeManager/model/';
define([path + 'HtmlGenerator', define([path + 'HtmlGenerator',
path + 'CssGenerator', path + 'CssGenerator',
'DomComponents',
'DomComponents/model/Component', 'DomComponents/model/Component',
'CssComposer'], 'CssComposer'],
function(HtmlGenerator, CssGenerator, Component, CssComposer) { function(HtmlGenerator, CssGenerator, DomComponents, Component, CssComposer) {
return { return {
run : function(){ run : function(){
var comp;
describe('HtmlGenerator', function() { describe('HtmlGenerator', function() {
beforeEach(function () { beforeEach(function () {
this.obj = new HtmlGenerator(); this.obj = new HtmlGenerator();
var dcomp = new DomComponents();
comp = new Component({}, {
defaultTypes: dcomp.componentTypes,
});
}); });
afterEach(function () { afterEach(function () {
@ -17,18 +24,15 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly one component', function() { it('Build correctly one component', function() {
var comp = new Component();
this.obj.build(comp).should.equal(''); this.obj.build(comp).should.equal('');
}); });
it('Build correctly empty component inside', function() { it('Build correctly empty component inside', function() {
var comp = new Component();
var m1 = comp.get('components').add({}); var m1 = comp.get('components').add({});
this.obj.build(comp).should.equal('<div></div>'); this.obj.build(comp).should.equal('<div></div>');
}); });
it('Build correctly not empty component inside', function() { it('Build correctly not empty component inside', function() {
var comp = new Component();
var m1 = comp.get('components').add({ var m1 = comp.get('components').add({
tagName: 'article', tagName: 'article',
attributes: { attributes: {
@ -40,7 +44,6 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly component with classes', function() { it('Build correctly component with classes', function() {
var comp = new Component();
var m1 = comp.get('components').add({ var m1 = comp.get('components').add({
tagName: 'article', tagName: 'article',
attributes: { attributes: {
@ -56,11 +59,15 @@ define([path + 'HtmlGenerator',
}); });
describe('CssGenerator', function() { describe('CssGenerator', function() {
var newCssComp = function(){ var newCssComp = function(){
return new CssComposer().init(); return new CssComposer().init();
}; };
beforeEach(function () { beforeEach(function () {
this.obj = new CssGenerator(); this.obj = new CssGenerator();
var dcomp = new DomComponents();
comp = new Component({}, {
defaultTypes: dcomp.componentTypes,
});
}); });
afterEach(function () { afterEach(function () {
@ -68,18 +75,15 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly one component', function() { it('Build correctly one component', function() {
var comp = new Component();
this.obj.build(comp).should.equal(''); this.obj.build(comp).should.equal('');
}); });
it('Build correctly empty component inside', function() { it('Build correctly empty component inside', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
this.obj.build(comp).should.equal(''); this.obj.build(comp).should.equal('');
}); });
it('Build correctly component with style inside', function() { it('Build correctly component with style inside', function() {
var comp = new Component();
var m1 = comp.get('components').add({ var m1 = comp.get('components').add({
tagName: 'article', tagName: 'article',
style: { style: {
@ -91,7 +95,6 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly component with class styled', function() { it('Build correctly component with class styled', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
@ -103,7 +106,6 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly component styled with class and state', function() { it('Build correctly component styled with class and state', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
@ -117,7 +119,6 @@ define([path + 'HtmlGenerator',
it('Build correctly with more classes', function() { it('Build correctly with more classes', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
var cls2 = m1.get('classes').add({name: 'class2'}); var cls2 = m1.get('classes').add({name: 'class2'});
@ -131,7 +132,6 @@ define([path + 'HtmlGenerator',
}); });
it('Build correctly with class styled out', function() { it('Build correctly with class styled out', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
var cls2 = m1.get('classes').add({name: 'class2'}); var cls2 = m1.get('classes').add({name: 'class2'});
@ -146,7 +146,6 @@ define([path + 'HtmlGenerator',
}); });
it('Rule with media query', function() { it('Rule with media query', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
var cls2 = m1.get('classes').add({name: 'class2'}); var cls2 = m1.get('classes').add({name: 'class2'});
@ -160,7 +159,6 @@ define([path + 'HtmlGenerator',
}); });
it('Rules mixed with media queries', function() { it('Rules mixed with media queries', function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
var cls2 = m1.get('classes').add({name: 'class2'}); var cls2 = m1.get('classes').add({name: 'class2'});
@ -186,7 +184,6 @@ define([path + 'HtmlGenerator',
}); });
it("Avoid useless code", function() { it("Avoid useless code", function() {
var comp = new Component();
var m1 = comp.get('components').add({tagName: 'article'}); var m1 = comp.get('components').add({tagName: 'article'});
var cls1 = m1.get('classes').add({name: 'class1'}); var cls1 = m1.get('classes').add({name: 'class1'});
@ -201,4 +198,4 @@ define([path + 'HtmlGenerator',
} }
}; };
}); });

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

@ -1,17 +1,24 @@
define(['DomComponents/model/Component', define(['DomComponents',
'DomComponents/model/Component',
'DomComponents/model/ComponentImage', 'DomComponents/model/ComponentImage',
'DomComponents/model/ComponentText', 'DomComponents/model/ComponentText',
'DomComponents/model/Components'], 'DomComponents/model/Components'],
function(Component, ComponentImage, ComponentText, Components) { function(DomComponents, Component, ComponentImage, ComponentText, Components) {
return { return {
run : function(){ run : function(){
var obj; var obj;
var dcomp;
var compOpts;
describe('Component', function() { describe('Component', function() {
beforeEach(function () { beforeEach(function () {
obj = new Component(); obj = new Component();
dcomp = new DomComponents();
compOpts = {
defaultTypes: dcomp.componentTypes,
};
}); });
afterEach(function () { afterEach(function () {
@ -79,13 +86,13 @@ define(['DomComponents/model/Component',
}); });
it('Component toHTML with children', function() { it('Component toHTML with children', function() {
obj = new Component({tagName: 'article'}); obj = new Component({tagName: 'article'}, compOpts);
obj.get('components').add({tagName: 'span'}); obj.get('components').add({tagName: 'span'});
obj.toHTML().should.equal('<article><span></span></article>'); obj.toHTML().should.equal('<article><span></span></article>');
}); });
it('Component toHTML with more children', function() { it('Component toHTML with more children', function() {
obj = new Component({tagName: 'article'}); obj = new Component({tagName: 'article'}, compOpts);
obj.get('components').add([{tagName: 'span'}, {tagName: 'div'}]); obj.get('components').add([{tagName: 'span'}, {tagName: 'div'}]);
obj.toHTML().should.equal('<article><span></span><div></div></article>'); obj.toHTML().should.equal('<article><span></span><div></div></article>');
}); });
@ -160,20 +167,27 @@ define(['DomComponents/model/Component',
describe('Components', function() { describe('Components', function() {
beforeEach(function () {
dcomp = new DomComponents();
compOpts = {
defaultTypes: dcomp.componentTypes,
}
});
it('Creates component correctly', function() { it('Creates component correctly', function() {
var c = new Components(); var c = new Components({}, compOpts);
var m = c.add({}); var m = c.add({});
m.should.be.an.instanceOf(Component); m.should.be.an.instanceOf(Component);
}); });
it('Creates image component correctly', function() { it('Creates image component correctly', function() {
var c = new Components(); var c = new Components({}, compOpts);
var m = c.add({ type: 'image' }); var m = c.add({ type: 'image' });
m.should.be.an.instanceOf(ComponentImage); m.should.be.an.instanceOf(ComponentImage);
}); });
it('Creates text component correctly', function() { it('Creates text component correctly', function() {
var c = new Components(); var c = new Components({}, compOpts);
var m = c.add({ type: 'text' }); var m = c.add({ type: 'text' });
m.should.be.an.instanceOf(ComponentText); m.should.be.an.instanceOf(ComponentText);
}); });

17
test/specs/dom_components/view/ComponentV.js

@ -1,6 +1,6 @@
var path = 'DomComponents/view/'; var path = 'DomComponents/view/';
define([path + 'ComponentView', 'DomComponents/model/Component'], define([path + 'ComponentView', 'DomComponents/model/Component', 'DomComponents'],
function(ComponentView, Component) { function(ComponentView, Component, DomComponents) {
return { return {
run : function(){ run : function(){
@ -12,6 +12,8 @@ define([path + 'ComponentView', 'DomComponents/model/Component'],
var model; var model;
var view; var view;
var hClass = 'hc-state'; var hClass = 'hc-state';
var dcomp;
var compOpts;
before(function () { before(function () {
$fixtures = $("#fixtures"); $fixtures = $("#fixtures");
@ -19,6 +21,10 @@ define([path + 'ComponentView', 'DomComponents/model/Component'],
}); });
beforeEach(function () { beforeEach(function () {
dcomp = new DomComponents();
compOpts = {
defaultTypes: dcomp.componentTypes,
};
model = new Component(); model = new Component();
view = new ComponentView({ view = new ComponentView({
model: model model: model
@ -120,9 +126,10 @@ define([path + 'ComponentView', 'DomComponents/model/Component'],
{ tagName: 'span'}, { tagName: 'span'},
{ attributes: { title: 'test'}} { attributes: { title: 'test'}}
] ]
}); }, compOpts);
view = new ComponentView({ view = new ComponentView({
model: model model: model,
defaultTypes: dcomp.componentTypes,
}); });
view.render().$el.html().should.equal('<span></span><div title="test"></div>'); view.render().$el.html().should.equal('<span></span><div title="test"></div>');
}); });
@ -131,4 +138,4 @@ define([path + 'ComponentView', 'DomComponents/model/Component'],
} }
}; };
}); });

17
test/specs/dom_components/view/ComponentsView.js

@ -1,6 +1,6 @@
var path = 'DomComponents/view/'; var path = 'DomComponents/view/';
define([path + 'ComponentsView', 'DomComponents/model/Components'], define(['DomComponents', path + 'ComponentsView', 'DomComponents/model/Components'],
function(ComponentsView, Components) { function(DomComponents, ComponentsView, Components) {
return { return {
run : function(){ run : function(){
@ -10,6 +10,8 @@ define([path + 'ComponentsView', 'DomComponents/model/Components'],
var $fixture; var $fixture;
var model; var model;
var view; var view;
var dcomp;
var compOpts;
before(function () { before(function () {
$fixtures = $("#fixtures"); $fixtures = $("#fixtures");
@ -17,9 +19,14 @@ define([path + 'ComponentsView', 'DomComponents/model/Components'],
}); });
beforeEach(function () { beforeEach(function () {
model = new Components([]); dcomp = new DomComponents();
compOpts = {
defaultTypes: dcomp.componentTypes,
};
model = new Components([], compOpts);
view = new ComponentsView({ view = new ComponentsView({
collection: model collection: model,
defaultTypes: dcomp.componentTypes,
}); });
$fixture.empty().appendTo($fixtures); $fixture.empty().appendTo($fixtures);
$fixture.html(view.render().el); $fixture.html(view.render().el);
@ -52,4 +59,4 @@ define([path + 'ComponentsView', 'DomComponents/model/Components'],
} }
}; };
}); });

Loading…
Cancel
Save