Skip to content

Commit 3359813

Browse files
committed
cleans up header notifications integration tests
1 parent e5fd294 commit 3359813

1 file changed

Lines changed: 23 additions & 105 deletions

File tree

test/javascripts/integration/header_test.js

Lines changed: 23 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -35,119 +35,37 @@ test("logo", function() {
3535
});
3636
});
3737

38-
var notificationsDropdown = function() {
39-
return Ember.$("#notifications-dropdown");
40-
};
38+
test("notifications dropdown", function() {
39+
expect(4);
4140

42-
var notificationFixture = [
43-
{
44-
notification_type: 1, //mentioned
45-
read: false,
46-
created_at: "2013-11-03T12:12:12-04:00",
47-
post_number: 1, //post number == 1 means no number included in URL
48-
topic_id: 1234,
49-
slug: "some-topic-title",
50-
data: {
51-
topic_title: "Some topic title",
52-
display_username: "velesin"
53-
}
54-
},
55-
{
56-
notification_type: 2, //replied
57-
read: true,
58-
created_at: "2013-11-02T10:10:10-04:00",
59-
post_number: 2, //post number > 1 means number is included in URL
60-
topic_id: 1234,
61-
slug: "", //no slug == differently formatted URL (hardcoded 'topic/' segment instead of slug)
62-
data: {
63-
topic_title: "Some topic title",
64-
display_username: "velesin"
65-
}
66-
},
67-
{
68-
notification_type: 5, //liked
69-
read: true,
70-
created_at: "2013-11-01T11:11:11-04:00",
71-
post_number: 2,
72-
topic_id: 1234,
73-
slug: "some-topic-title",
74-
data: {
75-
topic_title: "", //no title == link URL should be empty
76-
display_username: "velesin"
77-
}
78-
}
79-
];
80-
81-
test("notifications: flow", function() {
82-
expect(8);
41+
var itemSelector = "#notifications-dropdown li";
8342

8443
Ember.run(function() {
85-
Discourse.URL_FIXTURES["/notifications"] = [notificationFixture[0]];
86-
Discourse.User.current().set("unread_notifications", 1);
44+
Discourse.URL_FIXTURES["/notifications"] = [
45+
{
46+
notification_type: 2, //replied
47+
read: true,
48+
post_number: 2,
49+
topic_id: 1234,
50+
slug: "a-slug",
51+
data: {
52+
topic_title: "some title",
53+
display_username: "velesin"
54+
}
55+
}
56+
];
8757
});
8858

8959
visit("/")
90-
.then(function() {
91-
equal(notificationsDropdown().find("ul").length, 0, "initially a list of notifications is not loaded");
92-
equal(notificationsDropdown().find("div.none").length, 1, "initially special 'no notifications' message is displayed");
93-
equal(notificationsDropdown().find("div.none").text(), "notifications.none", "'no notifications' message contains proper internationalized text");
94-
equal(Discourse.User.current().get("unread_notifications"), 1, "initially current user's unread notification count is not reset");
95-
})
96-
.click("#user-notifications")
97-
.then(function() {
98-
equal(notificationsDropdown().find("li").length, 2, "after user opens notifications dropdown, notifications are loaded");
99-
equal(Discourse.User.current().get("unread_notifications"), 0, "after user opens notifications dropdown, current user's notification count is zeroed");
100-
})
101-
.then(function() {
102-
Ember.run(function() {
103-
Discourse.URL_FIXTURES["/notifications"] = [notificationFixture[0], notificationFixture[1]];
104-
Discourse.User.current().set("unread_notifications", 1);
105-
});
106-
})
107-
.click("#user-notifications")
108-
.then(function() {
109-
equal(notificationsDropdown().find("li").length, 3, "when user opens notifications dropdown for the second time, notifications are reloaded afresh");
110-
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");
111-
});
112-
});
113-
114-
test("notifications: when there are no notifications", function() {
115-
expect(3);
116-
117-
Discourse.URL_FIXTURES["/notifications"] = [];
118-
119-
visit("/")
60+
.then(function() {
61+
ok(!exists($(itemSelector)), "initially is empty");
62+
})
12063
.click("#user-notifications")
12164
.then(function() {
122-
equal(notificationsDropdown().find("ul").length, 0, "a list of notifications is not displayed");
123-
equal(notificationsDropdown().find("div.none").length, 1, "special 'no notifications' message is displayed");
124-
equal(notificationsDropdown().find("div.none").text(), "notifications.none", "'no notifications' message contains proper internationalized text");
125-
});
126-
});
127-
128-
test("notifications: content", function() {
129-
expect(9);
65+
var $items = $(itemSelector);
13066

131-
Ember.run(function() {
132-
Discourse.URL_FIXTURES["/notifications"] = notificationFixture;
133-
Discourse.User.current().set("unread_notifications", 2);
67+
ok(exists($items), "is lazily populated after user opens it");
68+
ok($items.first().hasClass("read"), "correctly binds items' 'read' class");
69+
equal($items.first().html(), 'notifications.replied velesin <a href="/t/a-slug/1234/2">some title</a>', "correctly generates items' content");
13470
});
135-
136-
visit("/")
137-
.click("#user-notifications")
138-
.then(function() {
139-
equal(notificationsDropdown().find("li").length, 4, "dropdown contains list items for all notifications plus for additional 'more' link");
140-
141-
equal(notificationsDropdown().find("li").eq(0).attr("class"), "", "list item for unread notification has no class");
142-
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");
143-
144-
equal(notificationsDropdown().find("li").eq(1).attr("class"), "read", "list item for read notification has correct class");
145-
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");
146-
147-
equal(notificationsDropdown().find("li").eq(2).html(), 'notifications.liked velesin', "notification without topic title is rendered correctly");
148-
149-
equal(notificationsDropdown().find("li").eq(3).attr("class"), "read last", "list item for 'more' link has correct class");
150-
equal(notificationsDropdown().find("li").eq(3).find("a").attr("href"), Discourse.User.current().get("path"), "'more' link points to a correct URL");
151-
equal(notificationsDropdown().find("li").eq(3).find("a").text(), "notifications.more" + " …", "'more' link has correct text");
152-
});
15371
});

0 commit comments

Comments
 (0)