mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
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:
commit
2f2d47d250
1 changed files with 14 additions and 6 deletions
|
@ -1,22 +1,28 @@
|
||||||
var server;
|
|
||||||
|
|
||||||
module("Discourse.HeaderController", {
|
module("Discourse.HeaderController", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
server = sinon.fakeServer.create();
|
sinon.stub(Discourse, "ajax");
|
||||||
},
|
},
|
||||||
|
|
||||||
teardown: function() {
|
teardown: function() {
|
||||||
server.restore();
|
Discourse.ajax.restore();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("showNotifications action", function() {
|
test("showNotifications action", function() {
|
||||||
|
var resolveRequestWith;
|
||||||
|
var request = new Ember.RSVP.Promise(function(resolve) {
|
||||||
|
resolveRequestWith = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var controller = Discourse.HeaderController.create();
|
var controller = Discourse.HeaderController.create();
|
||||||
var viewSpy = {
|
var viewSpy = {
|
||||||
showDropdownBySelector: sinon.spy()
|
showDropdownBySelector: sinon.spy()
|
||||||
};
|
};
|
||||||
Discourse.User.current().set("unread_notifications", 1);
|
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() {
|
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");
|
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");
|
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");
|
equal(Discourse.User.current().get("unread_notifications"), 0, "current user's unread notifications count is zeroed after data has finished loading");
|
||||||
|
|
Loading…
Reference in a new issue