Skip to content

Commit

Permalink
test(collectionRepeat): make tests not rely on browser sorting obj keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Feb 26, 2015
1 parent 68800e3 commit 6ee1177
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/unit/angular/directive/collectionRepeat.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,25 @@ describe('collectionRepeat', function() {
var items = getItems().filter(function(item) {
return item.isShown;
});
//Group items by their primary position, sort those groups by secondary position,
//then concat them all together.
//1. Group items by their primary position (row),
//2. Sort those groups by secondary position (column),
//3. Concat them all together.
var activeItems = {};
var result = [];
items.forEach(function(item) {
(activeItems[item.primaryPos] || (activeItems[item.primaryPos] = [])).push(item);
});
for (var primaryPos in activeItems) {
activeItems[primaryPos] = activeItems[primaryPos].sort(function(a,b) {
return a.secondaryPos > b.secondaryPos ? 1 : -1;

var result = [];
Object.keys(activeItems)
.sort(function(pos1, pos2) {
return (+pos1) > (+pos2) ? 1 : -1;
})
.forEach(function(primaryPos) {
var sortedRow = activeItems[primaryPos].sort(function(a,b) {
return a.secondaryPos > b.secondaryPos ? 1 : -1;
});
result = result.concat(sortedRow);
});
}
for (var primaryPos in activeItems) {
result = result.concat(activeItems[primaryPos]);
}
return result;
}
function activeItemContents() {
Expand Down

0 comments on commit 6ee1177

Please sign in to comment.