2014-08-12 16:55:23 -04:00
|
|
|
moduleFor("controller:header", "controller:header", {
|
|
|
|
needs: ['controller:application']
|
|
|
|
});
|
2013-11-08 15:06:27 -05:00
|
|
|
|
|
|
|
test("showNotifications action", function() {
|
2015-02-26 12:25:25 -05:00
|
|
|
let resolveRequestWith;
|
|
|
|
const request = new Ember.RSVP.Promise(function(resolve) {
|
2013-11-12 14:40:46 -05:00
|
|
|
resolveRequestWith = resolve;
|
|
|
|
});
|
|
|
|
|
2015-02-26 12:25:25 -05:00
|
|
|
const currentUser = Discourse.User.create({ unread_notifications: 1});
|
|
|
|
const controller = this.subject({ currentUser: currentUser });
|
|
|
|
const viewSpy = { showDropdownBySelector: sinon.spy() };
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(Discourse, "ajax").withArgs("/notifications").returns(request);
|
2013-11-08 15:06:27 -05:00
|
|
|
|
|
|
|
Ember.run(function() {
|
|
|
|
controller.send("showNotifications", viewSpy);
|
|
|
|
});
|
|
|
|
|
|
|
|
equal(controller.get("notifications"), null, "notifications are null before data has finished loading");
|
2015-02-26 12:25:25 -05:00
|
|
|
equal(currentUser.get("unread_notifications"), 1, "current user's unread notifications count is not zeroed before data has finished loading");
|
2014-05-09 12:53:27 -04:00
|
|
|
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with loading glyph is shown before data has finished loading");
|
2013-11-08 15:06:27 -05:00
|
|
|
|
2013-11-12 14:40:46 -05:00
|
|
|
Ember.run(function() {
|
|
|
|
resolveRequestWith(["notification"]);
|
|
|
|
});
|
2013-11-08 15:06:27 -05:00
|
|
|
|
2014-09-02 21:32:27 -04: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");
|
2015-02-26 12:25:25 -05:00
|
|
|
equal(currentUser.get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");
|
2013-11-08 15:06:27 -05:00
|
|
|
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with notifications is shown after data has finished loading");
|
|
|
|
});
|