From 5cf7d25d2b736fd9783ff933cd1ea48abba31d5f Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Fri, 16 Mar 2018 19:07:24 -0700 Subject: [PATCH] Adds a test for #5167 --- ...records-test.js => peeked-records-test.js} | 67 ++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) rename tests/integration/record-arrays/{unload-peeked-records-test.js => peeked-records-test.js} (76%) diff --git a/tests/integration/record-arrays/unload-peeked-records-test.js b/tests/integration/record-arrays/peeked-records-test.js similarity index 76% rename from tests/integration/record-arrays/unload-peeked-records-test.js rename to tests/integration/record-arrays/peeked-records-test.js index 74005ea22fc..297dc93d156 100644 --- a/tests/integration/record-arrays/unload-peeked-records-test.js +++ b/tests/integration/record-arrays/peeked-records-test.js @@ -1,10 +1,9 @@ import { run } from '@ember/runloop'; -import { watchProperties } from '../../helpers/watch-property'; import { createStore } from 'dummy/tests/helpers/store'; - import { module, test } from 'qunit'; - import DS from 'ember-data'; +import { get } from '@ember/object'; +import { watchProperties } from '../../helpers/watch-property'; let store; @@ -201,3 +200,65 @@ test('immediately peeking after unloading newly created records works as expecte 'RecordArray state when a new record is unloaded' ); }); + +test('unloadAll followed by peekAll in the same run-loop works as expected', function(assert) { + let peekedRecordArray = run(() => store.peekAll('person')); + let watcher = watchProperties(peekedRecordArray, ['length', '[]']); + + run(() => { + store.push({ + data: [ + { + type: 'person', + id: '1', + attributes: { + name: 'John' + } + }, + { + type: 'person', + id: '2', + attributes: { + name: 'Joe' + } + } + ] + }); + }); + + run(() => { + store.peekAll('person'); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after a single push with multiple records to add' + ); + + store.unloadAll('person'); + + assert.watchedPropertyCounts( + watcher, + { length: 1, '[]': 1 }, + 'RecordArray state after unloadAll has not changed yet' + ); + + assert.equal(get(peekedRecordArray, 'length'), 2, 'Array length is unchanged before the next peek'); + + store.peekAll('person'); + + assert.equal(get(peekedRecordArray, 'length'), 0, 'We no longer have any array content'); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state after a follow up peekAll reflects unload changes' + ); + }); + + assert.watchedPropertyCounts( + watcher, + { length: 2, '[]': 2 }, + 'RecordArray state has not changed any further' + ); +});