Merge pull request #1645 from velesin/header_controller_test_fix

fixes the problem with perceived not mocked xhr call in tests
This commit is contained in:
Régis Hanol 2013-11-13 00:26:58 -08:00
commit 2f2d47d250

View File

@ -1,22 +1,28 @@
var server;
module("Discourse.HeaderController", {
setup: function() {
server = sinon.fakeServer.create();
sinon.stub(Discourse, "ajax");
},
teardown: function() {
server.restore();
Discourse.ajax.restore();
}
});
test("showNotifications action", function() {
var resolveRequestWith;
var request = new Ember.RSVP.Promise(function(resolve) {
resolveRequestWith = resolve;
});
var controller = Discourse.HeaderController.create();
var viewSpy = {
showDropdownBySelector: sinon.spy()
};
Discourse.User.current().set("unread_notifications", 1);
server.respondWith("/notifications", [200, { "Content-Type": "application/json" }, '["notification"]']);
Ember.run(function() {
Discourse.ajax.withArgs("/notifications").returns(request);
});
Ember.run(function() {
@ -28,7 +34,9 @@ test("showNotifications action", function() {
ok(viewSpy.showDropdownBySelector.notCalled, "dropdown with notifications is not shown before data has finished loading");
server.respond();
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");