2015-08-18 21:24:09 -04:00
|
|
|
import Badge from 'discourse/models/badge';
|
2016-11-08 14:29:50 -05:00
|
|
|
import { mapRoutes } from 'discourse/mapping-router';
|
2015-08-18 21:24:09 -04:00
|
|
|
|
2015-08-07 15:08:27 -04:00
|
|
|
moduleFor('controller:admin-user-badges', {
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2016-11-08 14:29:50 -05:00
|
|
|
this.registry.register('router:main', mapRoutes());
|
|
|
|
},
|
2015-02-15 20:37:11 -05:00
|
|
|
needs: ['controller:adminUser']
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("grantableBadges", function(assert) {
|
2018-01-21 22:10:53 -05:00
|
|
|
const badgeFirst = Badge.create({ id: 3, name: "A Badge", enabled: true, manually_grantable: true });
|
|
|
|
const badgeMiddle = Badge.create({ id: 1, name: "My Badge", enabled: true, manually_grantable: true });
|
|
|
|
const badgeLast = Badge.create({ id: 2, name: "Zoo Badge", enabled: true, manually_grantable: true });
|
|
|
|
const badgeDisabled = Badge.create({ id: 4, name: "Disabled Badge", enabled: false, manually_grantable: true });
|
|
|
|
const badgeAutomatic = Badge.create({ id: 5, name: "Automatic Badge", enabled: true, manually_grantable: false });
|
|
|
|
|
|
|
|
const controller = this.subject({
|
|
|
|
model: [],
|
|
|
|
badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled, badgeAutomatic]
|
|
|
|
});
|
|
|
|
|
2015-08-18 21:24:09 -04:00
|
|
|
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
|
|
|
|
const badgeNames = controller.get('grantableBadges').map(function(badge) {
|
2015-02-15 20:37:11 -05:00
|
|
|
return badge.name;
|
|
|
|
});
|
|
|
|
|
2015-09-23 19:20:44 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
|
|
|
|
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
2015-02-15 20:37:11 -05:00
|
|
|
});
|