Skip to content

Commit

Permalink
[BUGFIX beta] Add a failing test for #12212
Browse files Browse the repository at this point in the history
Demonstrates issues with Ember.computed.sort used on class with multiple instances.
  • Loading branch information
Wesley Workman authored and mmun committed Feb 21, 2016
1 parent b00c076 commit 8adb04c
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1224,13 +1224,15 @@ QUnit.test('sorts correctly as only one property changes', function() {
});


var klass;
QUnit.module('sort - concurrency', {
setup() {
obj = EmberObject.extend({
klass = EmberObject.extend({
sortProps: ['count'],
sortedItems: sort('items', 'sortProps'),
customSortedItems: sort('items.@each.count', (a, b) => a.count - b.count)
}).create({
});
obj = klass.create({
items: emberA([
{ name: 'A', count: 1 },
{ name: 'B', count: 2 },
Expand All @@ -1255,7 +1257,7 @@ QUnit.test('sorts correctly after mutation to the sort properties', function() {
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
});

QUnit.test('sort correctl after mutation to the sor ', function() {
QUnit.test('sort correctly after mutation to the sort', function() {
deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');

set(obj.get('items')[1], 'count', 5);
Expand All @@ -1266,6 +1268,28 @@ QUnit.test('sort correctl after mutation to the sor ', function() {
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
});

QUnit.test('sort correctly on multiple instances of the same class', function() {
var obj2 = klass.create({
items: Ember.A([
{ name: 'W', count: 23 },
{ name: 'X', count: 24 },
{ name: 'Y', count: 25 },
{ name: 'Z', count: 26 }
])
});

deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');
deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'X', 'Y', 'Z'], 'initial');

set(obj.get('items')[1], 'count', 5);
set(obj.get('items')[2], 'count', 6);
set(obj2.get('items')[1], 'count', 27);
set(obj2.get('items')[2], 'count', 28);

deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'Z', 'X', 'Y'], 'final');
});

QUnit.module('max', {
setup() {
obj = EmberObject.extend({
Expand Down

0 comments on commit 8adb04c

Please sign in to comment.