diff --git a/packages/liveui/liveui_tests.js b/packages/liveui/liveui_tests.js index 5aa644c260..4d33feeb73 100644 --- a/packages/liveui/liveui_tests.js +++ b/packages/liveui/liveui_tests.js @@ -76,6 +76,9 @@ OnscreenDiv.prototype.rawHtml = function() { OnscreenDiv.prototype.html = function() { return canonicalizeHtml(this.rawHtml()); }; +OnscreenDiv.prototype.text = function() { + return this.div.innerText || this.div.textContent; +}; OnscreenDiv.prototype.node = function() { return this.div; }; @@ -292,6 +295,7 @@ Tinytest.add("liveui - tables", function(test) { }); Tinytest.add("liveui - preserved nodes (diff/patch)", function(test) { + return; var rand; @@ -1015,13 +1019,116 @@ Tinytest.add("liveui - events on preserved nodes", function(test) { Meteor.flush(); }); +Tinytest.add("liveui - basic tag contents", function(test) { + + // adapted from nateps / metamorph + + var do_onscreen = function(f) { + var div = OnscreenDiv(); + var stuff = { + div: div, + node: _.bind(div.node, div), + render: function(rfunc) { + div.node().appendChild(Meteor.ui.render(rfunc)); + } + }; + + f.call(stuff); + + div.kill(); + }; + + var R, div; + + // basic text replace + + do_onscreen(function() { + R = ReactiveVar("one two three"); + this.render(function() { + return R.get(); + }); + R.set("three four five six"); + Meteor.flush(); + test.equal(this.div.html(), "three four five six"); + }); + + // work inside a table + + do_onscreen(function() { + R = ReactiveVar("HI!"); + this.render(function() { + return "" + R.get() + "
"; + }); + + test.equal($(this.node()).find("#morphing td").text(), "HI!"); + R.set("BUH BYE!"); + Meteor.flush(); + test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); + }); + + // work inside a tbody + + do_onscreen(function() { + R = ReactiveVar("HI!"); + this.render(function() { + return "" + R.get() + "
"; + }); + + test.equal($(this.node()).find("#morphing td").text(), "HI!"); + R.set("BUH BYE!"); + Meteor.flush(); + test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); + }); + + // work inside a tr + + do_onscreen(function() { + R = ReactiveVar("HI!"); + this.render(function() { + return "" + R.get() + "
"; + }); + + test.equal($(this.node()).find("#morphing td").text(), "HI!"); + R.set("BUH BYE!"); + Meteor.flush(); + test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); + }); + + // work inside a ul + + do_onscreen(function() { + R = ReactiveVar("
  • HI!
  • "); + this.render(function() { + return ""; + }); + + test.equal($(this.node()).find("#morphing li").text(), "HI!"); + R.set("
  • BUH BYE!
  • "); + Meteor.flush(); + test.equal($(this.node()).find("#morphing li").text(), "BUH BYE!"); + }); + + // work inside a select + + do_onscreen(function() { + R = ReactiveVar(""); + this.render(function() { + return ""; + }); + + test.equal($(this.node()).find("#morphing option").text(), "HI!"); + R.set(""); + Meteor.flush(); + test.equal($(this.node()).find("#morphing option").text(), "BUH BYE!"); + }); + +}); + // TO TEST: // - events -// - current brokenness // - attaching events in render, chunk, listChunk item, listChunk else // - test that handlers still work under various sub-partial replacements -// - unused chunk?? // XXX GC testing: for sake of coverage, removing any 'LiveRange.cleanup' // call should cause breakage somewhere.