2015-08-19 09:24:09 +08:00
|
|
|
import Badge from 'discourse/models/badge';
|
2016-11-09 03:29:50 +08:00
|
|
|
import { mapRoutes } from 'discourse/mapping-router';
|
2015-08-19 09:24:09 +08:00
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
moduleFor('controller:admin-user-badges', {
|
2016-11-09 03:29:50 +08:00
|
|
|
setup() {
|
|
|
|
this.registry.register('router:main', mapRoutes());
|
|
|
|
},
|
2015-02-16 09:37:11 +08:00
|
|
|
needs: ['controller:adminUser']
|
|
|
|
});
|
|
|
|
|
|
|
|
test("grantableBadges", function() {
|
2015-09-24 07:20:44 +08:00
|
|
|
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});
|
2016-10-21 01:26:41 +08:00
|
|
|
const controller = this.subject({ model: [], badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] });
|
2015-08-19 09:24:09 +08:00
|
|
|
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
|
|
|
|
const badgeNames = controller.get('grantableBadges').map(function(badge) {
|
2015-02-16 09:37:11 +08:00
|
|
|
return badge.name;
|
|
|
|
});
|
|
|
|
|
2015-09-24 07:20:44 +08:00
|
|
|
|
2016-12-20 00:19:10 +08:00
|
|
|
not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
|
2015-08-19 09:24:09 +08:00
|
|
|
deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
2015-02-16 09:37:11 +08:00
|
|
|
});
|