discourse/test/javascripts/mixins/grant-badge-controller-test...

84 lines
2.0 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import GrantBadgeControllerMixin from "discourse/mixins/grant-badge-controller";
import Badge from "discourse/models/badge";
2018-06-15 11:03:24 -04:00
QUnit.module("mixin:grant-badge-controller", {
before: function() {
2018-06-15 11:03:24 -04:00
this.GrantBadgeController = Ember.Controller.extend(
GrantBadgeControllerMixin
);
2018-06-15 11:03:24 -04:00
this.badgeFirst = Badge.create({
id: 3,
name: "A Badge",
enabled: true,
manually_grantable: true
});
this.badgeMiddle = Badge.create({
id: 1,
name: "My Badge",
enabled: true,
manually_grantable: true
});
this.badgeLast = Badge.create({
id: 2,
name: "Zoo Badge",
enabled: true,
manually_grantable: true
});
this.badgeDisabled = Badge.create({
id: 4,
name: "Disabled Badge",
enabled: false,
manually_grantable: true
});
this.badgeAutomatic = Badge.create({
id: 5,
name: "Automatic Badge",
enabled: true,
manually_grantable: false
});
},
beforeEach: function() {
this.subject = this.GrantBadgeController.create({
userBadges: [],
2018-06-15 11:03:24 -04:00
allBadges: [
this.badgeLast,
this.badgeFirst,
this.badgeMiddle,
this.badgeDisabled,
this.badgeAutomatic
]
});
}
});
2018-06-15 11:03:24 -04:00
QUnit.test("grantableBadges", function(assert) {
const sortedNames = [
this.badgeFirst.name,
this.badgeMiddle.name,
this.badgeLast.name
];
const badgeNames = this.subject
.get("grantableBadges")
.map(badge => badge.name);
2018-06-15 11:03:24 -04:00
assert.not(
badgeNames.includes(this.badgeDisabled),
"excludes disabled badges"
);
assert.not(
badgeNames.includes(this.badgeAutomatic),
"excludes automatic badges"
);
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
});
2018-06-15 11:03:24 -04:00
QUnit.test("selectedBadgeGrantable", function(assert) {
this.subject.set("selectedBadgeId", this.badgeDisabled.id);
assert.not(this.subject.get("selectedBadgeGrantable"));
2018-06-15 11:03:24 -04:00
this.subject.set("selectedBadgeId", this.badgeFirst.id);
assert.ok(this.subject.get("selectedBadgeGrantable"));
});