Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired authored and pliljegr committed Jul 16, 2019
1 parent e414cb3 commit 6fd0a3d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/-ember-data/tests/integration/record-array-manager-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { A } from '@ember/array';
import { setupTest } from 'ember-qunit';
import OrderedSet from '@ember/ordered-set';

import { settled } from '@ember/test-helpers';
import { module, test } from 'qunit';

import Model from '@ember-data/model';
Expand Down Expand Up @@ -59,9 +59,6 @@ module('integration/record_array_manager', function(hooks) {
}

test('destroying the store correctly cleans everything up', async function(assert) {
let query = {};
let person;

store.push({
data: {
type: 'car',
Expand All @@ -78,7 +75,7 @@ module('integration/record_array_manager', function(hooks) {
},
});

store.push({
let person = store.push({
data: {
type: 'person',
id: '1',
Expand All @@ -92,30 +89,36 @@ module('integration/record_array_manager', function(hooks) {
},
},
});
person = store.peekRecord('person', 1);

let all = store.peekAll('person');
let query = {};
let adapterPopulated = manager.createAdapterPopulatedRecordArray('person', query);
let allSummary = tap(all, 'willDestroy');
let adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy');
let internalPersonModel = person._internalModel;

assert.equal(allSummary.called.length, 0);
assert.equal(adapterPopulatedSummary.called.length, 0);
assert.equal(internalPersonModel._recordArrays.size, 1, 'expected the person to be a member of 1 recordArrays');
assert.equal('person' in manager._liveRecordArrays, true);
assert.equal(allSummary.called.length, 0, 'initial: no calls to all.willDestroy');
assert.equal(adapterPopulatedSummary.called.length, 0, 'initial: no calls to adapterPopulated.willDestroy');
assert.equal(
internalPersonModel._recordArrays.size,
1,
'initial: expected the person to be a member of 1 recordArrays'
);
assert.equal('person' in manager._liveRecordArrays, true, 'initial: we have a live array for person');

await all.destroy();
all.destroy();
await settled();

assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of 1 recordArrays');
assert.equal(allSummary.called.length, 1);
assert.equal('person' in manager._liveRecordArrays, false);
assert.equal(allSummary.called.length, 1, 'all.willDestroy called once');
assert.equal('person' in manager._liveRecordArrays, false, 'no longer have a live array for person');

await manager.destroy();
manager.destroy();
await settled();

assert.equal(internalPersonModel._recordArrays.size, 0, 'expected the person to be a member of no recordArrays');
assert.equal(allSummary.called.length, 1);
assert.equal(adapterPopulatedSummary.called.length, 1);
assert.equal(allSummary.called.length, 1, 'all.willDestroy still only called once');
assert.equal(adapterPopulatedSummary.called.length, 1, 'adapterPopulated.willDestroy called once');
});

test('batch liveRecordArray changes', async function(assert) {
Expand Down

0 comments on commit 6fd0a3d

Please sign in to comment.