diff --git a/docs/samples/simplelist/simplelist.spec.js b/docs/samples/simplelist/simplelist.spec.js index 097c6d6..3260801 100644 --- a/docs/samples/simplelist/simplelist.spec.js +++ b/docs/samples/simplelist/simplelist.spec.js @@ -23,7 +23,7 @@ describe('simple list', function () { it('should toggle message on list item click', function () { h('li:eq(1)').click(); - expect(h('li:eq(1)').text()).to.equal('Marge : 38 years old'); + expect(h('li:eq(1)').text()).to.equal('Marge\n : 38 years old'); expect(h('li:eq(1)').hasClass('details')).to.be.ok(); h('li:eq(1)').click(); expect(h('li:eq(1)').text()).to.equal('Marge'); diff --git a/hsp/compiler/jsgenerator/processors.js b/hsp/compiler/jsgenerator/processors.js index 411422c..61dc069 100644 --- a/hsp/compiler/jsgenerator/processors.js +++ b/hsp/compiler/jsgenerator/processors.js @@ -388,7 +388,7 @@ function formatTextBlock (node, nextExprIndex, walker) { // (=args) for (var i = 0; i < content.length; i++) { item = content[i]; - if (item.type === "text") { + if (item.type === "text" || item.type === "eol") { if (index % 2 === 0) { // even index: arg must be a string args[index] = '"' + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"'; diff --git a/hsp/compiler/parser/hspblocks.pegjs b/hsp/compiler/parser/hspblocks.pegjs index 57ba8ef..2549807 100644 --- a/hsp/compiler/parser/hspblocks.pegjs +++ b/hsp/compiler/parser/hspblocks.pegjs @@ -67,8 +67,8 @@ TemplateEnd "template end statement" = _ "" _ (EOL / EOF) {return {type:"/template",line:line,column:column}} -TemplateContent "template content" - = _ blocks:( TplTextBlock +TemplateContent "template content" // TODO: CSSClassExpression + = blocks:( EOLBlock / TplTextBlock / CommentBlock / HTMLCommentBlock / IfBlock / ElseIfBlock / ElseBlock / EndIfBlock / ForeachBlock / EndForeachBlock @@ -89,41 +89,38 @@ TplTextBlock "text" TplTextChar "text character" = "\\{" {return "\u007B"} // { = \u007B / "\\}" {return "\u007D"} // } = \u007D - / "\\n" {return "\n"} - / EOL &TemplateEnd {return ""} // ignore last EOL - / EOL _ {return " "} / "#" !(_ "\/template") {return "#"} / "\/" !"/" {return "/"} / "\\/" {return "/"} / "\\//" {return "//"} / "\\<" {return "<"} - / [^{#/<] + / [^{#/<\n\r\u2028\u2029] InvalidBlock = "{" chars:[^{}#]* "}" {return {type:"invalidblock", code:chars.join(''), line:line, column:column}} IfBlock "if statement" - = "{" _ "if " _ expr:(IfCondWithBrackets / CoreExpText) _ "}" EOS? + = "{" _ "if " _ expr:(IfCondWithBrackets / CoreExpText) _ "}" {return {type:"if", condition:expr, line:line, column:column}} IfCondWithBrackets = "(" expr:CoreExpText ")" {return expr} ElseIfBlock "elseif statement" - = "{" _ "else " _ "if" _ expr:(IfCondWithBrackets / CoreExpText) _ "}" EOS? + = "{" _ "else " _ "if" _ expr:(IfCondWithBrackets / CoreExpText) _ "}" {return {type:"elseif", condition:expr, line:line, column:column}} ElseBlock - = "{" _ "else" _ "}" EOS? + = "{" _ "else" _ "}" {return {type:"else", line:line, column:column}} EndIfBlock - = "{" _ "/if" _ "}" EOS? + = "{" _ "/if" _ "}" {return {type:"endif", line:line, column:column}} CommentBlock - = _ "\/\/" chars:[^\r\n]* &EOL + = _ "\/\/" chars:[^\r\n]* {return {type:"comment", value:chars.join('')}} HTMLCommentBlock @@ -137,7 +134,7 @@ HTMLCommentChar / [^>\-] ForeachBlock - = "{" _ "foreach " _ args:( ForeachArgs / ("(" _ a:ForeachArgs _ ")") {return a}) _ "}" EOS? + = "{" _ "foreach " _ args:( ForeachArgs / ("(" _ a:ForeachArgs _ ")") {return a}) _ "}" {return {type:"foreach", item:args.item, key:args.key, colref:args.colref, line:line, column:column}} ForeachArgs @@ -156,30 +153,30 @@ EndForeachBlock {return {type:"endforeach", line:line, column:column}} HTMLElement - = "<" !(_ "template") name:HTMLName atts:HTMLElementAttributes? S? end:"/"? ">" EOS? + = "<" !(_ "template") name:HTMLName atts:HTMLElementAttributes? S? end:"/"? ">" {return {type:"element", name:name, closed:(end!==""), attributes:atts, line:line, column:column}} HTMLElementAttributes = atts:((S att:(HTMLAttribute)) {return att})* EndHTMLElement // TODO support comments inside Element - = "" EOS? + = "" {return {type:"endelement", name:name, line:line, column:column}} HspComponent - = "<#" ref:JSObjectRef atts:HTMLElementAttributes? S? end:"/"? ">" EOS? + = "<#" ref:JSObjectRef atts:HTMLElementAttributes? S? end:"/"? ">" {return {type:"component", ref:ref, closed:(end!==""), attributes:atts, line:line, column:column}} EndHspComponent - = "" EOS? + = "" {return {type:"endcomponent", ref:ref, line:line, column:column}} HspCptAttribute - = "<@" ref:VarIdentifier atts:HTMLElementAttributes? S? end:"/"? ">" EOS? + = "<@" ref:VarIdentifier atts:HTMLElementAttributes? S? end:"/"? ">" {return {type:"cptattribute", name:ref, closed:(end!==""), attributes:atts, line:line, column:column}} EndHspCptAttribute - = "" EOS? + = "" {return {type:"endcptattribute", name:ref, line:line, column:column}} InvalidHTMLElement @@ -215,7 +212,7 @@ HTMLAttributeChar // TODO look at W3C specs / [^{\"] LogBlock - = "{" _ "log " _ first:CoreExpText _ next:("," _ CoreExpText)* _"}" EOS? + = "{" _ "log " _ first:CoreExpText _ next:("," _ CoreExpText)* _"}" { var exprs=[first]; if (next) { @@ -227,7 +224,7 @@ LogBlock } LetBlock - = "{" _ "let " _ first:CoreExpText __ next:("," __ CoreExpText)* "}" EOS? + = "{" _ "let " _ first:CoreExpText __ next:("," __ CoreExpText)* "}" { var asn=[first]; if (next) { @@ -282,6 +279,10 @@ InvalidExpressionValue = !("/template" _) chars:[^}]+ {return {type:"invalidexpression", code:chars.join(''), line:line, column:column}} +EOLBlock "End of line block" + = eol:EOL + {return {type:"eol", value:eol, line:line, column:column};} + // White spaces // mandatory padding including line breaks S "white space" @@ -300,9 +301,6 @@ EOL "end of line" / "\u2028" // line separator / "\u2029" // paragraph separator -EOS "end of statement" // - = empty:(_ EOL _) - EOF "end of file" = !. diff --git a/hsp/compiler/treebuilder/syntaxTree.js b/hsp/compiler/treebuilder/syntaxTree.js index 583e36b..031d80a 100644 --- a/hsp/compiler/treebuilder/syntaxTree.js +++ b/hsp/compiler/treebuilder/syntaxTree.js @@ -296,6 +296,43 @@ var SyntaxTree = klass({ return index; }, + /** + * Manages a End Of Line block + * @param {Array} blocks the full list of blocks. + * @param {Integer} index the index of the block to manage. + * @param {Array} out the output as an array of Node. + * @return {Integer} the index of the block where the function stopped or -1 if all blocks have been handled. + */ + __eol : function(index, blocks, out) { + return this.__text(index, blocks, out); + }, + + _skipWhitespaces: function(index, blocks, out) { + //Skips opening whitespace block and ending EOL block if the line is only made of blocks which don't generate DOM element or text + var toBeSkipped = true; + var nextIndex = index + 1; + while (nextIndex < blocks.length) { + var nextBlock = blocks[nextIndex]; + if (!(nextBlock.type === "text" && nextBlock.value.match(/^(\s)+$/) || + ["if", "elseif", "else", "endif", "comment", "foreach", "endforeach", "eol", "log", "let"].indexOf(nextBlock.type) > -1)) { + toBeSkipped = false; + break; + } + if (nextBlock.type === "eol") { + break; + } + nextIndex++; + } + if (index + 1 < blocks.length && toBeSkipped) { + if (blocks[index + 1].type === "text") { + blocks[index + 1].toBeSkipped = true; + } + if (blocks[nextIndex].type === "eol") { + blocks[nextIndex].toBeSkipped = true; + } + } + }, + /** * Manages a text block: regroups adjacent text and expression blocks * @param {Array} blocks the full list of blocks. @@ -306,19 +343,28 @@ var SyntaxTree = klass({ __text : function (index, blocks, out) { var length = blocks.length, buffer = []; + if (index === 0) { + this._skipWhitespaces(-1, blocks, out); + } + //Regroups adjacent text and expression blocks by looking at the next ones var nextIndex = index, goAhead = (length > nextIndex), block; while (goAhead) { block = blocks[nextIndex]; - if (block.type === "text") { + if (block.type === "text" || block.type === "eol") { if (block.value !== "") { try { - block.value = htmlEntitiesToUtf8(block.value); - buffer.push(block); + block.value = htmlEntitiesToUtf8(block.value); + if (typeof block.toBeSkipped === "undefined") { + buffer.push(block); + } } catch (e) { - this._logError(e.message, block); + this._logError(e.message, block); } } + if (block.type === "eol") { + this._skipWhitespaces(nextIndex, blocks, out); + } } else if (block.type === "expression") { //parse the expression to detect errors if (this._validateExpressionBlock(block)){ @@ -338,7 +384,7 @@ var SyntaxTree = klass({ //Manages the adjacent text and expression blocks found var node = null; - if (buffer.length === 1 && buffer[0].type === "text") { + if (buffer.length === 1 && (buffer[0].type === "text" || buffer[0].type === "eol")) { // only one text block node = new Node("text"); node.value = buffer[0].value; @@ -346,7 +392,7 @@ var SyntaxTree = klass({ // if buffer is composed of only text expressions we concatenate them var onlyText=true; for (var i = 0; i < buffer.length; i++) { - if (buffer[i].type !== "text") { + if (buffer[i].type !== "text" && buffer[i].type !== "eol") { onlyText = false; break; } diff --git a/hsp/utils/hashtester.js b/hsp/utils/hashtester.js index eb9b029..04c9d99 100644 --- a/hsp/utils/hashtester.js +++ b/hsp/utils/hashtester.js @@ -196,3 +196,10 @@ module.exports.newTestContext = function() { }; return h; }; + +//Polyfill to perform tests in IE8 +if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + }; +} diff --git a/package.json b/package.json index 0b63d9b..037e2b9 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "grunt-verifylowercase": "~0.2.0", "grunt-leading-indent": "~0.1.0", "grunt-mocha-test": "~0.7.0", - "grunt-browserify": "~2.0.0", + "grunt-browserify": "~3.0.1", "grunt-peg": "~1.0.0", "grunt-karma": "~0.8.0", "grunt-jscs-checker": "~0.4.0", diff --git a/test/gestures/doubleTap.spec.hsp b/test/gestures/doubleTap.spec.hsp index dab0ce1..10d58d0 100644 --- a/test/gestures/doubleTap.spec.hsp +++ b/test/gestures/doubleTap.spec.hsp @@ -54,7 +54,8 @@ describe("DoubleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -65,7 +66,7 @@ describe("DoubleTap gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -92,11 +93,12 @@ describe("DoubleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 100, clientY : 100 }); @@ -113,15 +115,16 @@ describe("DoubleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); @@ -139,27 +142,28 @@ describe("DoubleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); diff --git a/test/gestures/drag.spec.hsp b/test/gestures/drag.spec.hsp index 42dd00d..6156b38 100644 --- a/test/gestures/drag.spec.hsp +++ b/test/gestures/drag.spec.hsp @@ -45,7 +45,8 @@ describe("Drag gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -56,7 +57,7 @@ describe("Drag gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : true, touches : [{ clientX : 5, @@ -67,7 +68,7 @@ describe("Drag gesture", function () { clientY : 5 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -94,23 +95,24 @@ describe("Drag gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 10, clientY : 10 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 15, clientY : 15 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 15, clientY : 15 }); diff --git a/test/gestures/longPress.spec.hsp b/test/gestures/longPress.spec.hsp index 9edab38..70bf9ce 100644 --- a/test/gestures/longPress.spec.hsp +++ b/test/gestures/longPress.spec.hsp @@ -53,7 +53,8 @@ describe("LongPress gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -64,7 +65,7 @@ describe("LongPress gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -91,11 +92,12 @@ describe("LongPress gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 100, clientY : 100 }); @@ -112,16 +114,17 @@ describe("LongPress gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); clock.tick(990); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); @@ -138,11 +141,12 @@ describe("LongPress gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); diff --git a/test/gestures/pinch.spec.hsp b/test/gestures/pinch.spec.hsp index 1aee986..ee5eee2 100644 --- a/test/gestures/pinch.spec.hsp +++ b/test/gestures/pinch.spec.hsp @@ -45,7 +45,8 @@ describe("Pinch gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { touches : [{ clientX : 0, clientY : 0 @@ -61,7 +62,7 @@ describe("Pinch gesture", function () { clientY : 5 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { touches : [{ clientX : 0, clientY : 0 @@ -74,7 +75,7 @@ describe("Pinch gesture", function () { clientY : 10 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { touches : [{ clientX : 0, clientY : 0 @@ -87,7 +88,7 @@ describe("Pinch gesture", function () { clientY : 15 }] }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { touches : [{ clientX : 0, clientY : 0 @@ -110,7 +111,8 @@ describe("Pinch gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { touches : [{ clientX : 0, clientY : 0 @@ -126,7 +128,7 @@ describe("Pinch gesture", function () { clientY : 5 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { touches : [{ clientX : 0, clientY : 0 @@ -139,7 +141,7 @@ describe("Pinch gesture", function () { clientY : 10 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { touches : [{ clientX : 0, clientY : 0 @@ -152,7 +154,7 @@ describe("Pinch gesture", function () { clientY : 15 }] }); - fireEvent(touchEventMap.touchend, n.node.firstChild,{ + fireEvent(touchEventMap.touchend, target,{ touches : [], changedTouches : [{ clientX : 0, @@ -175,37 +177,38 @@ describe("Pinch gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0, isPrimary : true }); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + fireEvent(touchEventMap.touchstart, target, { clientX : 20, clientY : 20, isPrimary : false }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 10, clientY : 5, isPrimary : true }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 20, clientY : 10, isPrimary : false }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 30, clientY : 15, isPrimary : true }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 40, clientY : 21, isPrimary : false }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 40, clientY : 21, isPrimary : false diff --git a/test/gestures/singleTap.spec.hsp b/test/gestures/singleTap.spec.hsp index 46c2f6e..18954f5 100644 --- a/test/gestures/singleTap.spec.hsp +++ b/test/gestures/singleTap.spec.hsp @@ -54,7 +54,8 @@ describe("SingleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -65,7 +66,7 @@ describe("SingleTap gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -92,11 +93,12 @@ describe("SingleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 100, clientY : 100 }); @@ -113,15 +115,16 @@ describe("SingleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); @@ -139,19 +142,20 @@ describe("SingleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + fireEvent(touchEventMap.touchstart, target, { clientX : 5, clientY : 5 }); @@ -168,15 +172,16 @@ describe("SingleTap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); diff --git a/test/gestures/swipe.spec.hsp b/test/gestures/swipe.spec.hsp index 31ac1b8..5f87421 100644 --- a/test/gestures/swipe.spec.hsp +++ b/test/gestures/swipe.spec.hsp @@ -45,7 +45,8 @@ describe("Swipe gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -56,7 +57,7 @@ describe("Swipe gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -83,27 +84,28 @@ describe("Swipe gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 10, clientY : 5 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 20, clientY : 10 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 30, clientY : 15 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 40, clientY : 21 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 40, clientY : 21 }); @@ -120,23 +122,24 @@ describe("Swipe gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 10, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 15, clientY : 0 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 15, clientY : 5 }); diff --git a/test/gestures/tap.spec.hsp b/test/gestures/tap.spec.hsp index 65fd251..0968a51 100644 --- a/test/gestures/tap.spec.hsp +++ b/test/gestures/tap.spec.hsp @@ -48,7 +48,8 @@ describe("Tap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { isPrimary : true, touches : [{ clientX : 0, @@ -59,7 +60,7 @@ describe("Tap gesture", function () { clientY : 0 }] }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { isPrimary : false, touches : [{ clientX : 0, @@ -86,15 +87,16 @@ describe("Tap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 100, clientY : 100 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 100, clientY : 100 }); @@ -111,15 +113,16 @@ describe("Tap gesture", function () { } }; var n = test1(ctl); - fireEvent(touchEventMap.touchstart, n.node.firstChild, { + var target = n.node.querySelector("div"); + fireEvent(touchEventMap.touchstart, target, { clientX : 0, clientY : 0 }); - fireEvent(touchEventMap.touchmove, n.node.firstChild, { + fireEvent(touchEventMap.touchmove, target, { clientX : 5, clientY : 5 }); - fireEvent(touchEventMap.touchend, n.node.firstChild, { + fireEvent(touchEventMap.touchend, target, { clientX : 5, clientY : 5 }); diff --git a/test/rt/attributes/class.spec.hsp b/test/rt/attributes/class.spec.hsp index ef0f5d4..0051ee7 100644 --- a/test/rt/attributes/class.spec.hsp +++ b/test/rt/attributes/class.spec.hsp @@ -33,20 +33,20 @@ describe("Class attribute", function () { list: "foo bar" }; var n = test1(model); - expect(n.node.childNodes[0].className).to.equal("test"); - expect(n.node.childNodes[1].className).to.equal("active"); - expect(n.node.childNodes[2].className).to.equal("base active"); - expect(n.node.childNodes[3].className).to.equal("foo bar"); - expect(n.node.childNodes[4].className).to.equal("base bar"); + expect(n.node.childNodes[1].className).to.equal("test"); + expect(n.node.childNodes[3].className).to.equal("active"); + expect(n.node.childNodes[5].className).to.equal("base active"); + expect(n.node.childNodes[7].className).to.equal("foo bar"); + expect(n.node.childNodes[9].className).to.equal("base bar"); $set(model, "isActive", false); $set(model, "list", "foz baz"); $set(model, "more", "foo"); hsp.refresh(); - expect(n.node.childNodes[0].className).to.equal("test"); - expect(n.node.childNodes[1].className).to.equal(""); - expect(n.node.childNodes[2].className).to.equal("base"); - expect(n.node.childNodes[3].className).to.equal("foz baz"); - expect(n.node.childNodes[4].className).to.equal("base foo"); + expect(n.node.childNodes[1].className).to.equal("test"); + expect(n.node.childNodes[3].className).to.equal(""); + expect(n.node.childNodes[5].className).to.equal("base"); + expect(n.node.childNodes[7].className).to.equal("foz baz"); + expect(n.node.childNodes[9].className).to.equal("base foo"); n.$dispose(); }); @@ -57,28 +57,28 @@ describe("Class attribute", function () { list: "foo bar" }; var n = test1(model); - expect(n.node.childNodes[0].className).to.equal("test"); - expect(n.node.childNodes[1].className).to.equal("active"); - expect(n.node.childNodes[2].className).to.equal("base active"); - expect(n.node.childNodes[3].className).to.equal("foo bar"); - expect(n.node.childNodes[4].className).to.equal("base bar"); - n.node.childNodes[2].className = "extra " + n.node.childNodes[2].className + " extras"; - n.node.childNodes[3].className = "extra " + n.node.childNodes[3].className + " extras"; - n.node.childNodes[4].className = "extra " + n.node.childNodes[4].className + " extras"; + expect(n.node.childNodes[1].className).to.equal("test"); + expect(n.node.childNodes[3].className).to.equal("active"); + expect(n.node.childNodes[5].className).to.equal("base active"); + expect(n.node.childNodes[7].className).to.equal("foo bar"); + expect(n.node.childNodes[9].className).to.equal("base bar"); + n.node.childNodes[5].className = "extra " + n.node.childNodes[5].className + " extras"; + n.node.childNodes[7].className = "extra " + n.node.childNodes[7].className + " extras"; + n.node.childNodes[9].className = "extra " + n.node.childNodes[9].className + " extras"; $set(model, "isActive", false); $set(model, "list", "foz baz"); $set(model, "more", "foo"); hsp.refresh(); - expect(n.node.childNodes[0].className).to.equal("test"); - expect(n.node.childNodes[1].className).to.equal(""); - expect(n.node.childNodes[2].className).to.equal("base extra extras"); - expect(n.node.childNodes[3].className).to.equal("foz baz extra extras"); - expect(n.node.childNodes[4].className).to.equal("base foo extra extras"); + expect(n.node.childNodes[1].className).to.equal("test"); + expect(n.node.childNodes[3].className).to.equal(""); + expect(n.node.childNodes[5].className).to.equal("base extra extras"); + expect(n.node.childNodes[7].className).to.equal("foz baz extra extras"); + expect(n.node.childNodes[9].className).to.equal("base foo extra extras"); $set(model, "isActive", true); hsp.refresh(); - expect(n.node.childNodes[0].className).to.equal("test"); - expect(n.node.childNodes[1].className).to.equal("active"); - expect(n.node.childNodes[2].className).to.equal("base active extra extras"); + expect(n.node.childNodes[1].className).to.equal("test"); + expect(n.node.childNodes[3].className).to.equal("active"); + expect(n.node.childNodes[5].className).to.equal("base active extra extras"); n.$dispose(); }); }); \ No newline at end of file diff --git a/test/rt/attributes/modelvalue.spec.hsp b/test/rt/attributes/modelvalue.spec.hsp index c417631..888abfa 100644 --- a/test/rt/attributes/modelvalue.spec.hsp +++ b/test/rt/attributes/modelvalue.spec.hsp @@ -70,53 +70,53 @@ describe("Input Elements", function () { } }; var n = enterEmptiesFieldSample(object); - var input1 = n.childNodes[2]; - var input2 = n.childNodes[4]; + var input1 = n.node.querySelectorAll("input")[0]; + var input2 = n.node.querySelectorAll("input")[1]; - expect(input1.node.value).to.equal(v1); - expect(input2.node.value).to.equal(v1); + expect(input1.value).to.equal(v1); + expect(input2.value).to.equal(v1); // test with input 1 var v2 = "new value"; - input1.node.value = v2; - fireEvent("keydown", input1.node); - fireEvent("keyup", input1.node); + input1.value = v2; + fireEvent("keydown", input1); + fireEvent("keyup", input1); hsp.refresh(); expect(object.value).to.equal(v2); - expect(input1.node.value).to.equal(v2); - expect(input2.node.value).to.equal(v2); + expect(input1.value).to.equal(v2); + expect(input2.value).to.equal(v2); expect(enterKeyDownCalled).to.equal(0); - fireEvent("keydown", input1.node, {keyCode: 13}); - fireEvent("keyup", input1.node, {keyCode: 13}); + fireEvent("keydown", input1, {keyCode: 13}); + fireEvent("keyup", input1, {keyCode: 13}); expect(enterKeyDownCalled).to.equal(1); hsp.refresh(); expect(object.value).to.equal(""); - expect(input1.node.value).to.equal(""); - expect(input2.node.value).to.equal(""); + expect(input1.value).to.equal(""); + expect(input2.value).to.equal(""); // test with input 2 var v3 = "other value"; - input2.node.value = v3; - fireEvent("keydown", input2.node); - fireEvent("keyup", input2.node); + input2.value = v3; + fireEvent("keydown", input2); + fireEvent("keyup", input2); hsp.refresh(); expect(object.value).to.equal(v3); - expect(input1.node.value).to.equal(v3); - expect(input2.node.value).to.equal(v3); + expect(input1.value).to.equal(v3); + expect(input2.value).to.equal(v3); expect(enterKeyDownCalled).to.equal(1); - fireEvent("keydown", input2.node, {keyCode: 13}); - fireEvent("keyup", input2.node, {keyCode: 13}); + fireEvent("keydown", input2, {keyCode: 13}); + fireEvent("keyup", input2, {keyCode: 13}); expect(enterKeyDownCalled).to.equal(2); hsp.refresh(); expect(object.value).to.equal(""); - expect(input1.node.value).to.equal(""); - expect(input2.node.value).to.equal(""); + expect(input1.value).to.equal(""); + expect(input2.value).to.equal(""); }); it("validates text elements", function () { @@ -128,33 +128,33 @@ describe("Input Elements", function () { }; var n = inputSample(d); - var input1 = n.childNodes[1].childNodes[1]; - var input2 = n.childNodes[1].childNodes[4]; + var input1 = n.node.querySelectorAll("input")[0]; + var input2 = n.node.querySelectorAll("input")[1]; - expect(input1.node.value).to.equal(v1); - expect(input2.node.value).to.equal(v1); + expect(input1.value).to.equal(v1); + expect(input2.value).to.equal(v1); // change value from the model var v2 = "foo"; json.set(d, "comment", v2); hsp.refresh(); - expect(input1.node.value).to.equal(v2); - expect(input2.node.value).to.equal(v2); + expect(input1.value).to.equal(v2); + expect(input2.value).to.equal(v2); // change the value from input1 (value attribute) var v3 = "bar2"; - input1.node.value = v3; - fireEvent("keyup",input1.node); // to simulate change - expect(input1.node.value).to.equal(v3); - expect(input2.node.value).to.equal(v3); + input1.value = v3; + fireEvent("keyup",input1); // to simulate change + expect(input1.value).to.equal(v3); + expect(input2.value).to.equal(v3); expect(d.comment).to.equal(v3); // change the value from input2 (model attribute) var v4 = "blah"; - input2.node.value = v4; - fireEvent("keyup",input2.node); // to simulate change - expect(input1.node.value).to.equal(v4); - expect(input2.node.value).to.equal(v4); + input2.value = v4; + fireEvent("keyup",input2); // to simulate change + expect(input1.value).to.equal(v4); + expect(input2.value).to.equal(v4); expect(d.comment).to.equal(v4); n.$dispose(); @@ -168,33 +168,33 @@ describe("Input Elements", function () { }; var n = inputSample(d); - var cb1 = n.childNodes[2].childNodes[0]; - var cb2 = n.childNodes[2].childNodes[3]; + var cb1 = n.node.querySelector("#cb1"); + var cb2 = n.node.querySelector("#cb2"); // TODO: fix following lines in IE8 - expect(cb1.node.checked).to.equal(true); - expect(cb2.node.checked).to.equal(true); + expect(cb1.checked).to.equal(true); + expect(cb2.checked).to.equal(true); // change from data model json.set(d, "isChecked", false); hsp.refresh(); - expect(cb1.node.checked).to.equal(false); - expect(cb2.node.checked).to.equal(false); + expect(cb1.checked).to.equal(false); + expect(cb2.checked).to.equal(false); expect(d.isChecked).to.equal(false); // change from cb1 (value reference) - fireEvent("click",cb1.node); - if (cb1.node.checked) { + fireEvent("click",cb1); + if (cb1.checked) { // on firefox calling click doesn't trigger the onclick event!? - expect(cb1.node.checked).to.equal(true); - expect(cb2.node.checked).to.equal(true); + expect(cb1.checked).to.equal(true); + expect(cb2.checked).to.equal(true); expect(d.isChecked).to.equal(true); } // change from cb2 (model reference) - fireEvent("click",cb2.node); - expect(cb1.node.checked).to.equal(false); - expect(cb2.node.checked).to.equal(false); + fireEvent("click",cb2); + expect(cb1.checked).to.equal(false); + expect(cb2.checked).to.equal(false); expect(d.isChecked).to.equal(false); n.$dispose(); @@ -208,23 +208,23 @@ describe("Input Elements", function () { }; var n = inputSample(d); - var rb1 = n.childNodes[3].childNodes[0]; - var rb2 = n.childNodes[3].childNodes[3]; + var rb1 = n.node.querySelector("#rb1"); + var rb2 = n.node.querySelector("#rb2"); - expect(rb1.node.checked).to.equal(false); + expect(rb1.checked).to.equal(false); // TODO fix next line in IE8 - expect(rb2.node.checked).to.equal(true); + expect(rb2.checked).to.equal(true); // change from data model json.set(d, "selection", "C"); hsp.refresh(); - expect(rb1.node.checked).to.equal(false); - expect(rb2.node.checked).to.equal(false); + expect(rb1.checked).to.equal(false); + expect(rb2.checked).to.equal(false); // change from rb1 - fireEvent("click",rb1.node); - expect(rb1.node.checked).to.equal(true); - expect(rb2.node.checked).to.equal(false); + fireEvent("click",rb1); + expect(rb1.checked).to.equal(true); + expect(rb2.checked).to.equal(false); expect(d.selection).to.equal("A"); n.$dispose(); diff --git a/test/rt/booleanAttributes.spec.hsp b/test/rt/booleanAttributes.spec.hsp index 23db512..0b97915 100644 --- a/test/rt/booleanAttributes.spec.hsp +++ b/test/rt/booleanAttributes.spec.hsp @@ -16,14 +16,14 @@ describe('boolean attributes', function () { var n = tpl(model); expect(n.node.firstChild.required).to.equal(true); - expect(n.node.childNodes[1].checked).to.equal(false); + expect(n.node.childNodes[2].checked).to.equal(false); // test property change json.set(model, "flag", false); json.set(model, "flag2", true); hsp.refresh(); expect(n.node.firstChild.required).to.equal(false); - expect(n.node.childNodes[1].checked).to.equal(true); + expect(n.node.childNodes[2].checked).to.equal(true); n.$dispose(); }); diff --git a/test/rt/cptbinding.spec.hsp b/test/rt/cptbinding.spec.hsp index a97b530..8eba4c7 100644 --- a/test/rt/cptbinding.spec.hsp +++ b/test/rt/cptbinding.spec.hsp @@ -85,12 +85,12 @@ describe("Component attributes binding", function () { var d={value:2,max:100,defaultvalue:42}; var n=test(d); - expect(n.node.childNodes.length).to.equal(6); // 4+2comments - var cptInput=n.node.childNodes[1]; - var c=n.childNodes[0].controller; - var valueInput=n.node.childNodes[3]; - var maxInput=n.node.childNodes[4]; - var defaultInput=n.node.childNodes[5]; + expect(n.node.childNodes.length).to.equal(13); // 4+2comments+7whitespaces + var cptInput=n.node.childNodes[3]; + var c=n.childNodes[1].controller; + var valueInput=n.node.childNodes[7]; + var maxInput=n.node.childNodes[9]; + var defaultInput=n.node.childNodes[11]; expect(cptInput.value).to.equal("2"); expect(valueInput.value).to.equal("2"); @@ -143,8 +143,8 @@ describe("Component attributes binding", function () { var n=test2(d); checks=[]; - expect(n.node.childNodes.length).to.equal(3); // 1+2comments - var cptInput=n.node.childNodes[1]; + expect(n.node.childNodes.length).to.equal(7); // 1+2comments+4whitespaces + var cptInput=n.node.childNodes[3]; setFieldValue(cptInput,"b"); expect(checks.length).to.equal(1); diff --git a/test/rt/cptwrapper.spec.hsp b/test/rt/cptwrapper.spec.hsp index f0fdc7b..ee88d69 100644 --- a/test/rt/cptwrapper.spec.hsp +++ b/test/rt/cptwrapper.spec.hsp @@ -239,8 +239,8 @@ describe("Component Nodes", function () { it("tests a component template load", function() { var n=nbrfield(); - var textInput=n.node.firstChild; - var button=n.node.childNodes[1]; + var textInput=n.node.childNodes[1]; + var button=n.node.childNodes[3]; expect(textInput.nodeType).to.equal(ELEMENT_NODE); expect(textInput.attributes.type.value).to.equal("text"); expect(textInput.value).to.equal("0"); @@ -281,9 +281,9 @@ it("tests a component inside another template", function() { var d={value:'42'}; var n=test(d); - var textInput=n.node.firstChild; - var cptInput=n.node.childNodes[2]; - var cptButton=n.node.childNodes[3]; + var textInput=n.node.childNodes[1]; + var cptInput=n.node.childNodes[5]; + var cptButton=n.node.childNodes[7]; expect(textInput.value).to.equal('42'); expect(cptInput.value).to.equal('42'); @@ -326,7 +326,7 @@ it("tests a component inside another template", function() { var d={value:'42'}; var n=test(d); - var cptButton=n.node.childNodes[3]; + var cptButton=n.node.childNodes[7]; fireEvent("click",cptButton); hsp.refresh(); @@ -343,7 +343,7 @@ it("tests a component inside another template", function() { isBrCbEmpty=false; var d={value:'42'}; var n=test2(d); - var cptButton=n.node.childNodes[3]; + var cptButton=n.node.childNodes[7]; fireEvent("click",cptButton); hsp.refresh(); diff --git a/test/rt/customAttributes.spec.hsp b/test/rt/customAttributes.spec.hsp index d6bc1cc..7274c31 100644 --- a/test/rt/customAttributes.spec.hsp +++ b/test/rt/customAttributes.spec.hsp @@ -121,14 +121,14 @@ describe("Custom attributes", function () { it("tests a simple custom attribute", function () { var n = test1(); - expect(n.node.firstChild.style.height).to.equal("100px"); + expect(n.node.childNodes[1].style.height).to.equal("100px"); n.$dispose(); expect(status).to.equal("Dirty"); }); it("tests a custom attribute with static value", function () { var n = test2(); - expect(n.node.firstChild.style.height).to.equal("50px"); + expect(n.node.childNodes[1].style.height).to.equal("50px"); n.$dispose(); expect(status).to.equal("Dirty"); }); @@ -138,10 +138,10 @@ describe("Custom attributes", function () { myHeight: 25 }; var n = test3(ctl); - expect(n.node.firstChild.style.height).to.equal("25px"); + expect(n.node.childNodes[1].style.height).to.equal("25px"); $set(ctl, "myHeight", 90); hsp.refresh(); - expect(n.node.firstChild.style.height).to.equal("90px"); + expect(n.node.childNodes[1].style.height).to.equal("90px"); n.$dispose(); expect(status).to.equal("Dirty"); }); @@ -162,11 +162,11 @@ describe("Custom attributes", function () { myHeight: 25 }; var n = test3(ctl); - expect(n.node.firstChild.className).to.equal(""); + expect(n.node.childNodes[1].className).to.equal(""); expect(handleAttributeCount).to.equal(1); $set(ctl, "isActive", true); hsp.refresh(); - expect(n.node.firstChild.className).to.equal("active"); + expect(n.node.childNodes[1].className).to.equal("active"); expect(handleAttributeCount).to.equal(1); n.$dispose(); expect(status).to.equal("Dirty"); @@ -174,7 +174,7 @@ describe("Custom attributes", function () { it("tests several custom attributes on same node", function () { var n = test4(); - expect(n.node.firstChild.style.height).to.equal("100px"); + expect(n.node.childNodes[1].style.height).to.equal("100px"); n.$dispose(); expect(status).to.equal("Dirty"); }); @@ -183,8 +183,8 @@ describe("Custom attributes", function () { handlerCreationCount = 0; var n = test6(); expect(handlerCreationCount).to.equal(1); - expect(n.node.firstChild.style.height).to.equal("50px"); - expect(n.node.firstChild.style.width).to.equal("100px"); + expect(n.node.childNodes[1].style.height).to.equal("50px"); + expect(n.node.childNodes[1].style.width).to.equal("100px"); n.$dispose(); expect(status).to.equal("Dirty"); }); @@ -200,7 +200,7 @@ describe("Custom attributes", function () { it("tests a simple custom attribute with several handlers", function () { hsp.registerCustomAttributes("verybigdiv", customHandler2, 1); var n = test1(); - expect(n.node.firstChild.style.height).to.equal("90px"); + expect(n.node.childNodes[1].style.height).to.equal("90px"); n.$dispose(); expect(status).to.equal("Clean"); }); diff --git a/test/rt/elt.spec.hsp b/test/rt/elt.spec.hsp index 417c85a..0a0ff46 100644 --- a/test/rt/elt.spec.hsp +++ b/test/rt/elt.spec.hsp @@ -79,16 +79,16 @@ describe("Element Nodes", function () { it("tests a simple div with text and bound data on text content", function() { var dm={name:"Omer"}; var n=test1(dm); - expect(n.node.firstChild.nodeType).to.equal(ELEMENT_NODE); - expect(n.node.firstChild.attributes.title.value).to.equal("test1"); - expect(n.node.firstChild.firstChild.nodeType).to.equal(TEXT_NODE); - expect(n.node.firstChild.firstChild.nodeValue).to.equal("Hello Omer! "); + expect(n.node.childNodes[1].nodeType).to.equal(ELEMENT_NODE); + expect(n.node.childNodes[1].attributes.title.value).to.equal("test1"); + expect(n.node.childNodes[1].firstChild.nodeType).to.equal(TEXT_NODE); + expect(n.node.childNodes[1].firstChild.nodeValue.trim()).to.equal("Hello Omer!"); // test property change json.set(dm,"name","Marge"); hsp.refresh(); - expect(n.node.firstChild.firstChild.nodeValue).to.equal("Hello Marge! "); + expect(n.node.childNodes[1].firstChild.nodeValue.trim()).to.equal("Hello Marge!"); n.$dispose(); }); @@ -97,15 +97,15 @@ describe("Element Nodes", function () { var dm={idx:1, firstName:"Omer", lastName:"Simpson", gender:"male", ffNbr:1234567890, ffLevel:"platinum"}; var n=test2(dm); - expect(n.node.firstChild.nodeName).to.equal("DIV"); - expect(n.node.firstChild.attributes["class"].value).to.equal("t2 male"); - expect(n.node.firstChild.attributes["tabIndex"].value).to.equal("1"); - expect(n.node.firstChild.childNodes[0].nodeName).to.equal("#text"); - expect(n.node.firstChild.childNodes[0].nodeValue).to.equal("Omer / Simpson [ "); - expect(n.node.firstChild.childNodes[1].nodeName).to.equal("SPAN"); - expect(n.node.firstChild.childNodes[1].attributes["class"].value).to.equal("platinum"); - expect(n.node.firstChild.childNodes[1].firstChild.nodeValue).to.equal("Frequent flyer #: 1234567890 "); - expect(n.node.firstChild.childNodes[2].nodeValue).to.equal(" ] "); + expect(n.node.childNodes[1].nodeName).to.equal("DIV"); + expect(n.node.childNodes[1].attributes["class"].value).to.equal("t2 male"); + expect(n.node.childNodes[1].attributes["tabIndex"].value).to.equal("1"); + expect(n.node.childNodes[1].childNodes[0].nodeName).to.equal("#text"); + expect(n.node.childNodes[1].childNodes[0].nodeValue).to.equal("\n Omer / Simpson \n [ "); + expect(n.node.childNodes[1].childNodes[1].nodeName).to.equal("SPAN"); + expect(n.node.childNodes[1].childNodes[1].attributes["class"].value).to.equal("platinum"); + expect(n.node.childNodes[1].childNodes[1].firstChild.nodeValue.trim()).to.equal("Frequent flyer #: 1234567890"); + expect(n.node.childNodes[1].childNodes[2].nodeValue).to.equal(" ]\n "); json.set(dm,"firstName","Marge"); json.set(dm,"gender","female"); @@ -113,12 +113,12 @@ describe("Element Nodes", function () { json.set(dm,"ffNbr",1112223330); hsp.refresh(); - expect(n.node.firstChild.attributes["class"].value).to.equal("t2 female"); - expect(n.node.firstChild.attributes["tabIndex"].value).to.equal("1"); - expect(n.node.firstChild.childNodes[0].nodeValue).to.equal("Marge / Simpson [ "); - expect(n.node.firstChild.childNodes[1].attributes["class"].value).to.equal("gold"); - expect(n.node.firstChild.childNodes[1].firstChild.nodeValue).to.equal("Frequent flyer #: 1112223330 "); - expect(n.node.firstChild.childNodes[2].nodeValue).to.equal(" ] "); + expect(n.node.childNodes[1].attributes["class"].value).to.equal("t2 female"); + expect(n.node.childNodes[1].attributes["tabIndex"].value).to.equal("1"); + expect(n.node.childNodes[1].childNodes[0].nodeValue).to.equal("\n Marge / Simpson \n [ "); + expect(n.node.childNodes[1].childNodes[1].attributes["class"].value).to.equal("gold"); + expect(n.node.childNodes[1].childNodes[1].firstChild.nodeValue.trim()).to.equal("Frequent flyer #: 1112223330"); + expect(n.node.childNodes[1].childNodes[2].nodeValue).to.equal(" ]\n "); n.$dispose(); }); @@ -127,10 +127,10 @@ describe("Element Nodes", function () { var dm={idx:1, firstName:"Omer", lastName:"Simpson", gender:"male", ffNbr:1234567890, ffLevel:"platinum"}; var n=test2(dm); - var n0=n.childNodes[0]; - var n00=n.childNodes[0].childNodes[0]; - var n01=n.childNodes[0].childNodes[1]; - var n010=n.childNodes[0].childNodes[1].childNodes[0]; + var n0=n.childNodes[1]; + var n00=n.childNodes[1].childNodes[0]; + var n01=n.childNodes[1].childNodes[1]; + var n010=n.childNodes[1].childNodes[1].childNodes[0]; // TODO n.$dispose(); @@ -142,23 +142,23 @@ describe("Element Nodes", function () { // check that generator tree still works and is not impacted by the instance disposal n=test2(dm); - expect(n.node.firstChild.attributes["class"].value).to.equal("t2 male"); - expect(n.node.firstChild.attributes["tabIndex"].value).to.equal("1"); - expect(n.node.firstChild.childNodes[0].nodeValue).to.equal("Omer / Simpson [ "); - expect(n.node.firstChild.childNodes[1].attributes["class"].value).to.equal("platinum"); - expect(n.node.firstChild.childNodes[1].firstChild.nodeValue).to.equal("Frequent flyer #: 1234567890 "); - expect(n.node.firstChild.childNodes[2].nodeValue).to.equal(" ] "); + expect(n.node.childNodes[1].attributes["class"].value).to.equal("t2 male"); + expect(n.node.childNodes[1].attributes["tabIndex"].value).to.equal("1"); + expect(n.node.childNodes[1].childNodes[0].nodeValue).to.equal("\n Omer / Simpson \n [ "); + expect(n.node.childNodes[1].childNodes[1].attributes["class"].value).to.equal("platinum"); + expect(n.node.childNodes[1].childNodes[1].firstChild.nodeValue.trim()).to.equal("Frequent flyer #: 1234567890"); + expect(n.node.childNodes[1].childNodes[2].nodeValue).to.equal(" ]\n "); n.$dispose(); }); it("tests the EltNode with an empty data model", function() { var n=test2(); - expect(n.node.firstChild.attributes["class"].value).to.equal("t2"); - expect(n.node.firstChild.childNodes[0].nodeValue).to.equal(" / [ "); + expect(n.node.childNodes[1].attributes["class"].value).to.equal("t2"); + expect(n.node.childNodes[1].childNodes[0].nodeValue).to.equal("\n / \n [ "); //expect(n.node.firstChild.childNodes[1].attributes["class"].value).to.equal(""); - expect(n.node.firstChild.childNodes[1].firstChild.nodeValue).to.equal("Frequent flyer #: "); - expect(n.node.firstChild.childNodes[2].nodeValue).to.equal(" ] "); + expect(n.node.childNodes[1].childNodes[1].firstChild.nodeValue).to.equal("\n Frequent flyer #: \n "); + expect(n.node.childNodes[1].childNodes[2].nodeValue).to.equal(" ]\n "); n.$dispose(); }); @@ -175,10 +175,10 @@ describe("Element Nodes", function () { it("validates input value binding", function() { var dm={idx:1, name:"Omer"}; var n=test3(dm); - expect(n.node.firstChild.value).to.equal("Omer"); - n.node.firstChild.value="Marge"; + expect(n.node.childNodes[1].value).to.equal("Omer"); + n.node.childNodes[1].value="Marge"; expect(dm.name).to.equal("Omer"); // doesn't change has not event has been triggered - fireEvent("click",n.node.firstChild); + fireEvent("click",n.node.childNodes[1]); expect(dm.name).to.equal("Marge"); n.$dispose(); @@ -187,10 +187,10 @@ describe("Element Nodes", function () { it("validates input value binding for literal data reference", function() { globalObject.value="Omer"; var n=test4(); - expect(n.node.firstChild.value).to.equal("Omer"); - n.node.firstChild.value="Marge"; + expect(n.node.childNodes[1].value).to.equal("Omer"); + n.node.childNodes[1].value="Marge"; expect(globalObject.value).to.equal("Omer"); // doesn't change has not event has been triggered - fireEvent("click",n.node.firstChild); + fireEvent("click",n.node.childNodes[1]); expect(globalObject.value).to.equal("Marge"); n.$dispose(); diff --git a/test/rt/evthandler.spec.hsp b/test/rt/evthandler.spec.hsp index 7461939..27385c0 100644 --- a/test/rt/evthandler.spec.hsp +++ b/test/rt/evthandler.spec.hsp @@ -52,12 +52,12 @@ function doClick (str, evt) { describe("Event Handlers", function () { function test2SpanNode (n, idx) { - return n.node.childNodes[1 + idx * 3 + 1]; + return n.node.childNodes[1 + idx * 5 + 1 + 1]; } function test2SpanValue (n, idx) { // return the value of the text node in the span - return test2SpanNode(n, idx).childNodes[0].nodeValue; + return test2SpanNode(n, idx).childNodes[0].nodeValue.trim(); } it("tests a simple event handler", function () { @@ -73,10 +73,10 @@ describe("Event Handlers", function () { } }; var n = test1(dm, ctl); - expect(n.node.firstChild.firstChild.nodeValue).to.equal("Hello Omer! "); + expect(n.node.childNodes[1].childNodes[0].nodeValue.trim()).to.equal("Hello Omer!"); expect(count).to.equal(0); - fireEvent("click",n.node.firstChild); + fireEvent("click",n.node.childNodes[1]); expect(count).to.equal(1); expect(lastArg).to.equal(undefined); @@ -102,8 +102,8 @@ describe("Event Handlers", function () { var ds = ["Omer", "Marge", "Bart", "Lisa", "Maggie"]; var n = test2("index", ds, ctl); - expect(test2SpanValue(n, 1)).to.equal("index 1: Marge "); - expect(test2SpanValue(n, 3)).to.equal("index 3: Lisa "); + expect(test2SpanValue(n, 1)).to.equal("index 1: Marge"); + expect(test2SpanValue(n, 3)).to.equal("index 3: Lisa"); expect(count).to.equal(0); fireEvent("click",test2SpanNode(n, 1)); @@ -131,10 +131,10 @@ describe("Event Handlers", function () { }; var n = test3(dm); - expect(n.node.firstChild.firstChild.nodeValue).to.equal("Hello Omer! "); + expect(n.node.childNodes[1].childNodes[0].nodeValue.trim()).to.equal("Hello Omer!"); expect(doClickCount).to.equal(0); - fireEvent("click",n.node.firstChild); + fireEvent("click",n.node.childNodes[1]); expect(doClickCount).to.equal(1); expect(doClickStrArg).to.equal("blah"); diff --git a/test/rt/filescope.spec.hsp b/test/rt/filescope.spec.hsp index d0a937b..d132bf0 100644 --- a/test/rt/filescope.spec.hsp +++ b/test/rt/filescope.spec.hsp @@ -38,7 +38,7 @@ describe("Templates using expressions with global references", function () { it("should actually access the reference", function () { var h = ht.newTestContext(); test1().render(h.container); - expect(h.container.childNodes[1].innerHTML).to.equal("I am here because of a global helper"); + expect(h.container.childNodes[2].innerHTML).to.equal("I am here because of a global helper"); h.$dispose(); }); diff --git a/test/rt/fnexpressions.spec.hsp b/test/rt/fnexpressions.spec.hsp index 1677694..942c33c 100644 --- a/test/rt/fnexpressions.spec.hsp +++ b/test/rt/fnexpressions.spec.hsp @@ -174,7 +174,7 @@ describe("Function expressions", function () { // trigger if h.$set(d,"showEndText",true); - expect(h(C).text()).to.equal("[hello earth]! *123*"); + expect(h(C).text()).to.equal("[hello earth]!\n *123*"); h.$dispose(); }); diff --git a/test/rt/foreach.spec.hsp b/test/rt/foreach.spec.hsp index 883a695..89180ad 100644 --- a/test/rt/foreach.spec.hsp +++ b/test/rt/foreach.spec.hsp @@ -52,16 +52,16 @@ var hsp=require("hsp/rt"), @@ -175,7 +175,7 @@ var Sorter=klass({ describe("ForEach Node", function () { function test1Count (arrayLength) { // return number of items produced by test 1 - return 1 + arrayLength * 5 + 1 + 1; + return 1 + arrayLength * 7 + 1 + 1; } function test1SpanValue (n, idx) { @@ -185,7 +185,7 @@ describe("ForEach Node", function () { function test1SpanNodeValue (node, idx) { // return the value of the text node in the span - return node.childNodes[1 + idx * 5 + 1].childNodes[0].nodeValue; + return node.childNodes[1 + idx * 7 + 1 + 1].childNodes[0].nodeValue.trim(); } function test2Count (arrayLength) { @@ -214,12 +214,12 @@ describe("ForEach Node", function () { var elt = doc.createElement("div"); n.render(elt); - expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Marge (5 chars) "); - expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Lisa (4 chars) "); - expect(elt.childNodes[1 + 4 * 5 + 3].nodeValue).to.equal("Number of items: 5 "); // last if content + expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Marge (5 chars)"); + expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Lisa (4 chars)"); + expect(elt.childNodes[1 + 4 * 7 + 5].nodeValue.trim()).to.equal("Number of items: 5"); // last if content - var nd = n.childNodes[0].childNodes[2].childNodes[0].childNodes[0]; // text node for Bart - expect(nd.node.nodeValue).to.equal("index 2: Bart (4 chars) "); + var nd = n.childNodes[0].childNodes[2].childNodes[1].childNodes[0]; // text node for Bart + expect(nd.node.nodeValue.trim()).to.equal("index 2: Bart (4 chars)"); n.$dispose(); expect(nd.node).to.equal(null); @@ -229,14 +229,14 @@ describe("ForEach Node", function () { var ds = ["Omer", "Marge", "Bart", "Lisa", "Maggie"]; var n = test1("index", ds); - expect(n.node.childNodes.length).to.equal(1 + 5 * 5 + 1 + 1); - expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars) "); + expect(n.node.childNodes.length).to.equal(1 + 5 * 7 + 1 + 1); + expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars)"); var idx = n.childNodes[0].deleteItem(1); hsp.refresh(); - expect(n.node.childNodes.length).to.equal(1 + 4 * 5 + 1 + 1); - expect(idx).to.equal(1 + 5 - 1); - expect(test1SpanValue(n, 1)).to.equal("index 1: Bart (4 chars) "); + expect(n.node.childNodes.length).to.equal(1 + 4 * 7 + 1 + 1); + expect(idx).to.equal(1 + 7 - 1); + expect(test1SpanValue(n, 1)).to.equal("index 1: Bart (4 chars)"); n.$dispose(); }); @@ -252,19 +252,19 @@ describe("ForEach Node", function () { hsp.refresh(); // new displayed array: ["Omer","Lisa","Marge","Bart","Maggie"] expect(n.node.childNodes.length).to.equal(test1Count(5)); - expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Lisa (4 chars) "); - expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Marge (5 chars) "); - expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Bart (4 chars) "); + expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Lisa (4 chars)"); + expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Marge (5 chars)"); + expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Bart (4 chars)"); n.childNodes[0].moveItem(0, 4); // Omer should replace Maggie hsp.refresh(); // new displayed array: ["Lisa","Marge","Bart","Maggie","Omer"] expect(n.childNodes[0].childNodes.length).to.equal(5); expect(n.node.childNodes.length).to.equal(test1Count(5)); - expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Lisa (4 chars) "); - expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Marge (5 chars) "); - expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Maggie (6 chars) "); - expect(test1SpanNodeValue(elt, 4)).to.equal("index 4: Omer (4 chars) "); + expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Lisa (4 chars)"); + expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Marge (5 chars)"); + expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Maggie (6 chars)"); + expect(test1SpanNodeValue(elt, 4)).to.equal("index 4: Omer (4 chars)"); n.$dispose(); }); @@ -273,14 +273,14 @@ describe("ForEach Node", function () { var ds = ["Omer", "Marge", "Bart", "Lisa", "Maggie"]; var n = test1("index", ds); - expect(test1SpanValue(n, 3)).to.equal("index 3: Lisa (4 chars) "); + expect(test1SpanValue(n, 3)).to.equal("index 3: Lisa (4 chars)"); // item change: ["Omer","Marge","Bart","LISA","Maggie"] json.set(ds, 3, "LISA"); hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(5); expect(n.node.childNodes.length).to.equal(test1Count(5)); - expect(test1SpanValue(n, 3)).to.equal("index 3: LISA (4 chars) "); + expect(test1SpanValue(n, 3)).to.equal("index 3: LISA (4 chars)"); n.$dispose(); }); @@ -297,11 +297,11 @@ describe("ForEach Node", function () { expect(n.childNodes[0].childNodes.length).to.equal(5); expect(n.node.childNodes.length).to.equal(test1Count(5)); - expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanValue(n, 1)).to.equal("index 1: Maggie (6 chars) "); - expect(test1SpanValue(n, 2)).to.equal("index 2: Marge (5 chars) "); - expect(test1SpanValue(n, 3)).to.equal("index 3: LISA (4 chars) "); - expect(test1SpanValue(n, 4)).to.equal("index 4: BART (4 chars) "); + expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanValue(n, 1)).to.equal("index 1: Maggie (6 chars)"); + expect(test1SpanValue(n, 2)).to.equal("index 2: Marge (5 chars)"); + expect(test1SpanValue(n, 3)).to.equal("index 3: LISA (4 chars)"); + expect(test1SpanValue(n, 4)).to.equal("index 4: BART (4 chars)"); n.$dispose(); }); @@ -316,8 +316,8 @@ describe("ForEach Node", function () { hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(2); expect(n.node.childNodes.length).to.equal(test1Count(2)); - expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars) "); + expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars)"); n.$dispose(); }); @@ -334,10 +334,10 @@ describe("ForEach Node", function () { hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(4); expect(n.node.childNodes.length).to.equal(test1Count(4)); - expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Bart (4 chars) "); - expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Lisa (4 chars) "); - expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Marge (5 chars) "); + expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Bart (4 chars)"); + expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Lisa (4 chars)"); + expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Marge (5 chars)"); n.$dispose(); }); @@ -351,9 +351,9 @@ describe("ForEach Node", function () { hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(3); expect(n.node.childNodes.length).to.equal(test1Count(3)); - expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars) "); - expect(test1SpanValue(n, 2)).to.equal("index 2: Bart (4 chars) "); + expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars)"); + expect(test1SpanValue(n, 2)).to.equal("index 2: Bart (4 chars)"); n.$dispose(); }); @@ -370,16 +370,16 @@ describe("ForEach Node", function () { hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(4); expect(n.node.childNodes.length).to.equal(test1Count(4)); - expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Bart (4 chars) "); - expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Lisa (4 chars) "); - expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Marge (5 chars) "); - expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Maggie (6 chars) "); + expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Bart (4 chars)"); + expect(test1SpanNodeValue(elt, 1)).to.equal("index 1: Lisa (4 chars)"); + expect(test1SpanNodeValue(elt, 2)).to.equal("index 2: Marge (5 chars)"); + expect(test1SpanNodeValue(elt, 3)).to.equal("index 3: Maggie (6 chars)"); ds.shift(); hsp.refresh(); expect(n.childNodes[0].childNodes.length).to.equal(3); expect(n.node.childNodes.length).to.equal(test1Count(3)); - expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Lisa (4 chars) "); + expect(test1SpanNodeValue(elt, 0)).to.equal("index 0: Lisa (4 chars)"); n.$dispose(); }); @@ -390,8 +390,8 @@ describe("ForEach Node", function () { expect(n.childNodes[0].childNodes.length).to.equal(2); expect(n.node.childNodes.length).to.equal(test1Count(2) - 1); - expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars) "); + expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars)"); n.$dispose(); }); @@ -404,9 +404,9 @@ describe("ForEach Node", function () { expect(n.childNodes[0].childNodes.length).to.equal(3); expect(n.node.childNodes.length).to.equal(test1Count(3)); - expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars) "); - expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars) "); - expect(test1SpanValue(n, 2)).to.equal("index 2: Lisa (4 chars) "); + expect(test1SpanValue(n, 0)).to.equal("index 0: Omer (4 chars)"); + expect(test1SpanValue(n, 1)).to.equal("index 1: Marge (5 chars)"); + expect(test1SpanValue(n, 2)).to.equal("index 2: Lisa (4 chars)"); n.$dispose(); }); @@ -427,19 +427,19 @@ describe("ForEach Node", function () { expect(n.childNodes[0].childNodes.length).to.equal(3); expect(n.node.childNodes.length).to.equal(test2Count(3)); - expect(test2NodeValue(n, 0, 1)).to.equal("Person #0: Omer Simpson "); - expect(test2NodeValue(n, 0, 3)).to.equal("(first) "); - expect(test2NodeValue(n, 1, 1)).to.equal("Person #1: Marge Simpson "); - expect(test2NodeValue(n, 2, 1)).to.equal("Person #2: Bart Simpson "); + expect(test2NodeValue(n, 0, 1)).to.equal(" Person #0: Omer Simpson\n"); + expect(test2NodeValue(n, 0, 3)).to.equal(" (first)\n"); + expect(test2NodeValue(n, 1, 1)).to.equal(" Person #1: Marge Simpson\n"); + expect(test2NodeValue(n, 2, 1)).to.equal(" Person #2: Bart Simpson\n"); // test dynamic update json.set(ds.persons[1], "lastName", "SIMPSON"); hsp.refresh(); expect(n.node.childNodes.length).to.equal(test2Count(3)); - expect(test2NodeValue(n, 0, 1)).to.equal("Person #0: Omer Simpson "); - expect(test2NodeValue(n, 1, 1)).to.equal("Person #1: Marge SIMPSON "); - expect(test2NodeValue(n, 2, 1)).to.equal("Person #2: Bart Simpson "); + expect(test2NodeValue(n, 0, 1)).to.equal(" Person #0: Omer Simpson\n"); + expect(test2NodeValue(n, 1, 1)).to.equal(" Person #1: Marge SIMPSON\n"); + expect(test2NodeValue(n, 2, 1)).to.equal(" Person #2: Bart Simpson\n"); n.$dispose(); }); @@ -471,12 +471,12 @@ describe("ForEach Node", function () { hsp.refresh(); expect(n.node.childNodes.length).to.equal(test2Count(4)); - expect(test2NodeValue(n, 0, 1)).to.equal("Person #0: Omer Simpson "); - expect(test2NodeValue(n, 0, 3)).to.equal("(first) "); - expect(test2NodeValue(n, 1, 1)).to.equal("Person #1: Bart Simpson "); - expect(test2NodeValue(n, 2, 1)).to.equal("Person #2: Lisa SIMPSON "); - expect(test2NodeValue(n, 3, 1)).to.equal("Person #3: Maggie S "); - expect(test2NodeValue(n, 3, 5)).to.equal("(last) "); + expect(test2NodeValue(n, 0, 1)).to.equal(" Person #0: Omer Simpson\n"); + expect(test2NodeValue(n, 0, 3)).to.equal(" (first)\n"); + expect(test2NodeValue(n, 1, 1)).to.equal(" Person #1: Bart Simpson\n"); + expect(test2NodeValue(n, 2, 1)).to.equal(" Person #2: Lisa SIMPSON\n"); + expect(test2NodeValue(n, 3, 1)).to.equal(" Person #3: Maggie S\n"); + expect(test2NodeValue(n, 3, 5)).to.equal(" (last)\n"); n.$dispose(); }); @@ -507,10 +507,10 @@ describe("ForEach Node", function () { json.set(ds, "persons", ds2); hsp.refresh(); expect(n.node.childNodes.length).to.equal(test2Count(2)); - expect(test2NodeValue(n, 0, 1)).to.equal("Person #0: Fred Astaire "); - expect(test2NodeValue(n, 0, 3)).to.equal("(first) "); - expect(test2NodeValue(n, 1, 1)).to.equal("Person #1: Ginger Rogers "); - expect(test2NodeValue(n, 1, 5)).to.equal("(last) "); + expect(test2NodeValue(n, 0, 1)).to.equal(" Person #0: Fred Astaire\n"); + expect(test2NodeValue(n, 0, 3)).to.equal(" (first)\n"); + expect(test2NodeValue(n, 1, 1)).to.equal(" Person #1: Ginger Rogers\n"); + expect(test2NodeValue(n, 1, 5)).to.equal(" (last)\n"); n.$dispose(); }); @@ -529,7 +529,7 @@ describe("ForEach Node", function () { hsp.refresh(); expect(elt.childNodes.length).to.equal(8); - expect(elt.childNodes[5].nodeValue).to.equal("mangos "); + expect(elt.childNodes[5].nodeValue).to.equal(" mangos\n"); }); it("tests splice with nested ifs in a foreach loop", function () { @@ -540,8 +540,8 @@ describe("ForEach Node", function () { var elt = doc.createElement("div"); n.render(elt); - var str1 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+and last +# /if+# /if+BB ++# /item+# /foreach"; - var str2 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+then +# /if+# /if+CC ++# /item+# item+# if+# if+and last +# /if+# /if+BB ++# /item+# /foreach"; + var str1 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+BB\n++\n+# /item+# /foreach"; + var str2 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+CC\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+BB\n++\n+# /item+# /foreach"; var r = domToString(elt); expect(r).to.equal(str1); @@ -562,10 +562,10 @@ describe("ForEach Node", function () { var elt = doc.createElement("div"); n.render(elt); - var str1 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+and last +# /if+# /if+BB ++# /item+# /foreach"; - var str2 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+then +# /if+# /if+BB ++# /item+# item+# if+# if+and last +# /if+# /if+CC ++# /item+# /foreach"; - var str3 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+then +# /if+# /if+BB ++# /item+# item+# if+# if+then +# /if+# /if+CC ++# /item+# item+# if+# if+and last +# /if+# /if+DD ++# /item+# /foreach"; - var str4 = "# foreach+# item+# if+First +# /if+AA ++# /item+# item+# if+# if+then +# /if+# /if+A2 ++# /item+# item+# if+# if+then +# /if+# /if+BB ++# /item+# item+# if+# if+then +# /if+# /if+CC ++# /item+# item+# if+# if+and last +# /if+# /if+DD ++# /item+# /foreach"; + var str1 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+BB\n++\n+# /item+# /foreach"; + var str2 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+BB\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+CC\n++\n+# /item+# /foreach"; + var str3 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+BB\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+CC\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+DD\n++\n+# /item+# /foreach"; + var str4 = "# foreach+# item+# if+First\n+# /if+AA\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+A2\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+BB\n++\n+# /item+# item+# if+# if+then\n+# /if+# /if+CC\n++\n+# /item+# item+# if+# if+and last\n+# /if+# /if+DD\n++\n+# /item+# /foreach"; var r = domToString(elt); expect(r).to.equal(str1); @@ -598,7 +598,7 @@ describe("ForEach Node", function () { var n = test5(ds); expect(n.node.childNodes.length).to.equal(5); - expect(n.node.childNodes[2].nodeValue).to.equal("Omer "); + expect(n.node.childNodes[2].nodeValue).to.equal(" Omer\n"); ds.splice(0, 1); hsp.refresh(); @@ -609,7 +609,7 @@ describe("ForEach Node", function () { }]); hsp.refresh(); expect(n.node.childNodes.length).to.equal(5); - expect(n.node.childNodes[2].nodeValue).to.equal("Marge "); + expect(n.node.childNodes[2].nodeValue).to.equal(" Marge\n"); ds.splice(0, 1); hsp.refresh(); diff --git a/test/rt/if.spec.hsp b/test/rt/if.spec.hsp index 61e5a4b..a5d3ce4 100644 --- a/test/rt/if.spec.hsp +++ b/test/rt/if.spec.hsp @@ -76,12 +76,12 @@ describe("If Node", function () { expect(n.node.firstChild.nodeType).to.equal(COMMENT_NODE); expect(n.node.firstChild.nodeValue).to.equal("# if"); expect(n.node.childNodes.length).to.equal(3); - expect(n.node.childNodes[1].nodeValue).to.equal("Hello Omer "); + expect(n.node.childNodes[1].nodeValue).to.equal(" Hello Omer\n"); // change first name and check update json.set(dm, "firstName", "Marge"); hsp.refresh(); - expect(n.node.childNodes[1].nodeValue).to.equal("Hello Marge "); + expect(n.node.childNodes[1].nodeValue).to.equal(" Hello Marge\n"); json.set(dm, "firstName", null); hsp.refresh(); @@ -97,22 +97,22 @@ describe("If Node", function () { }; var n = test2(dm); - expect(n.node.childNodes[1].nodeName).to.equal("H2"); - expect(n.node.childNodes[1].firstChild.nodeValue).to.equal("Hello Omer"); - expect(n.node.childNodes.length).to.equal(5); - expect(n.node.childNodes[3].nodeName).to.equal("#comment"); + expect(n.node.childNodes[2].nodeName).to.equal("H2"); + expect(n.node.childNodes[2].firstChild.nodeValue).to.equal("Hello Omer"); + expect(n.node.childNodes.length).to.equal(7); + expect(n.node.childNodes[6].nodeName).to.equal("#comment"); json.set(dm, "favouriteDish", "Donuts"); hsp.refresh(); - expect(n.node.childNodes.length).to.equal(6); - expect(n.node.childNodes[3].nodeName).to.equal("SPAN"); - expect(n.node.childNodes[3].firstChild.nodeValue).to.equal("Your preferred dish: Donuts"); + expect(n.node.childNodes.length).to.equal(10); + expect(n.node.childNodes[6].nodeName).to.equal("SPAN"); + expect(n.node.childNodes[6].firstChild.nodeValue).to.equal("Your preferred dish: Donuts"); json.set(dm, "firstName", null); hsp.refresh(); - expect(n.node.childNodes.length).to.equal(3); - expect(n.node.childNodes[1].nodeName).to.equal("DIV"); - expect(n.node.childNodes[1].firstChild.nodeValue).to.equal("Hello Simpson "); + expect(n.node.childNodes.length).to.equal(5); + expect(n.node.childNodes[2].nodeName).to.equal("DIV"); + expect(n.node.childNodes[2].firstChild.nodeValue).to.equal("\n Hello Simpson\n "); n.$dispose(); }); @@ -125,8 +125,8 @@ describe("If Node", function () { }; var n = test2(dm); - var n1 = n.childNodes[0].childNodes[0]; - var n2 = n.childNodes[0].childNodes[1].childNodes[0]; + var n1 = n.childNodes[0].childNodes[1]; + var n2 = n.childNodes[0].childNodes[3].childNodes[1]; expect(n1.tag).to.equal("h2"); expect(n1.node).not.to.equal(null); expect(n2.tag).to.equal("span"); @@ -136,13 +136,13 @@ describe("If Node", function () { json.set(dm, "firstName", null); hsp.refresh(); expect(n1.node).to.equal(null); - expect(n.childNodes[0].childNodes[0].tag).to.equal("div"); + expect(n.childNodes[0].childNodes[1].tag).to.equal("div"); expect(n2.node).to.equal(null); json.set(dm, "firstName", "Marge"); hsp.refresh(); - expect(n.childNodes[0].childNodes[0].tag).to.equal("h2"); - n2 = n.childNodes[0].childNodes[1].childNodes[0]; + expect(n.childNodes[0].childNodes[1].tag).to.equal("h2"); + n2 = n.childNodes[0].childNodes[3].childNodes[1]; expect(n2.node).not.to.equal(null); n.$dispose(); @@ -161,7 +161,7 @@ describe("If Node", function () { var ch1 = n.childNodes[1]; var ch2 = n.childNodes[1].childNodes[0]; expect(ch1.node).not.to.equal(null); - expect(ch2.node.nodeValue).to.equal("Omer! "); + expect(ch2.node.nodeValue).to.equal(" Omer!\n"); n.$dispose(); expect(n.childNodes).to.equal(null); expect(ch1.node).to.equal(null); @@ -179,7 +179,7 @@ describe("If Node", function () { var ch1 = n.childNodes[1]; var ch2 = n.childNodes[1].childNodes[0]; expect(ch1.node).not.to.equal(null); - expect(ch2.node.nodeValue).to.equal("Omer! "); + expect(ch2.node.nodeValue).to.equal(" Omer!\n"); n.$dispose(); }); @@ -192,7 +192,7 @@ describe("If Node", function () { var if1 = n.childNodes[0]; expect(if1.childNodes.length).to.equal(1); var text1 = if1.childNodes[0]; - expect(text1.node.nodeValue).to.equal("Hello "); + expect(text1.node.nodeValue).to.equal(" Hello\n"); json.set(dm, "value", "foo"); hsp.refresh(); @@ -202,7 +202,7 @@ describe("If Node", function () { hsp.refresh(); expect(if1.childNodes.length).to.equal(1); text1 = if1.childNodes[0]; - expect(text1.node.nodeValue).to.equal("Hello "); + expect(text1.node.nodeValue).to.equal(" Hello\n"); n.$dispose(); }); @@ -213,7 +213,7 @@ describe("If Node", function () { var if1 = n.childNodes[0]; expect(if1.childNodes.length).to.equal(1); var text1 = if1.childNodes[0]; - expect(text1.node.nodeValue).to.equal("Hello "); + expect(text1.node.nodeValue).to.equal(" Hello\n"); n.$dispose(); }); diff --git a/test/rt/let.spec.hsp b/test/rt/let.spec.hsp index 4189917..f7b9a35 100644 --- a/test/rt/let.spec.hsp +++ b/test/rt/let.spec.hsp @@ -71,13 +71,13 @@ describe("Let statement", function () { var h=ht.newTestContext(), d={value:"hello"}; test1(d).render(h.container); - expect(h(".foo").text()).to.equal("Blah hello"); + expect(h(".foo").text()).to.equal("Blah\n hello"); expect(h(".bar").text()).to.equal("hello3AL"); // change value dynamically h.$set(d,"value","salut"); - expect(h(".foo").text()).to.equal("Blah salut"); + expect(h(".foo").text()).to.equal("Blah\n salut"); expect(h(".bar").text()).to.equal("salut3AL"); expect(h.logs().length).to.equal(0); diff --git a/test/rt/subtemplates1.spec.hsp b/test/rt/subtemplates1.spec.hsp index f762b75..6395ae6 100644 --- a/test/rt/subtemplates1.spec.hsp +++ b/test/rt/subtemplates1.spec.hsp @@ -92,8 +92,8 @@ describe("Sub-template insertion", function () { expect(n.childNodes.length).to.equal(3); expect(n.node.childNodes.length).to.equal(5); // 3 + 2 comments - expect(n.node.childNodes[2].nodeValue).to.equal("First Name: Omer"); - expect(tn.node.nodeValue).to.equal("First Name: Omer"); + expect(n.node.childNodes[2].nodeValue).to.equal(" First Name: Omer\n"); + expect(tn.node.nodeValue.trim()).to.equal("First Name: Omer"); n.$dispose(); expect(tn.node).to.equal(null); @@ -106,29 +106,29 @@ describe("Sub-template insertion", function () { }; var n = test2(dm); - expect(n.childNodes.length).to.equal(1); - expect(n.node.childNodes.length).to.equal(11); // 5 + 6 comments - expect(n.node.childNodes[2].nodeValue).to.equal("Last Name: Simpson"); - expect(n.node.childNodes[7].nodeValue).to.equal("First Name: Omer"); + expect(n.childNodes.length).to.equal(3); + expect(n.node.childNodes.length).to.equal(16); // 5 + 6 comments + 5 white spaces + expect(n.node.childNodes[4].nodeValue.trim()).to.equal("Last Name: Simpson"); + expect(n.node.childNodes[10].nodeValue.trim()).to.equal("First Name: Omer"); // update the data model json.set(dm, "firstName", "Marge"); hsp.refresh(); - expect(n.node.childNodes[7].nodeValue).to.equal("First Name: Marge"); + expect(n.node.childNodes[10].nodeValue.trim()).to.equal("First Name: Marge"); json.set(dm, "firstName", null); hsp.refresh(); - expect(n.node.childNodes.length).to.equal(7); // 3 + 4 comments + expect(n.node.childNodes.length).to.equal(11); // 3 + 4 comments json.set(dm, "firstName", "Mickey"); json.set(dm, "lastName", "Mouse"); hsp.refresh(); - expect(n.node.childNodes.length).to.equal(11); - expect(n.node.childNodes[2].nodeValue).to.equal("Last Name: Mouse"); - expect(n.node.childNodes[7].nodeValue).to.equal("First Name: Mickey"); + expect(n.node.childNodes.length).to.equal(16); + expect(n.node.childNodes[4].nodeValue.trim()).to.equal("Last Name: Mouse"); + expect(n.node.childNodes[10].nodeValue.trim()).to.equal("First Name: Mickey"); - var n2 = n.childNodes[0].childNodes[1].childNodes[1].childNodes[0]; - expect(n2.node.nodeValue).to.equal("First Name: Mickey"); + var n2 = n.childNodes[1].childNodes[3].childNodes[1].childNodes[0]; + expect(n2.node.nodeValue.trim()).to.equal("First Name: Mickey"); n.$dispose(); expect(n2.node).to.equal(null); @@ -141,9 +141,9 @@ describe("Sub-template insertion", function () { }; var n = test3(dm, "Always look on the bright side of life"); - expect(n.node.childNodes.length).to.equal(4); // 2 + 2 comments - expect(n.node.childNodes[0].nodeValue).to.equal(" Always look on the bright side of life "); - expect(n.node.childNodes[2].nodeValue).to.equal("Omer: Simpson"); + expect(n.node.childNodes.length).to.equal(5); // 2 + 2 comments + 1 white space + expect(n.node.childNodes[0].nodeValue).to.equal(" Always look on the bright side of life\n "); + expect(n.node.childNodes[2].nodeValue.trim()).to.equal("Omer: Simpson"); n.$dispose(); }); @@ -156,7 +156,7 @@ describe("Sub-template insertion", function () { var n = test4(dm); expect(n.node.childNodes.length).to.equal(1); - expect(n.node.childNodes[0].nodeValue).to.equal("Omer: Simpson"); + expect(n.node.childNodes[0].nodeValue.trim()).to.equal("Omer: Simpson"); n.$dispose(); }); @@ -169,7 +169,7 @@ describe("Sub-template insertion", function () { // is not interpreted as a tag, but as <b> expect(n.node.childNodes.length).to.equal(1); - expect(n.node.childNodes[0].nodeValue).to.equal("Omer: Simpson"); + expect(n.node.childNodes[0].nodeValue.trim()).to.equal("Omer: Simpson"); n.$dispose(); }); @@ -180,12 +180,12 @@ describe("Sub-template insertion", function () { }; var n = test3(dm, "answer is?"); - expect(n.node.childNodes[0].nodeValue).to.equal(" answer is? "); + expect(n.node.childNodes[0].nodeValue).to.equal(" answer is?\n "); n.updateArgument(1, "answer is 42"); hsp.refresh(); - expect(n.node.childNodes[0].nodeValue).to.equal(" answer is 42 "); + expect(n.node.childNodes[0].nodeValue).to.equal(" answer is 42\n "); n.$dispose(); }); @@ -196,7 +196,7 @@ describe("Sub-template insertion", function () { }; var n = test5(dm); - var input = n.node.childNodes[2]; + var input = n.node.querySelector("input"); expect(input.value).to.equal("some text"); input.value = "foo"; @@ -219,7 +219,7 @@ describe("Sub-template insertion", function () { }; var n = test6(dm); - var input = n.node.childNodes[2]; + var input = n.node.querySelector("input"); expect(input.value).to.equal("some text"); input.value = "bar"; @@ -239,7 +239,7 @@ describe("Sub-template insertion", function () { }; var n = test6(dm); - var input = n.node.childNodes[2]; + var input = n.node.querySelector("input"); expect(input.value).to.equal("some text"); // change the whole attributes object, which is a root @@ -259,7 +259,7 @@ describe("Sub-template insertion", function () { }; var n = test7(dm); - var input = n.node.childNodes[2]; + var input = n.node.querySelector("input"); expect(input.value).to.equal("some text"); // change the whole attributes object, which is a root diff --git a/test/rt/subtemplates2.spec.hsp b/test/rt/subtemplates2.spec.hsp index ddaf60c..2458940 100644 --- a/test/rt/subtemplates2.spec.hsp +++ b/test/rt/subtemplates2.spec.hsp @@ -19,46 +19,40 @@ var ht=require("hsp/utils/hashtester"), var C2Controller=klass({ @@ -69,7 +63,7 @@ var C2Controller=klass({ }); var ctxt={ @@ -78,9 +72,7 @@ var ctxt={ } @@ -88,9 +80,7 @@ var ctxt={ {let x=c.a}
{let y=x.b} - Before - - <#y.tpl/> - - After + Before - <#y.tpl/> - After
@@ -100,19 +90,19 @@ describe("Dynamic template insertion", function () { test1(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentA - After"); + expect(h(".content").text()).to.equal("Before - This is contentA \n - After"); // change template dynamically h.$set(c,"tpl",contentB); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentB - After"); + expect(h(".content").text()).to.equal("Before - This is contentB \n - After"); // change template dynamically, again h.$set(c,"tpl",contentC); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentC - After"); + expect(h(".content").text()).to.equal("Before - This is contentC \n - After"); h.$dispose(); }); @@ -122,25 +112,25 @@ describe("Dynamic template insertion", function () { test2(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentA - After"); + expect(h(".content").text()).to.equal("Before - This is contentA \n - After"); // change template dynamically h.$set(c.a.b,"tpl",contentB); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentB - After"); + expect(h(".content").text()).to.equal("Before - This is contentB \n - After"); // change path but not the template h.$set(c.a,"b",{tpl:contentB,foo:"bar"}); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentB - After"); + expect(h(".content").text()).to.equal("Before - This is contentB \n - After"); // change path and template h.$set(c.a,"b",{tpl:contentC,foo:"bar"}); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentC - After"); + expect(h(".content").text()).to.equal("Before - This is contentC \n - After"); h.$dispose(); }); @@ -150,25 +140,25 @@ describe("Dynamic template insertion", function () { test3(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentA2: foo - After"); + expect(h(".content").text()).to.equal("Before - contentA2: foo \n - After"); // change template dynamically h.$set(c,"tpl",contentB2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentB2: foo - After"); + expect(h(".content").text()).to.equal("Before - contentB2: foo \n - After"); // change txt value h.$set(c,"txt","bar"); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentB2: bar - After"); + expect(h(".content").text()).to.equal("Before - contentB2: bar \n - After"); // change template again dynamically h.$set(c,"tpl",contentA2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentA2: bar - After"); + expect(h(".content").text()).to.equal("Before - contentA2: bar \n - After"); h.$dispose(); }); @@ -178,13 +168,13 @@ describe("Dynamic template insertion", function () { test4(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentA - After"); + expect(h(".content").text()).to.equal("Before - This is contentA \n - After"); // change template dynamically h.$set(c,"tpl",contentB2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentB2: hello - After"); + expect(h(".content").text()).to.equal("Before - contentB2: hello \n - After"); h.$dispose(); }); @@ -194,19 +184,19 @@ describe("Dynamic template insertion", function () { test5(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentA - After"); + expect(h(".content").text()).to.equal("Before - This is contentA \n - After"); // change intermediate object in the template path h.$set(c,"a",{b:{tpl:contentB,foo:"bar"}}); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentB - After"); + expect(h(".content").text()).to.equal("Before - This is contentB \n - After"); // change path and template h.$set(c.a,"b",{tpl:contentC,foo:"bar"}); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentC - After"); + expect(h(".content").text()).to.equal("Before - This is contentC \n - After"); h.$dispose(); }); @@ -216,27 +206,27 @@ describe("Dynamic template insertion", function () { test4(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - This is contentA - After"); + expect(h(".content").text()).to.equal("Before - This is contentA \n - After"); // change template to component h.$set(c,"tpl",contentC2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentC2: hello foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello foo \n - After"); h.$set(c,"msg","hello2"); - expect(h(".content").text()).to.equal("Before - contentC2: hello2 foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello2 foo \n - After"); // change component to template h.$set(c,"tpl",contentB2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentB2: hello2 - After"); + expect(h(".content").text()).to.equal("Before - contentB2: hello2 \n - After"); h.$set(c,"msg","hello"); - expect(h(".content").text()).to.equal("Before - contentB2: hello - After"); + expect(h(".content").text()).to.equal("Before - contentB2: hello \n - After"); // change again h.$set(c,"tpl",contentC2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentC2: hello foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello foo \n - After"); h.$dispose(); }); @@ -246,22 +236,22 @@ describe("Dynamic template insertion", function () { test4(c).render(h.container); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentC2: hello foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello foo \n - After"); h.$set(c,"msg","hello2"); - expect(h(".content").text()).to.equal("Before - contentC2: hello2 foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello2 foo \n - After"); // change component to template h.$set(c,"tpl",contentB2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentB2: hello2 - After"); + expect(h(".content").text()).to.equal("Before - contentB2: hello2 \n - After"); h.$set(c,"msg","hello3"); - expect(h(".content").text()).to.equal("Before - contentB2: hello3 - After"); + expect(h(".content").text()).to.equal("Before - contentB2: hello3 \n - After"); // change template to component h.$set(c,"tpl",contentC2); expect(h.logs().length).to.equal(0); - expect(h(".content").text()).to.equal("Before - contentC2: hello3 foo - After"); + expect(h(".content").text()).to.equal("Before - contentC2: hello3 foo \n - After"); h.$dispose(); }); diff --git a/test/rt/text.spec.hsp b/test/rt/text.spec.hsp index 86ff80e..2c7e27c 100644 --- a/test/rt/text.spec.hsp +++ b/test/rt/text.spec.hsp @@ -74,7 +74,7 @@ describe("Text Nodes", function () { it("checks hello world text node - without any parameter", function () { var n = hello1(); expect(n.node.firstChild.nodeType).to.equal(TEXT_NODE); - expect(n.node.firstChild.nodeValue).to.equal("Hello World!"); + expect(n.node.firstChild.nodeValue).to.equal(" Hello World!\n"); n.$dispose(); }); @@ -82,7 +82,7 @@ describe("Text Nodes", function () { var n = hello2({ name : "Alexandre" }); - expect(n.node.firstChild.nodeValue).to.equal("Hello Alexandre!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Alexandre!"); n.$dispose(); }); @@ -91,7 +91,7 @@ describe("Text Nodes", function () { firstName : "Miles", lastName : "Davis" }); - expect(n.node.firstChild.nodeValue).to.equal("Hello Miles Davis!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Miles Davis!"); n.$dispose(); }); @@ -101,15 +101,15 @@ describe("Text Nodes", function () { lastName : "Kahneman" }; var n = hello3(dm); - expect(n.node.firstChild.nodeValue).to.equal("Hello Daniel Kahneman!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Daniel Kahneman!"); json.set(dm, "lastName", "Craig"); - expect(n.node.firstChild.nodeValue).to.equal("Hello Daniel Kahneman!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Daniel Kahneman!"); n.refresh(); - expect(n.node.firstChild.nodeValue).to.equal("Hello Daniel Craig!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Daniel Craig!"); json.set(dm, "firstName", "Mickey"); json.set(dm, "lastName", "Mouse"); n.refresh(); - expect(n.node.firstChild.nodeValue).to.equal("Hello Mickey Mouse!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Mickey Mouse!"); n.$dispose(); }); @@ -125,14 +125,14 @@ describe("Text Nodes", function () { }; var n2 = hello3(dm2); - expect(n1.node.firstChild.nodeValue).to.equal("Hello Daniel Kahneman!"); - expect(n2.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); + expect(n1.node.firstChild.nodeValue.trim()).to.equal("Hello Daniel Kahneman!"); + expect(n2.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); json.set(dm2, "lastName", "Brown"); hsp.refresh(); - expect(n1.node.firstChild.nodeValue).to.equal("Hello Daniel Kahneman!"); - expect(n2.node.firstChild.nodeValue).to.equal("Hello Charles Brown!"); + expect(n1.node.firstChild.nodeValue.trim()).to.equal("Hello Daniel Kahneman!"); + expect(n2.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Brown!"); n1.$dispose(); n2.$dispose(); }); @@ -146,15 +146,15 @@ describe("Text Nodes", function () { var n2 = hello3(dm); var n3 = hello4(dm); - expect(n1.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); - expect(n2.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); - expect(n3.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); + expect(n1.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); + expect(n2.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); + expect(n3.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); json.set(dm, "lastName", "Brown"); hsp.refresh(); - expect(n1.node.firstChild.nodeValue).to.equal("Hello Charles Brown!"); - expect(n2.node.firstChild.nodeValue).to.equal("Hello Charles Brown!"); - expect(n3.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); // unbound case + expect(n1.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Brown!"); + expect(n2.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Brown!"); + expect(n3.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); // unbound case n1.$dispose(); n2.$dispose(); @@ -182,17 +182,17 @@ describe("Text Nodes", function () { // check that generator is not impacted by the $dispose call n = hello3(dm); - expect(n.node.firstChild.nodeValue).to.equal("Hello Charles Darwin!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Darwin!"); json.set(dm, "lastName", "Brown"); hsp.refresh(); - expect(n.node.firstChild.nodeValue).to.equal("Hello Charles Brown!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Charles Brown!"); n.$dispose(); }); it("tests a template with a simple string parameter", function () { var n = hello5("Bart"); - expect(n.node.firstChild.nodeValue).to.equal("Hello Bart!"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Hello Bart!"); n.$dispose(); }); @@ -200,7 +200,7 @@ describe("Text Nodes", function () { globalValue = "blah blah"; var n = hello6(); - expect(n.node.firstChild.nodeValue).to.equal("blah blah"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("blah blah"); n.$dispose(); }); @@ -208,7 +208,7 @@ describe("Text Nodes", function () { globalValueInt = 0; var n = hello9(); - expect(n.node.firstChild.nodeValue).to.equal("0"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("0"); n.$dispose(); }); @@ -219,12 +219,12 @@ describe("Text Nodes", function () { }; var n = hello7(d); - expect(n.node.firstChild.nodeValue).to.equal("Omer-Simpson"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Omer-Simpson"); json.set(d, "firstName", "Marge"); hsp.refresh(); - expect(n.node.firstChild.nodeValue).to.equal("Marge-Simpson"); + expect(n.node.firstChild.nodeValue.trim()).to.equal("Marge-Simpson"); n.$dispose(); });