Skip to content

Commit

Permalink
Adds unit test to prove that SC.ArrayController's Array orderBy doesn…
Browse files Browse the repository at this point in the history
…'t work for more than a single Array item. The following commit will fix this.
  • Loading branch information
publickeating committed Jun 15, 2012
1 parent 07d7717 commit ab8211d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions frameworks/core_foundation/tests/controllers/array/array_case.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ var TestObject = SC.Object.extend({
toString: function() { return "TestObject(%@)".fmt(this.get("title")); }
});

var ComplexTestObject = SC.Object.extend({
firstName: null,
lastName: null,
toString: function() { return "TestObject(%@ %@)".fmt(this.get("firstName"), this.get('lastName')); }
});

// ..........................................................
// EMPTY
Expand Down Expand Up @@ -177,6 +182,34 @@ test("array orderBy using String", function(){
equals(testController.get('firstSelectableObject'), content[4], 'first selectable object should be the first object in arrangedObjects (changed order)');
});


test("array orderBy using Array", function(){
var complexContent,
familyNames = "Keating Zane Alberts Keating Keating".w(),
givenNames = "Travis Harold Brian Alvin Peter".w(),
testController;

complexContent = familyNames.map(function(x, i) {
return ComplexTestObject.create({ lastName: x, firstName: givenNames.objectAt(i) });
});

testController = SC.ArrayController.create({
content: complexContent
});

equals(testController.get('firstSelectableObject'), complexContent[0], 'first selectable object should be the first object in arrangedObjects');

// Reorder the content
testController.set('orderBy', ['lastName', 'firstName']); // Brian Alberts, Alvin Keating, Peter Keating, Travis Keating, Harold Zane
equals(testController.get('firstSelectableObject'), complexContent[2], 'first selectable object should be the first object in arrangedObjects (changed order)');
equals(testController.objectAt(1), complexContent[3], 'fourth content object should be the second object in arrangedObjects (changed order)');

// Reorder the content
testController.set('orderBy', ['lastName', 'firstName DESC']); // Brian Alberts, Travis Keating, Peter Keating, Alvin Keating,Harold Zane
equals(testController.objectAt(3), complexContent[3], 'fourth content object should be the fourth object in arrangedObjects (changed order)');

});

test("array orderBy using function", function(){
var testFunc = function(a,b){
if(a.get('title') > b.get('title')) return -1;
Expand Down

0 comments on commit ab8211d

Please sign in to comment.