mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 07:53:43 +08: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,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");
|
||||
|
|
Loading…
Reference in New Issue
Block a user