Skip to content

Commit

Permalink
Add tests for key splice fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Aug 13, 2015
1 parent f74d072 commit 4bc055b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
35 changes: 33 additions & 2 deletions test/unit/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -3092,8 +3092,6 @@ <h4>inDocumentRepeater</h4>

});



suite('item changing on instance', function() {

test('primitive values - initial stamping', function() {
Expand Down Expand Up @@ -3191,6 +3189,39 @@ <h4>inDocumentRepeater</h4>

});

suite('external change & notification', function() {

test('in-place sort', function(done) {
var items = [
173, 166, 145, 755, 907,
836, 564, 721, 540, 372,
244, 145, 525, 958, 595,
207, 103, 602, 769, 190];
primitive.items = items;
setTimeout(function() {
var stamped1 = Polymer.dom(primitive.$.container1).querySelectorAll('*:not(template)');
for (var i=0; i<items.length; i++) {
assert.equal(stamped1[i].textContent, items[i]);
}
var prev = items.slice();
items.sort();
var splices = Polymer.ArraySplice.calculateSplices(items, prev);
var change = {
keySplices: Polymer.Collection.applySplices(items, splices),
indexSplices: splices
};
primitive.set('items.splices', change);
setTimeout(function() {
var stamped1 = Polymer.dom(primitive.$.container1).querySelectorAll('*:not(template)');
for (var i=0; i<items.length; i++) {
assert.equal(stamped1[i].textContent, items[i]);
}
done();
});
});
});
});

suite('repeater API', function() {

test('modelForElement', function() {
Expand Down
49 changes: 21 additions & 28 deletions test/unit/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
el.push('arrayNoColl', 1, 2, 3);
assert.equal(el.observerCounts.arrayNoCollChanged, 2);
assert.equal(Polymer.Collection.get(el.arrayNoColl).getKeys().length, 3);
el.push('arrayNoColl', 1, 2, 3);
el.push('arrayNoColl', 4, 5, 6);
assert.equal(el.observerCounts.arrayNoCollChanged, 3);
assert.equal(Polymer.Collection.get(el.arrayNoColl).getKeys().length, 6);
});
Expand All @@ -741,7 +741,7 @@
el.push('array', 1, 2, 3);
assert.equal(el.observerCounts.arrayChanged, 2);
assert.equal(Polymer.Collection.get(el.array).getKeys().length, 3);
el.push('array', 1, 2, 3);
el.push('array', 4, 5, 6);
assert.equal(el.observerCounts.arrayChanged, 3);
assert.equal(Polymer.Collection.get(el.array).getKeys().length, 6);
});
Expand All @@ -753,7 +753,7 @@
el.prop = 'first';
el.push('array', 1, 2, 3);
assert.equal(el.observerCounts.arrayOrPropChanged, 1);
el.push('array', 1, 2, 3);
el.push('array', 4, 5, 6);
assert.equal(el.observerCounts.arrayOrPropChanged, 2);
});

