mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
refactors header notifications (renders them via separate controller / template)
This commit is contained in:
51
test/javascripts/controllers/notification_controller_test.js
Normal file
51
test/javascripts/controllers/notification_controller_test.js
Normal file
@ -0,0 +1,51 @@
|
||||
var controller;
|
||||
var notificationFixture = {
|
||||
notification_type: 1, //mentioned
|
||||
post_number: 1,
|
||||
topic_id: 1234,
|
||||
slug: "a-slug",
|
||||
data: {
|
||||
topic_title: "some title",
|
||||
display_username: "velesin"
|
||||
}
|
||||
};
|
||||
var postUrlStub = "post-url-stub";
|
||||
|
||||
module("Discourse.NotificationController", {
|
||||
setup: function() {
|
||||
sinon.stub(Discourse.Utilities, "postUrl").returns(postUrlStub);
|
||||
|
||||
controller = Discourse.NotificationController.create({
|
||||
content: notificationFixture
|
||||
});
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
Discourse.Utilities.postUrl.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("scope property is correct", function() {
|
||||
equal(controller.get("scope"), "notifications.mentioned");
|
||||
});
|
||||
|
||||
test("username property is correct", function() {
|
||||
equal(controller.get("username"), "velesin");
|
||||
});
|
||||
|
||||
test("link property returns empty string when there is no topic title", function() {
|
||||
var fixtureWithEmptyTopicTitle = _.extend({}, notificationFixture, {data: {topic_title: ""}});
|
||||
Ember.run(function() {
|
||||
controller.set("content", fixtureWithEmptyTopicTitle);
|
||||
});
|
||||
|
||||
equal(controller.get("link"), "");
|
||||
});
|
||||
|
||||
test("link property returns correctly built link when there is a topic title", function() {
|
||||
var $link = $(controller.get("link"));
|
||||
|
||||
ok(Discourse.Utilities.postUrl.calledWithExactly("a-slug", 1234, 1), "URL is generated with the correct slug, topic ID and post number");
|
||||
equal($link.attr("href"), postUrlStub, "generated link points to a correct URL");
|
||||
equal($link.text(), "some title", "generated link has correct text");
|
||||
});
|
Reference in New Issue
Block a user