discourse/test/javascripts/admin/controllers/admin-user-badges-test.js.es6

56 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import Badge from "discourse/models/badge";
import { mapRoutes } from "discourse/mapping-router";
2015-08-19 09:24:09 +08:00
2018-06-15 23:03:24 +08:00
moduleFor("controller:admin-user-badges", {
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-15 23:03:24 +08:00
this.registry.register("router:main", mapRoutes());
2016-11-09 03:29:50 +08:00
},
2018-06-15 23:03:24 +08:00
needs: ["controller:adminUser"]
});
2017-06-15 01:57:58 +08:00
QUnit.test("grantableBadges", function(assert) {
2018-06-15 23:03:24 +08: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-19 09:24:09 +08:00
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
2018-06-15 23:03:24 +08:00
const badgeNames = controller.get("grantableBadges").map(function(badge) {
return badge.name;
});
2017-06-15 01:57:58 +08:00
assert.not(badgeNames.includes(badgeDisabled), "excludes disabled badges");
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
});