Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import EmberObject from '@ember/object';
import { A } from '@ember/array';
import MutableArray from '@ember/array/mutable';
import { tracked, notifyPropertyChange } from '@ember/-internals/metal';
import { InternalMutableArray as MutableArray } from '@ember/array/index-internal';
import Service, { service } from '@ember/service';
import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers';
import {
expectDeprecation,
moduleFor,
RenderingTestCase,
runTask,
testUnless,
} from 'internal-test-helpers';
import { DEPRECATIONS } from '@ember/-internals/deprecations';
import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@glimmer/manager';

Expand Down Expand Up @@ -172,7 +179,14 @@ moduleFor(
this.assertText('1, 2, 3, 4');
}

'@test custom ember array properties rerender when updated'() {
[`${testUnless(
DEPRECATIONS.DEPRECATE_MUTABLE_ARRAY_MIXIN.isRemoved
)} @test custom ember array properties rerender when updated`]() {
expectDeprecation(
/The `MutableArray` mixin is deprecated/,
DEPRECATIONS.DEPRECATE_MUTABLE_ARRAY_MIXIN.isEnabled
);

let CustomArray = class extends EmberObject.extend(MutableArray) {
init() {
super.init(...arguments);
Expand Down
78 changes: 63 additions & 15 deletions packages/@ember/-internals/runtime/tests/mixins/array_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ import {
arrayContentWillChange,
} from '@ember/-internals/metal';
import EmberObject, { get, set, computed, observer as emberObserver } from '@ember/object';
import { A as emberA } from '@ember/array';
import { InternalEmberArray as EmberArray } from '@ember/array/index-internal';
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
import EmberArray, { A as emberA } from '@ember/array';
import {
expectDeprecation,
moduleFor,
AbstractTestCase,
runLoopSettled,
testUnless,
} from 'internal-test-helpers';
import { DEPRECATIONS } from '../../../deprecations';

const MIXIN = DEPRECATIONS.DEPRECATE_EMBER_ARRAY_MIXIN;

function expectMixinDeprecation() {
expectDeprecation(/The `EmberArray` mixin is deprecated/, MIXIN.isEnabled);
}

/*
Implement a basic fake mutable array. This validates that any non-native
Expand All @@ -19,6 +31,7 @@ const TestArray = class extends EmberObject.extend(EmberArray) {
_content = null;

init() {
super.init(...arguments);
this._content = this._content || [];
}

Expand Down Expand Up @@ -50,15 +63,21 @@ const TestArray = class extends EmberObject.extend(EmberArray) {
moduleFor(
'Ember.Array',
class extends AbstractTestCase {
['@test the return value of slice has Ember.Array applied'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test the return value of slice has Ember.Array applied`](
assert
) {
expectMixinDeprecation();

let x = EmberObject.extend(EmberArray).create({
length: 0,
});
let y = x.slice(1);
assert.equal(EmberArray.detect(y), true, 'mixin should be applied');
}

['@test slice supports negative index arguments'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test slice supports negative index arguments`](assert) {
expectMixinDeprecation();

let testArray = TestArray.create({ _content: [1, 2, 3, 4] });

assert.deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)');
Expand Down Expand Up @@ -97,7 +116,9 @@ let obj, observer;
moduleFor(
'mixins/array/arrayContent[Will|Did]Change',
class extends AbstractTestCase {
async ['@test should notify observers of []'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test should notify observers of []`](assert) {
expectMixinDeprecation();

obj = DummyArray.extend({
enumerablePropertyDidChange: emberObserver('[]', function () {
this._count++;
Expand Down Expand Up @@ -130,6 +151,8 @@ moduleFor(
'notify observers of length',
class extends AbstractTestCase {
beforeEach(assert) {
expectMixinDeprecation();

obj = DummyArray.extend({
lengthDidChange: emberObserver('length', function () {
this._after++;
Expand All @@ -146,7 +169,9 @@ moduleFor(
obj = undefined;
}

async ['@test should notify observers when call with no params'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test should notify observers when call with no params`](
assert
) {
arrayContentWillChange(obj);
await runLoopSettled();

Expand All @@ -159,7 +184,9 @@ moduleFor(
}

// API variation that included items only
async ['@test should not notify when passed lengths are same'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test should not notify when passed lengths are same`](
assert
) {
arrayContentWillChange(obj, 0, 1, 1);
await runLoopSettled();

Expand All @@ -171,7 +198,9 @@ moduleFor(
assert.equal(obj._after, 0);
}

async ['@test should notify when passed lengths are different'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test should notify when passed lengths are different`](
assert
) {
arrayContentWillChange(obj, 0, 1, 2);
await runLoopSettled();

Expand All @@ -193,6 +222,8 @@ moduleFor(
'notify array observers (internal)',
class extends AbstractTestCase {
beforeEach(assert) {
expectMixinDeprecation();

obj = DummyArray.create();

observer = class extends EmberObject {
Expand Down Expand Up @@ -220,7 +251,9 @@ moduleFor(
obj = observer = null;
}

['@test should notify array observers when called with no params'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test should notify array observers when called with no params`](
assert
) {
arrayContentWillChange(obj);
assert.deepEqual(observer._before, [obj, 0, -1, -1]);

Expand All @@ -229,23 +262,27 @@ moduleFor(
}

// API variation that included items only
['@test should notify when called with same length items'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test should notify when called with same length items`](
assert
) {
arrayContentWillChange(obj, 0, 1, 1);
assert.deepEqual(observer._before, [obj, 0, 1, 1]);

arrayContentDidChange(obj, 0, 1, 1);
assert.deepEqual(observer._after, [obj, 0, 1, 1]);
}

['@test should notify when called with diff length items'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test should notify when called with diff length items`](
assert
) {
arrayContentWillChange(obj, 0, 2, 1);
assert.deepEqual(observer._before, [obj, 0, 2, 1]);

arrayContentDidChange(obj, 0, 2, 1);
assert.deepEqual(observer._after, [obj, 0, 2, 1]);
}

['@test removing array observer should disable'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test removing array observer should disable`](assert) {
removeArrayObserver(obj, observer, {
willChange: 'arrayWillChange',
didChange: 'arrayDidChange',
Expand All @@ -269,6 +306,8 @@ moduleFor(
'EmberArray.@each support',
class extends AbstractTestCase {
beforeEach() {
expectMixinDeprecation();

ary = TestArray.create({
_content: [
{ isDone: true, desc: 'Todo 1' },
Expand All @@ -284,7 +323,9 @@ moduleFor(
ary = null;
}

async ['@test adding an object should notify (@each.isDone)'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test adding an object should notify (@each.isDone)`](
assert
) {
let called = 0;

let observerObject = EmberObject.create({
Expand All @@ -306,7 +347,9 @@ moduleFor(
assert.equal(called, 1, 'calls observer when object is pushed');
}

async ['@test using @each to observe arrays that does not return objects raise error'](assert) {
async [`${testUnless(MIXIN.isRemoved)} @test using @each to observe arrays that does not return objects raise error`](
assert
) {
let called = 0;

let observerObject = EmberObject.create({
Expand All @@ -333,7 +376,12 @@ moduleFor(
await runLoopSettled();
assert.equal(called, 0, 'not calls observer when object is pushed');
}
}
);

moduleFor(
'@each support',
class extends AbstractTestCase {
['@test `objectAt` returns correct object'](assert) {
let arr = ['first', 'second', 'third', 'fourth'];
assert.equal(objectAt(arr, 2), 'third');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { getOwner } from '@ember/-internals/owner';
import { Container, Registry } from '@ember/-internals/container';
import ContainerProxy from '../../lib/mixins/container_proxy-internal';
import ContainerProxy from '../../lib/mixins/container_proxy';
import EmberObject from '@ember/object';
import { run, schedule } from '@ember/runloop';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { expectDeprecation, moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers';
import { DEPRECATIONS } from '../../../deprecations';
import { destroy } from '@glimmer/destroyable';

const MIXIN = DEPRECATIONS.DEPRECATE_CONTAINER_PROXY_MIXIN;

moduleFor(
'@ember/-internals/runtime/mixins/container_proxy',
class extends AbstractTestCase {
beforeEach() {
expectDeprecation(/The `ContainerProxyMixin` mixin is deprecated/, MIXIN.isEnabled);

this.Owner = EmberObject.extend(ContainerProxy);
this.instance = this.Owner.create();

Expand All @@ -20,14 +25,14 @@ moduleFor(
});
}

['@test provides ownerInjection helper method'](assert) {
[`${testUnless(MIXIN.isRemoved)} @test provides ownerInjection helper method`](assert) {
let result = this.instance.ownerInjection();

assert.equal(getOwner(result), this.instance, 'returns an object with an associated owner');
}

['@test actions queue completes before destruction'](assert) {
assert.expect(1);
[`${testUnless(MIXIN.isRemoved)} @test actions queue completes before destruction`](assert) {
assert.expect(2);

this.registry.register(
'service:auth',
Expand All @@ -46,10 +51,12 @@ moduleFor(
});
}

'@test being destroyed by @ember/destroyable properly destroys the container and created instances'(
[`${testUnless(
MIXIN.isRemoved
)} @test being destroyed by @ember/destroyable properly destroys the container and created instances`](
assert
) {
assert.expect(1);
assert.expect(2);

this.registry.register(
'service:foo',
Expand Down
Loading
Loading