Browse Source

Fix tests

pull/36/head
Artur Arseniev 9 years ago
parent
commit
bd10795aca
  1. 5
      src/demo.js
  2. 5
      src/dom_components/model/ComponentImage.js
  3. 2
      src/dom_components/model/Components.js
  4. 28
      src/parser/model/ParserHtml.js
  5. 2
      test/specs/asset_manager/main.js
  6. 55
      test/specs/parser/model/ParserHtml.js

5
src/demo.js

@ -10,7 +10,7 @@ require(['config/require-config'], function() {
container : '#gjs',
height: '100%',
//fromElement: true,
/*
components: [{
type: 'text',
style:{
@ -32,7 +32,8 @@ require(['config/require-config'], function() {
type: 'textnode',
content: " More text node --- ",
}],
}],
}],*/
components: '<div id="test1">a b <b>b</b> <i>i</i>c <div>ABC</div> <i>i</i> <u>u</u> test </div>',
storageManager:{
autoload: 0,

5
src/dom_components/model/ComponentImage.js

@ -67,10 +67,7 @@ define(['./Component'],
isComponent: function(el) {
var result = '';
if(el.tagName == 'IMG'){
result = {
type: 'image',
src: el.src
};
result = {type: 'image'};
}
return result;
},

2
src/dom_components/model/Components.js

@ -51,8 +51,6 @@ define([ 'backbone', 'require'],
if(parsed.css && cssc){
var added = cssc.addCollection(parsed.css);
}
console.log('Parsed from add', models);
}
return Backbone.Collection.prototype.add.apply(this, [models, opt]);

28
src/parser/model/ParserHtml.js

@ -68,8 +68,8 @@ define(function(require) {
var attrsLen = attrs.length;
var prevI = result.length - 1;
var prevSib = result[prevI];
var ct = this.compTypes;
if(ct){
var obj = '';
for (var cType in ct) {
@ -125,7 +125,13 @@ define(function(require) {
}
}
var prevIsText = prevSib && prevSib.type == 'text' && prevSib.tagName == TEXT_NODE;
var prevIsText = prevSib && prevSib.type == 'textnode';
if(model.type == 'textnode'){
if(prevIsText){
prevSib.content += model.content;
continue;
}
}
// Find text nodes
/*
if(model.type == 'textnode'){
@ -156,6 +162,24 @@ define(function(require) {
}
}*/
// If all components are texts and textnodes the parent should be text too
// otherwise I'm unable to edit texts
var comps = model.components;
if(!model.type && comps){
var allTxt = 1;
for(var ci = 0; ci < comps.length; ci++){
var comp = comps[ci];
if(comp.type != 'text' &&
comp.type != 'textnode' &&
c.textTags.indexOf(comp.tagName) < 0 ){
allTxt = 0;
break;
}
}
if(allTxt)
model.type = 'text';
}
// If tagName is still empty and is not a textnode, do not push it
if(!model.tagName && model.type != 'textnode')
continue;

2
test/specs/asset_manager/main.js

@ -139,4 +139,4 @@ define(['StorageManager','AssetManager',
AssetsView.run();
FileUploader.run();
});
});
});

55
test/specs/parser/model/ParserHtml.js

@ -1,17 +1,19 @@
var path = 'Parser/';
define([path + 'model/ParserHtml', path + 'model/ParserCss'],
function(ParserHtml, ParserCss) {
define([path + 'model/ParserHtml', path + 'model/ParserCss', 'DomComponents'],
function(ParserHtml, ParserCss, DomComponents) {
return {
run : function(){
describe('ParserHtml', function() {
describe.only('ParserHtml', function() {
var obj;
beforeEach(function () {
var dom = new DomComponents();
obj = new ParserHtml({
textTags: ['br', 'b', 'i', 'u'],
});
obj.compTypes = dom.componentTypes;
});
afterEach(function () {
@ -89,8 +91,10 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'],
var result = {
tagName: 'img',
type: 'image',
src: './index.html',
attributes: { id: 'test1'},
attributes: {
id: 'test1',
src: './index.html',
},
};
obj.parse(str).html.should.deep.equal(result);
});
@ -112,7 +116,44 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'],
tagName: 'div',
attributes: { id: 'test1'},
type: 'text',
content: '<br> test2 <br> a b <b>b</b> <i>i</i> <u>u</u> test ',
components: [
{tagName: 'br'},
{
content: ' test2 ',
type: 'textnode',
tagName: ''
},
{tagName: 'br'},
{
content: ' a b ',
type: 'textnode',
tagName: ''
},{
content: 'b',
type: 'text',
tagName: 'b'
},{
content: ' ',
type: 'textnode',
tagName: ''
},{
content: 'i',
tagName: 'i',
type: 'text'
},{
content: ' ',
type: 'textnode',
tagName: ''
},{
content: 'u',
tagName: 'u',
type: 'text'
},{
content: ' test ',
type: 'textnode',
tagName: ''
}
],
};
obj.parse(str).html.should.deep.equal(result);
});
@ -253,4 +294,4 @@ define([path + 'model/ParserHtml', path + 'model/ParserCss'],
}
};
});
});

Loading…
Cancel
Save