From 28b83437eba8409efc81e0d3d358f37277733f01 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Wed, 19 Oct 2016 19:16:07 +0300 Subject: [PATCH] tidy up integration/record-array-manager-test --- .../integration/record-array-manager-test.js | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/tests/integration/record-array-manager-test.js b/tests/integration/record-array-manager-test.js index c62003a0284..2b12d21185d 100644 --- a/tests/integration/record-array-manager-test.js +++ b/tests/integration/record-array-manager-test.js @@ -5,23 +5,22 @@ import {module, test} from 'qunit'; import DS from 'ember-data'; -var store, env; -var run = Ember.run; +let store, env, manager; -var Person = DS.Model.extend({ +const { run } = Ember; + +const Person = DS.Model.extend({ name: DS.attr('string'), cars: DS.hasMany('car', { async: false }) }); -var Car = DS.Model.extend({ +const Car = DS.Model.extend({ make: DS.attr('string'), model: DS.attr('string'), person: DS.belongsTo('person', { async: false }) }); -var manager; - -module("integration/record_array_manager", { +module('integration/record_array_manager', { beforeEach() { env = setupStore({ adapter: DS.RESTAdapter.extend() @@ -52,11 +51,11 @@ function tap(obj, methodName, callback) { return summary; } -test("destroying the store correctly cleans everything up", function(assert) { - var query = { }; - var person; +test('destroying the store correctly cleans everything up', function(assert) { + let query = { }; + let person; - run(function() { + run(() => { store.push({ data: { type: 'car', @@ -74,7 +73,7 @@ test("destroying the store correctly cleans everything up", function(assert) { }); }); - run(function() { + run(() => { store.push({ data: { type: 'person', @@ -94,50 +93,54 @@ test("destroying the store correctly cleans everything up", function(assert) { person = store.peekRecord('person', 1); }); - var filterd = manager.createFilteredRecordArray(Person, function() { return true; }); - var filterd2 = manager.createFilteredRecordArray(Person, function() { return true; }); - var all = store.peekAll('person'); - var adapterPopulated = manager.createAdapterPopulatedRecordArray(Person, query); + let filterd = manager.createFilteredRecordArray(Person, () => true); + let filterd2 = manager.createFilteredRecordArray(Person, () => true); + let all = store.peekAll('person'); + let adapterPopulated = manager.createAdapterPopulatedRecordArray(Person, query); - var filterdSummary = tap(filterd, 'willDestroy'); - var filterd2Summary = tap(filterd2, 'willDestroy'); - var allSummary = tap(all, 'willDestroy'); - var adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy'); + let filterdSummary = tap(filterd, 'willDestroy'); + let filterd2Summary = tap(filterd2, 'willDestroy'); + let allSummary = tap(all, 'willDestroy'); + let adapterPopulatedSummary = tap(adapterPopulated, 'willDestroy'); + + let internalPersonModel = person._internalModel; assert.equal(filterdSummary.called.length, 0); assert.equal(filterd2Summary.called.length, 0); assert.equal(allSummary.called.length, 0); assert.equal(adapterPopulatedSummary.called.length, 0); - assert.equal(person._internalModel._recordArrays.list.length, 3, 'expected the person to be a member of 3 recordArrays'); + assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 3, 'expected the person to be a member of 3 recordArrays'); Ember.run(filterd2, filterd2.destroy); - assert.equal(person._internalModel._recordArrays.list.length, 2, 'expected the person to be a member of 2 recordArrays'); + + assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 2, 'expected the person to be a member of 2 recordArrays'); assert.equal(filterd2Summary.called.length, 1); assert.equal(manager.liveRecordArrays.has(all.type), true); + Ember.run(all, all.destroy); - assert.equal(person._internalModel._recordArrays.list.length, 1, 'expected the person to be a member of 1 recordArrays'); + + assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 1, 'expected the person to be a member of 1 recordArrays'); assert.equal(allSummary.called.length, 1); assert.equal(manager.liveRecordArrays.has(all.type), false); Ember.run(manager, manager.destroy); - assert.equal(person._internalModel._recordArrays.list.length, 0, 'expected the person to be a member of no recordArrays'); + + assert.equal(manager.recordArraysForRecord(internalPersonModel).size, 0, 'expected the person to be a member of no recordArrays'); assert.equal(filterdSummary.called.length, 1); assert.equal(filterd2Summary.called.length, 1); assert.equal(allSummary.called.length, 1); assert.equal(adapterPopulatedSummary.called.length, 1); }); -test("Should not filter a store.peekAll() array when a record property is changed", function(assert) { - var car; - - var populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray'); - var updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray'); +test('Should not filter a store.peekAll() array when a record property is changed', function(assert) { + let populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray'); + let updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray'); store.peekAll('car'); - run(function() { + let car = run(() => { store.push({ data: { type: 'car', @@ -153,19 +156,17 @@ test("Should not filter a store.peekAll() array when a record property is change } } }); - car = store.peekRecord('car', 1); + + return store.peekRecord('car', 1); }); assert.equal(populateLiveRecordArray.called.length, 1); assert.equal(updateFilterRecordArray.called.length, 0); - run(function() { - car.set('model', 'Mini'); - }); + run(() => car.set('model', 'Mini')); assert.equal(populateLiveRecordArray.called.length, 1); assert.equal(updateFilterRecordArray.called.length, 0); - }); test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their managers instead of retained when #destroy is called', function(assert) { @@ -181,13 +182,12 @@ test('#GH-4041 store#query AdapterPopulatedRecordArrays are removed from their m } }); }); + const query = {}; - var adapterPopulated = manager.createAdapterPopulatedRecordArray(Car, query); + let adapterPopulated = manager.createAdapterPopulatedRecordArray(Car, query); - run(() => { - adapterPopulated.destroy(); - }); + run(() => adapterPopulated.destroy()); assert.equal(manager._adapterPopulatedRecordArrays.length, 0); });