ES6: Tests

This commit is contained in:
Robin Ward
2014-07-31 12:05:47 -04:00
parent 3b46b5ecbf
commit b8bfbcb3cb
19 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1,33 @@
moduleFor("controller:header", "controller:header");
test("showNotifications action", function() {
var resolveRequestWith;
var request = new Ember.RSVP.Promise(function(resolve) {
resolveRequestWith = resolve;
});
var controller = this.subject();
var viewSpy = {
showDropdownBySelector: sinon.spy()
};
sandbox.stub(Discourse, "ajax").withArgs("/notifications").returns(request);
sandbox.stub(Discourse.User, "current").returns(Discourse.User.create({
unread_notifications: 1
}));
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");
ok(viewSpy.showDropdownBySelector.calledWith("#user-notifications"), "dropdown with loading glyph is shown before data has finished loading");
Ember.run(function() {
resolveRequestWith(["notification"]);
});
deepEqual(controller.get("notifications"), ["notification"], "notifications are set correctly after data has finished loading");
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");
});