Skip to content

Commit

Permalink
Failing tests for #12475
Browse files Browse the repository at this point in the history
* reduces EF4’s case further
* move related tests to runtime/computed/chains
* adds more thorough tests revealing more related issues
  • Loading branch information
stefanpenner committed Jan 19, 2016
1 parent ba3d5ff commit bef7236
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 22 deletions.
74 changes: 74 additions & 0 deletions packages/ember-runtime/tests/computed/chains_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { computed } from 'ember-metal/computed';
import { defineProperty } from 'ember-metal/properties';
import { get } from 'ember-metal/property_get';
import { set } from 'ember-metal/property_set';
import { isWatching } from 'ember-metal/watching';
import { A as emberA } from 'ember-runtime/system/native_array';

let a1, a2, a3, a4, obj;

QUnit.module('chain watching', {
setup() {
a1 = { foo: true, id: 1 };
a2 = { foo: true, id: 2 };

a3 = { foo: false, id: 3 };
a4 = { foo: false, id: 4 };

obj = { };
defineProperty(obj, 'a', computed('array.@each.foo', function() {}));
}
});

QUnit.test('replace array (no overlap)', function() {
set(obj, 'array', Ember.A([a1, a2]));
get(obj, 'a'); // kick CP;

ok( isWatching(a1, 'foo'), 'BEFORE: a1.foo is watched');
ok( isWatching(a2, 'foo'), 'BEFORE: a2.foo is watched');
ok(!isWatching(a3, 'foo'), 'BEFORE: a3.foo is NOT watched');
ok(!isWatching(a4, 'foo'), 'BEFORE: a4.foo is NOT watched');

set(obj, 'array', [a3, a4]);

ok(!isWatching(a1, 'foo'), 'AFTER: a1.foo is NOT watched');
ok(!isWatching(a2, 'foo'), 'AFTER: a2.foo is NOT watched');
ok( isWatching(a3, 'foo'), 'AFTER: a3.foo is watched');
ok( isWatching(a4, 'foo'), 'AFTER: a4.foo is watched');
});

QUnit.test('replace array (overlap)', function() {
set(obj, 'array', Ember.A([a1, a2, a3]));
get(obj, 'a'); // kick CP;

ok( isWatching(a1, 'foo'), 'BEFORE: a1.foo is watched');
ok( isWatching(a2, 'foo'), 'BEFORE: a2.foo is watched');
ok( isWatching(a3, 'foo'), 'BEFORE: a3.foo is watched');
ok(!isWatching(a4, 'foo'), 'BEFORE: a4.foo is NOT watched');

obj.set('array', [a2, a3, a4]);

ok(!isWatching(a1, 'foo'), 'AFTER: a1.foo is NOT watched');
ok( isWatching(a2, 'foo'), 'AFTER: a2.foo is watched');
ok( isWatching(a3, 'foo'), 'AFTER: a3.foo is watched');
ok( isWatching(a4, 'foo'), 'AFTER: a4.foo is watched');
});

QUnit.test('responds to change of property value on element after replacing array', function() {
let obj = { };

defineProperty(obj, 'a', computed('array.@each.foo', function() {
return this.array.filter(elt => elt.foo).reduce(((a,b) => a + b.id), 0);
}));

set(obj, 'array', emberA([a1,a2]));

deepEqual(get(obj, 'a'), 3, 'value is correct initially');
set(a1, 'foo', false);
deepEqual(get(obj, 'a'), 2, 'responds to change of property on element');
set(obj, 'array', [a1, a2, a3]);
deepEqual(get(obj, 'a'), 6, 'responds to content array change');
set(a1, 'foo', true);
deepEqual(get(obj, 'a'), 7, 'still responds to change of property on element');
});

Original file line number Diff line number Diff line change
Expand Up @@ -428,28 +428,6 @@ QUnit.test('properties values can be replaced', function() {
deepEqual(obj.get('a1bs').mapBy('name'), ['item1'], 'properties can be filtered by matching value');
});

QUnit.test('responds to change of property value on element after replacing array', function() {
let a1 = { foo: true, id: 1 };
let a2 = { foo: true, id: 2 };
let a3 = { foo: true, id: 4 };

obj = EmberObject.extend({
a: computed('array.@each.foo', function() {
return this.get('array').filter(elt => elt.foo).reduce(((a,b) => a + b.id), 0);
})
}).create({
array: emberA([a1, a2])
});

deepEqual(obj.get('a'), 3, 'value is correct initially');
set(a1, 'foo', false);
deepEqual(obj.get('a'), 2, 'responds to change of property on element');
obj.set('array', [a1, a2, a3]);
deepEqual(obj.get('a'), 6, 'responds to content array change');
set(a1, 'foo', true);
deepEqual(obj.get('a'), 7, 'still responds to change of property on element');
});

[
['uniq', uniq],
['union', union]
Expand Down

0 comments on commit bef7236

Please sign in to comment.