2014-07-22 23:20:45 -04:00
|
|
|
module("controller:admin-badges");
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
test("canEditDescription", function() {
|
|
|
|
var badge, controller;
|
|
|
|
|
2014-05-19 00:29:12 -04:00
|
|
|
badge = Discourse.Badge.create({id: 101, name: "Test Badge"});
|
2014-07-22 23:20:45 -04:00
|
|
|
controller = testController("admin-badges", [badge]);
|
2014-03-05 07:52:20 -05:00
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
ok(controller.get('canEditDescription'), "allows editing description when a translation exists for the badge name");
|
|
|
|
|
|
|
|
this.stub(I18n, "t").returns("translated string");
|
2014-05-19 00:29:12 -04:00
|
|
|
badge = Discourse.Badge.create({id: 102, name: "Test Badge"});
|
2014-07-22 23:20:45 -04:00
|
|
|
controller = testController("admin-badges", [badge]);
|
2014-03-05 07:52:20 -05:00
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
ok(!controller.get('canEditDescription'), "shows the displayName when it is different from the name");
|
|
|
|
});
|
|
|
|
|
2014-05-23 22:33:46 -04:00
|
|
|
test("createNewBadge", function() {
|
2014-07-22 23:20:45 -04:00
|
|
|
var controller = testController("admin-badges", []);
|
2014-05-23 22:33:46 -04:00
|
|
|
controller.send('createNewBadge');
|
2014-03-05 07:52:20 -05:00
|
|
|
equal(controller.get('model.length'), 1, "adds a new badge to the list of badges");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("selectBadge", function() {
|
2014-05-19 00:29:12 -04:00
|
|
|
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
2014-07-22 23:20:45 -04:00
|
|
|
controller = testController("admin-badges", [badge]);
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
equal(controller.get('selectedItem'), badge, "the badge is selected");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("save", function() {
|
2014-05-19 00:29:12 -04:00
|
|
|
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
|
|
|
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
2014-07-22 23:20:45 -04:00
|
|
|
controller = testController("admin-badges", [badge, otherBadge]);
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
this.stub(badge, "save").returns(Ember.RSVP.resolve({}));
|
|
|
|
controller.send("save");
|
|
|
|
ok(badge.save.calledOnce, "called save on the badge");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("destroy", function() {
|
2014-05-19 00:29:12 -04:00
|
|
|
var badge = Discourse.Badge.create({id: 101, name: "Test Badge"}),
|
|
|
|
otherBadge = Discourse.Badge.create({id: 102, name: "Other Badge"}),
|
2014-07-22 23:20:45 -04:00
|
|
|
controller = testController("admin-badges", [badge, otherBadge]);
|
2014-03-05 07:52:20 -05:00
|
|
|
|
|
|
|
this.stub(badge, 'destroy').returns(Ember.RSVP.resolve({}));
|
|
|
|
|
|
|
|
bootbox.confirm = function(text, yes, no, func) {
|
|
|
|
func(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
controller.send('destroy');
|
|
|
|
ok(!badge.destroy.calledOnce, "badge is not destroyed if they user clicks no");
|
|
|
|
|
|
|
|
bootbox.confirm = function(text, yes, no, func) {
|
|
|
|
func(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.send('selectBadge', badge);
|
|
|
|
controller.send('destroy');
|
|
|
|
ok(badge.destroy.calledOnce, "badge is destroyed if they user clicks yes");
|
|
|
|
});
|