Merge pull request #1642 from velesin/header_notifications_tests_refactoring

cleans up header notifications integration tests
This commit is contained in:
Robin Ward 2013-11-12 08:19:24 -08:00
commit 7e1f433f27
1 changed files with 24 additions and 106 deletions

View File

@ -35,119 +35,37 @@ test("logo", function() {
});
});
var notificationsDropdown = function() {
return Ember.$("#notifications-dropdown");
};
test("notifications dropdown", function() {
expect(4);
var notificationFixture = [
{
notification_type: 1, //mentioned
read: false,
created_at: "2013-11-03T12:12:12-04:00",
post_number: 1, //post number == 1 means no number included in URL
topic_id: 1234,
slug: "some-topic-title",
data: {
topic_title: "Some topic title",
display_username: "velesin"
}
},
{
notification_type: 2, //replied
read: true,
created_at: "2013-11-02T10:10:10-04:00",
post_number: 2, //post number > 1 means number is included in URL
topic_id: 1234,
slug: "", //no slug == differently formatted URL (hardcoded 'topic/' segment instead of slug)
data: {
topic_title: "Some topic title",
display_username: "velesin"
}
},
{
notification_type: 5, //liked
read: true,
created_at: "2013-11-01T11:11:11-04:00",
post_number: 2,
topic_id: 1234,
slug: "some-topic-title",
data: {
topic_title: "", //no title == link URL should be empty
display_username: "velesin"
}
}
];
test("notifications: flow", function() {
expect(8);
var itemSelector = "#notifications-dropdown li";
Ember.run(function() {
Discourse.URL_FIXTURES["/notifications"] = [notificationFixture[0]];
Discourse.User.current().set("unread_notifications", 1);
Discourse.URL_FIXTURES["/notifications"] = [
{
notification_type: 2, //replied
read: true,
post_number: 2,
topic_id: 1234,
slug: "a-slug",
data: {
topic_title: "some title",
display_username: "velesin"
}
}
];
});
visit("/")
.then(function() {
equal(notificationsDropdown().find("ul").length, 0, "initially a list of notifications is not loaded");
equal(notificationsDropdown().find("div.none").length, 1, "initially special 'no notifications' message is displayed");
equal(notificationsDropdown().find("div.none").text(), "notifications.none", "'no notifications' message contains proper internationalized text");
equal(Discourse.User.current().get("unread_notifications"), 1, "initially current user's unread notification count is not reset");
})
.click("#user-notifications")
.then(function() {
equal(notificationsDropdown().find("li").length, 2, "after user opens notifications dropdown, notifications are loaded");
equal(Discourse.User.current().get("unread_notifications"), 0, "after user opens notifications dropdown, current user's notification count is zeroed");
})
.then(function() {
Ember.run(function() {
Discourse.URL_FIXTURES["/notifications"] = [notificationFixture[0], notificationFixture[1]];
Discourse.User.current().set("unread_notifications", 1);
});
})
.click("#user-notifications")
.then(function() {
equal(notificationsDropdown().find("li").length, 3, "when user opens notifications dropdown for the second time, notifications are reloaded afresh");
equal(Discourse.User.current().get("unread_notifications"), 0, "when user opens notifications dropdown for the second time, current user's notification count is zeroed again");
});
});
test("notifications: when there are no notifications", function() {
expect(3);
Discourse.URL_FIXTURES["/notifications"] = [];
visit("/")
.then(function() {
ok(!exists($(itemSelector)), "initially is empty");
})
.click("#user-notifications")
.then(function() {
equal(notificationsDropdown().find("ul").length, 0, "a list of notifications is not displayed");
equal(notificationsDropdown().find("div.none").length, 1, "special 'no notifications' message is displayed");
equal(notificationsDropdown().find("div.none").text(), "notifications.none", "'no notifications' message contains proper internationalized text");
var $items = $(itemSelector);
ok(exists($items), "is lazily populated after user opens it");
ok($items.first().hasClass("read"), "correctly binds items' 'read' class");
equal($items.first().html(), 'notifications.replied velesin <a href="/t/a-slug/1234/2">some title</a>', "correctly generates items' content");
});
});
test("notifications: content", function() {
expect(9);
Ember.run(function() {
Discourse.URL_FIXTURES["/notifications"] = notificationFixture;
Discourse.User.current().set("unread_notifications", 2);
});
visit("/")
.click("#user-notifications")
.then(function() {
equal(notificationsDropdown().find("li").length, 4, "dropdown contains list items for all notifications plus for additional 'more' link");
equal(notificationsDropdown().find("li").eq(0).attr("class"), "", "list item for unread notification has no class");
equal(notificationsDropdown().find("li").eq(0).html(), 'notifications.mentioned velesin <a href="/t/some-topic-title/1234">Some topic title</a>', "notification with a slug and for the first post in a topic is rendered correctly");
equal(notificationsDropdown().find("li").eq(1).attr("class"), "read", "list item for read notification has correct class");
equal(notificationsDropdown().find("li").eq(1).html(), 'notifications.replied velesin <a href="/t/topic/1234/2">Some topic title</a>', "notification without a slug and for a non-first post in a topic is rendered correctly");
equal(notificationsDropdown().find("li").eq(2).html(), 'notifications.liked velesin', "notification without topic title is rendered correctly");
equal(notificationsDropdown().find("li").eq(3).attr("class"), "read last", "list item for 'more' link has correct class");
equal(notificationsDropdown().find("li").eq(3).find("a").attr("href"), Discourse.User.current().get("path"), "'more' link points to a correct URL");
equal(notificationsDropdown().find("li").eq(3).find("a").text(), "notifications.more" + " …", "'more' link has correct text");
});
});