diff --git a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 index b85fbaf069d..de9b3cc9825 100644 --- a/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-user-badges.js.es6 @@ -56,12 +56,12 @@ export default Ember.ArrayController.extend({ var badges = []; this.get('badges').forEach(function(badge) { - if (badge.get('multiple_grant') || !granted[badge.get('id')]) { + if (badge.get('enabled') && (badge.get('multiple_grant') || !granted[badge.get('id')])) { badges.push(badge); } }); - return _.sortBy(badges, "name"); + return _.sortBy(badges, badge => badge.get('displayName')); }.property('badges.@each', 'model.@each'), /** diff --git a/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 b/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 index 5c06c69c52f..4a0a676651a 100644 --- a/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 +++ b/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 @@ -5,14 +5,17 @@ moduleFor('controller:admin-user-badges', { }); test("grantableBadges", function() { - const badgeFirst = Badge.create({id: 3, name: "A Badge"}); - const badgeMiddle = Badge.create({id: 1, name: "My Badge"}); - const badgeLast = Badge.create({id: 2, name: "Zoo Badge"}); - const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle] }); + const badgeFirst = Badge.create({id: 3, name: "A Badge", enabled: true}); + const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true}); + const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true}); + const badgeDisabled = Badge.create({id: 4, name: "Disabled Badge", enabled: false}); + const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] }); const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name]; const badgeNames = controller.get('grantableBadges').map(function(badge) { return badge.name; }); + + not(badgeNames.contains(badgeDisabled), "excludes disabled badges"); deepEqual(badgeNames, sortedNames, "sorts badges by name"); });