2014-08-13 04:55:23 +08:00
moduleFor("controller:header", "controller:header", {
needs: ['controller:application']
});
2013-11-09 04:06:27 +08:00
test("showNotifications action", function() {
2013-11-13 03:40:46 +08:00
var resolveRequestWith;
var request = new Ember.RSVP.Promise(function(resolve) {
resolveRequestWith = resolve;
});
2014-07-31 06:56:01 +08:00
var controller = this.subject();
2013-11-09 04:06:27 +08:00
var viewSpy = {
showDropdownBySelector: sinon.spy()
};
2014-07-31 06:56:01 +08:00
sandbox.stub(Discourse, "ajax").withArgs("/notifications").returns(request);
sandbox.stub(Discourse.User, "current").returns(Discourse.User.create({
2013-12-20 01:59:30 +08:00
unread_notifications: 1
}));
2013-11-09 04:06:27 +08:00
Ember.run(function() {
controller.send("showNotifications", viewSpy);
});
equal(controller.get("notifications"), null, "notifications are null before data has finished loading");
equal(Discourse.User.current().get("unread_notifications"), 1, "current user's unread notifications count is not zeroed before data has finished loading");
2014-05-10 00:53:27 +08:00
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with loading glyph is shown before data has finished loading");
2013-11-09 04:06:27 +08:00
2013-11-13 03:40:46 +08:00
Ember.run(function() {
resolveRequestWith(["notification"]);
});
2013-11-09 04:06:27 +08:00
2014-09-03 09:32:27 +08:00
// Can't use deepEquals because controller.get("notifications") is an ArrayProxy, not an Array
ok(controller.get("notifications").indexOf("notification") !== -1, "notification is in the controller");
2013-11-09 04:06:27 +08:00
equal(Discourse.User.current().get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with notifications is shown after data has finished loading");
});