From 4c4de06ecfffcab6fe78294a1abb2daa8fd7b5c9 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Fri, 27 Jan 2012 07:51:30 -0800 Subject: [PATCH] template and htmljs tests --- tests/unit/client/htmljs_test.js | 6 ++++ tests/unit/client/liveui_test.js | 2 +- tests/unit/client/template_test.html | 35 +++++++++++++++++++++++ tests/unit/client/template_test.js | 42 +++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 tests/unit/client/htmljs_test.js diff --git a/tests/unit/client/htmljs_test.js b/tests/unit/client/htmljs_test.js new file mode 100644 index 0000000000..8377b3490d --- /dev/null +++ b/tests/unit/client/htmljs_test.js @@ -0,0 +1,6 @@ + +test("htmljs", function() { + + // Make sure "style" works, which has to be special-cased for IE. + assert.equal(DIV({style:"display:none"}).style.display, "none"); +}); \ No newline at end of file diff --git a/tests/unit/client/liveui_test.js b/tests/unit/client/liveui_test.js index 168494bfb0..c5ff160d45 100644 --- a/tests/unit/client/liveui_test.js +++ b/tests/unit/client/liveui_test.js @@ -636,7 +636,7 @@ test("renderList - list items are reactive", function () { return DIV({id: doc.id}); } }); - onscreen = DIV({style: "display: none;"}); + var onscreen = DIV({style: "display: none;"}); onscreen.appendChild(r); document.body.appendChild(onscreen); diff --git a/tests/unit/client/template_test.html b/tests/unit/client/template_test.html index 22de10ac96..b548623136 100644 --- a/tests/unit/client/template_test.html +++ b/tests/unit/client/template_test.html @@ -53,3 +53,38 @@ + + + + + + + + + + + diff --git a/tests/unit/client/template_test.js b/tests/unit/client/template_test.js index 27084ef0b7..a31c60865b 100644 --- a/tests/unit/client/template_test.js +++ b/tests/unit/client/template_test.js @@ -33,13 +33,41 @@ test("template assembly", function () { test("template table assembly", function() { - var frag = Template.test_table_a0(); - var table = _.find(frag.childNodes, function(n) { - return n.nodeName == "TABLE"; - }); - assert.isTrue(table); + var childWithTag = function(node, tag) { + return _.find(node.childNodes, function(n) { + return n.nodeName === tag; + }); + }; - // This will accurately detect whether TRs in a TABLE in Internet Explorer - // are considered "not really there" for lack of an explicit TBODY. + var table; + + table = childWithTag(Template.test_table_a0(), "TABLE"); + + // table.rows is a great test, as it fails not only when TR/TD tags are + // stripped due to improper html-to-fragment, but also when they are present + // but don't show up because we didn't create a TBODY for IE. assert.equal(table.rows.length, 3); + + // this time with an explicit TBODY + table = childWithTag(Template.test_table_b0(), "TABLE"); + assert.equal(table.rows.length, 3); + + var c = Meteor.Collection(); + c.insert({bar:'a'}); + c.insert({bar:'b'}); + c.insert({bar:'c'}); + var onscreen = DIV({style: "display: none;"}); + onscreen.appendChild(Template.test_table_each({foo: c.find()})); + document.body.appendChild(onscreen); + table = childWithTag(onscreen, "TABLE"); + + assert.equal(table.rows.length, 3); + var tds = onscreen.getElementsByTagName("TD"); + assert.equal(tds.length, 3); + assert.equal(tds[0].innerHTML, "a"); + assert.equal(tds[1].innerHTML, "b"); + assert.equal(tds[2].innerHTML, "c"); + + + document.body.removeChild(onscreen); });