Expand All @@ -774,10 +774,10 @@
el.pop('data');
el.pop('data');
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.unshift('data', 1, 2);
el.unshift('data', 1, 2, 3);
el.unshift('data', 4, 5);
el.unshift('data', 6, 7, 8);
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.splice('data', 2, 2, 1, 2, 3);
el.splice('data', 9, 10, 11, 12, 13);
assert.equal(el.$.boundChild.arrayLength, el.data.length);
el.shift('data');
el.shift('data');
Expand Down Expand Up @@ -914,10 +914,9 @@
assert.strictEqual(change.indexSplices[0].addedCount, 2);
assert.strictEqual(change.indexSplices[0].removed.length, 0);
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 3);
assert.strictEqual(change.keySplices[0].added.length, 2);
assert.strictEqual(change.keySplices[0].added[0], key);
assert.strictEqual(change.keySplices[0].added[1], key+1);
assert.equal(change.keySplices[0].added[0], key);
assert.equal(change.keySplices[0].added[1], key+1);
assert.strictEqual(change.keySplices[0].removed.length, 0);
};
var ret = el.push('array', 'new1', 'new2');
Expand All @@ -942,10 +941,9 @@
assert.strictEqual(change.indexSplices[0].removed.length, 1);
assert.strictEqual(change.indexSplices[0].removed[0], 'orig3');
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 2);
assert.strictEqual(change.keySplices[0].added.length, 0);
assert.strictEqual(change.keySplices[0].removed.length, 1);
assert.strictEqual(change.keySplices[0].removed[0], key);
assert.equal(change.keySplices[0].removed[0], key);
};
var ret = el.pop('array');
assert.strictEqual(ret, 'orig3');
Expand All @@ -965,10 +963,9 @@
assert.strictEqual(change.indexSplices[0].addedCount, 2);
assert.strictEqual(change.indexSplices[0].removed.length, 0);
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 0);
assert.strictEqual(change.keySplices[0].added.length, 2);
assert.strictEqual(change.keySplices[0].added[0], key);
assert.strictEqual(change.keySplices[0].added[1], key+1);
assert.equal(change.keySplices[0].added[0], key);
assert.equal(change.keySplices[0].added[1], key+1);
assert.strictEqual(change.keySplices[0].removed.length, 0);
};
var ret = el.unshift('array', 'new1', 'new2');
Expand All @@ -991,11 +988,10 @@
assert.strictEqual(change.indexSplices[0].addedCount, 0);
assert.strictEqual(change.indexSplices[0].removed.length, 1);
assert.strictEqual(change.indexSplices[0].removed[0], 'orig1');
assert.strictEqual(change.keySplices[0].index, 0);
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].added.length, 0);
assert.strictEqual(change.keySplices[0].removed.length, 1);
assert.strictEqual(change.keySplices[0].removed[0], 0);
assert.equal(change.keySplices[0].removed[0], 0);
};
var ret = el.shift('array');
assert.strictEqual(ret, 'orig1');
Expand All @@ -1016,12 +1012,11 @@
assert.strictEqual(change.indexSplices[0].removed.length, 1);
assert.strictEqual(change.indexSplices[0].removed[0], 'orig2');
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 1);
assert.strictEqual(change.keySplices[0].added.length, 2);
assert.strictEqual(change.keySplices[0].added[0], key);
assert.strictEqual(change.keySplices[0].added[1], key+1);
assert.equal(change.keySplices[0].added[0], key);
assert.equal(change.keySplices[0].added[1], key+1);
assert.strictEqual(change.keySplices[0].removed.length, 1);
assert.strictEqual(change.keySplices[0].removed[0], 1);
assert.equal(change.keySplices[0].removed[0], 1);
};
var ret = el.splice('array', 1, 1, 'new1', 'new2');
assert.deepEqual(ret, ['orig2']);
Expand Down Expand Up @@ -1116,12 +1111,11 @@
assert.strictEqual(change.indexSplices[0].removed.length, 1);
assert.strictEqual(change.indexSplices[0].removed[0], 'orig2');
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 1);
assert.strictEqual(change.keySplices[0].added.length, 2);
assert.strictEqual(change.keySplices[0].added[0], key);
assert.strictEqual(change.keySplices[0].added[1], key+1);
assert.equal(change.keySplices[0].added[0], key);
assert.equal(change.keySplices[0].added[1], key+1);
assert.strictEqual(change.keySplices[0].removed.length, 1);
assert.strictEqual(change.keySplices[0].removed[0], 1);
assert.equal(change.keySplices[0].removed[0], 1);
};
var ret = el.splice('array', '1', '1', 'new1', 'new2');
assert.deepEqual(ret, ['orig2']);
Expand All @@ -1144,12 +1138,11 @@
assert.strictEqual(change.indexSplices[0].removed.length, 1);
assert.strictEqual(change.indexSplices[0].removed[0], 'orig2');
assert.strictEqual(change.keySplices.length, 1);
assert.strictEqual(change.keySplices[0].index, 1);
assert.strictEqual(change.keySplices[0].added.length, 2);
assert.strictEqual(change.keySplices[0].added[0], key);
assert.strictEqual(change.keySplices[0].added[1], key+1);
assert.equal(change.keySplices[0].added[0], key);
assert.equal(change.keySplices[0].added[1], key+1);
assert.strictEqual(change.keySplices[0].removed.length, 1);
assert.strictEqual(change.keySplices[0].removed[0], 1);
assert.equal(change.keySplices[0].removed[0], 1);
};
var ret = el.splice('array', '-2', '1', 'new1', 'new2');
assert.deepEqual(ret, ['orig2']);
Expand Down

0 comments on commit 4bc055b

Please sign in to comment.