From 176797628e9a4fffc79b73759433a4807836c0cc Mon Sep 17 00:00:00 2001 From: Steven Fuchs Date: Tue, 10 Jan 2012 00:07:42 -0500 Subject: [PATCH] javascript tests for the notification click callback routine. --- .../javascripts/widgets/notifications-spec.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/spec/javascripts/widgets/notifications-spec.js b/spec/javascripts/widgets/notifications-spec.js index cbb962180..f9ae7ee80 100644 --- a/spec/javascripts/widgets/notifications-spec.js +++ b/spec/javascripts/widgets/notifications-spec.js @@ -3,13 +3,44 @@ * the COPYRIGHT file. */ describe("Diaspora.Widgets.Notifications", function() { - var changeNotificationCountSpy, notifications; + var changeNotificationCountSpy, notifications, incrementCountSpy, decrementCountSpy; beforeEach(function() { spec.loadFixture("aspects_index"); notifications = Diaspora.BaseWidget.instantiate("Notifications", $("#notifications"), $("#notification_badge .badge_count")); changeNotificationCountSpy = spyOn(notifications, "changeNotificationCount").andCallThrough(); + incrementCountSpy = spyOn(notifications, "incrementCount").andCallThrough(); + decrementCountSpy = spyOn(notifications, "decrementCount").andCallThrough(); + }); + + describe("clickSuccess", function(){ + it("changes the css to a read cell", function() { + $(".notifications").html( + '
' + + '
' + ); + notifications.clickSuccess(JSON.stringify({guid:2,unread:false})); + expect( $('.stream_element#2')).toHaveClass("read"); + }); + it("changes the css to an unread cell", function() { + $(".notifications").html( + '
' + + '
' + ); + notifications.clickSuccess(JSON.stringify({guid:1,unread:true})); + expect( $('.stream_element#1')).toHaveClass("unread"); + }); + + + it("calls Notifications.decrementCount on a read cell", function() { + notifications.clickSuccess(JSON.stringify({guid:1,unread:false})); + expect(notifications.decrementCount).toHaveBeenCalled(); + }); + it("calls Notifications.incrementCount on a unread cell", function() { + notifications.clickSuccess(JSON.stringify({guid:1,unread:true})); + expect(notifications.incrementCount).toHaveBeenCalled(); + }); }); describe("decrementCount", function() {