<commit_before>module("Discourse.HeaderController", {
  setup: function() {
    sinon.stub(Discourse, "ajax");
  },

  teardown: function() {
    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);
  Ember.run(function() {
    Discourse.ajax.withArgs("/notifications").returns(request);
  });


  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.notCalled, "dropdown with notifications is not 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");
});<commit_msg>fixes HeaderController test<commit_after>module("Discourse.HeaderController");

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()
  };
  this.stub(Discourse, "ajax").withArgs("/notifications").returns(request);
  this.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.notCalled, "dropdown with notifications is not 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");
});
{'fraction_non_alphanumeric': 0.12987012987012986, 'fraction_numerical': 0.0019005384859043396, 'mean_word_length': 5.806034482758621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '132775', 'n_tokens_mistral': 887, 'n_tokens_neox': 857, 'n_words': 213}