Skip to content

Commit

Permalink
add test for emberjs#5395
Browse files Browse the repository at this point in the history
  • Loading branch information
kilowhisky committed Mar 27, 2018
1 parent fe685f6 commit bb2a15c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/integration/record-arrays/peeked-records-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,72 @@ test('unloading filtered records', function(assert) {
assert.equal(get(people, 'length'), 1, 'Unloaded record removed from the array');
assert.equal(get(people.objectAt(0), 'name'), 'Scumbag Joe', 'Joe shifted down after the unload');
});

test('array observers on peekAll multiple unload changes sees all changes as they occur', function(assert) {
function push() {
run(() => {
store.push({
data: [
{
type: 'person',
id: '1',
attributes: {
name: 'Scumbag John'
}
},
{
type: 'person',
id: '2',
attributes: {
name: 'Scumbag Joe'
}
},
{
type: 'person',
id: '3',
attributes: {
name: 'Scumbag Mark'
}
},
{
type: 'person',
id: '4',
attributes: {
name: 'Scumbag Dave'
}
}
]
});
});
}

let people = run(() => {
return store.filter('person', hash => {
if (hash.get('name').match(/Scumbag/)) {
return true;
}
});
});

people.addArrayObserver(this, {
willChange: function(array, start, removeCount, addCount) {
if (removeCount > 0) {
let removed = array.slice(start, start + removeCount);
assert.equal(removed.any(x => !x), false, 'Records to be removed can be captured before removal');
}
},
didChange: function(array, start, removeCount, addCount) {}
});

assert.equal(get(people, 'length'), 0, 'precond - no items in the RecordArray');

push();

assert.equal(get(people, 'length'), 4, 'precond - four items in the RecordArray');

run(() => {
['2','3','4'].forEach(x => {
store.peekRecord('person', x).unloadRecord();
});
});
});

0 comments on commit bb2a15c

Please sign in to comment.