From 5855c9fcf41b57b15af4e19cdf5c5bdca2f68242 Mon Sep 17 00:00:00 2001 From: David Greenspan Date: Fri, 13 Jul 2012 16:32:20 -0700 Subject: [PATCH] beginning of branch key tests --- packages/liveui/liveui_tests.js | 109 +++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/packages/liveui/liveui_tests.js b/packages/liveui/liveui_tests.js index cb577a59b2..817ea5cfd6 100644 --- a/packages/liveui/liveui_tests.js +++ b/packages/liveui/liveui_tests.js @@ -2307,10 +2307,115 @@ Tinytest.add("liveui - constant chunk", function(test) { }); +Tinytest.add("liveui - branch keys", function(test) { + + var R, div; + + // Re-rendered Meteor.ui.render keeps same chunkState + + var objs = []; + R = ReactiveVar("foo"); + div = OnscreenDiv(Meteor.ui.render(function() { + return R.get(); + }, { + onscreen: function() { + objs.push(this); + } + })); + + Meteor.flush(); + R.set("bar"); + Meteor.flush(); + R.set("baz"); + Meteor.flush(); + + test.equal(objs.length, 3); + test.isTrue(objs[0] === objs[1]); + test.isTrue(objs[1] === objs[2]); + + div.kill(); + Meteor.flush(); + + // track chunk matching / re-rendering in detail + + var buf; + var counts; + + var testCallbacks = function(theNum /*, extend opts*/) { + return _.extend.apply(_, [{ + created: function() { + this.num = String(theNum); + var howManyBefore = counts[this.num] || 0; + counts[this.num] = howManyBefore + 1; + for(var i=0;iapple', 2, 'x'], + ['banana', 3, 'y'], + ['kiwi', 4, 'z'] + ], 1, 'fruit'); + })); + + Meteor.flush(); + buf.sort(); + test.equal(buf, ['c1', 'c2', 'c3', 'c4', 'on1', 'on2', 'on3', 'on4']); + buf.length = 0; + + R.set("bar"); + Meteor.flush(); + buf.sort(); + test.equal(buf, ['on1', 'on2', 'on3', 'on4']); + buf.length = 0; + + R.set("nothing"); + Meteor.flush(); + buf.sort(); + test.equal(buf, ['off1', 'off2', 'off3', 'off4']); + buf.length = 0; + + div.kill(); + Meteor.flush(); + + // XXX test some chunks not preserved; intermediate unkeyed chunks; + // duplicate branch keys; different order +}); + // TO TEST: // - chunk matching // - Handlebars branch keys -// - top-level replacement always matches // - options.branch // - preserve nodes // - API (one-match selectors, lambdas) @@ -2318,7 +2423,7 @@ Tinytest.add("liveui - constant chunk", function(test) { // - onscreen/offscreen/created callbacks // - timing of calls // - custom vs. original object -// - arguments to offscreen +// - arguments to onscreen // - when differ between old/new // - on listChunk // - different old and new data