From 3359813624f13a35bb887649745806332ac0b2ea Mon Sep 17 00:00:00 2001 From: Wojciech Zawistowski Date: Mon, 11 Nov 2013 21:51:49 +0100 Subject: [PATCH] cleans up header notifications integration tests --- test/javascripts/integration/header_test.js | 130 ++++---------------- 1 file changed, 24 insertions(+), 106 deletions(-) diff --git a/test/javascripts/integration/header_test.js b/test/javascripts/integration/header_test.js index f7ce4f336ab..9740d1bcd71 100644 --- a/test/javascripts/integration/header_test.js +++ b/test/javascripts/integration/header_test.js @@ -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 some title', "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 Some topic title', "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 Some topic title', "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"); - }); -});