import { AbstractTestCase } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; import { get } from '@ember/-internals/metal'; class SetObjectsTests extends AbstractTestCase { '@test [A,B,C].setObjects([]) = > [] + notify'() { let before = newFixture(3); let after = []; let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ this.assert.equal(obj.setObjects(after), obj, 'return self'); this.assert.deepEqual(this.toArray(obj), after, 'post item results'); this.assert.equal(get(obj, 'length'), after.length, 'length'); this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once'); this.assert.equal( observer.timesCalled('firstObject'), 1, 'should have notified firstObject once' ); this.assert.equal( observer.timesCalled('lastObject'), 1, 'should have notified lastObject once' ); } '@test [A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify'() { let before = newFixture(3); let after = newFixture(4); let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ this.assert.equal(obj.setObjects(after), obj, 'return self'); this.assert.deepEqual(this.toArray(obj), after, 'post item results'); this.assert.equal(get(obj, 'length'), after.length, 'length'); this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once'); this.assert.equal( observer.timesCalled('firstObject'), 1, 'should have notified firstObject once' ); this.assert.equal( observer.timesCalled('lastObject'), 1, 'should have notified lastObject once' ); } } runArrayTests('setObjects', SetObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');