Newer
Older
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
Dan Hansen
a validé
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
describe("Diaspora.Widgets.Notifications", function() {
var changeNotificationCountSpy, notifications, incrementCountSpy, decrementCountSpy;
Dan Hansen
a validé
beforeEach(function() {
spec.loadFixture("aspects_index");
this.view = new app.views.Header().render();
notifications = Diaspora.BaseWidget.instantiate("Notifications", this.view.$("#notification_badge .badge_count"), this.view.$(".notifications"));
Dan Hansen
a validé
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 at stream element", function() {
this.view.$(".notifications").html(
'<div id="1" class="stream_element read" data-guid=1></div>' +
'<div id="2" class="stream_element unread" data-guid=2></div>'
);
Steven Fuchs
a validé
notifications.clickSuccess({guid:2,unread:false});
expect( this.view.$('.stream_element#2')).toHaveClass("read");
});
it("changes the css to a read cell at notications element", function() {
this.view.$(".notifications").html(
'<div id="1" class="notification_element read" data-guid=1></div>' +
'<div id="2" class="notification_element unread" data-guid=2></div>'
);
notifications.clickSuccess({guid:2,unread:false});
expect( this.view.$('.notification_element#2')).toHaveClass("read");
});
it("changes the css to an unread cell at stream element", function() {
this.view.$(".notifications").html(
'<div id="1" class="stream_element read" data-guid=1></div>' +
'<div id="2" class="stream_element unread" data-guid=2></div>'
);
Steven Fuchs
a validé
notifications.clickSuccess({guid:1,unread:true});
expect( this.view.$('.stream_element#1')).toHaveClass("unread");
});
it("changes the css to an unread cell at notications element", function() {
this.view.$(".notifications").html(
'<div id="1" class="notification_element read" data-guid=1></div>' +
'<div id="2" class="notification_element unread" data-guid=2></div>'
);
notifications.clickSuccess({guid:1,unread:true});
expect( this.view.$('.notification_element#1')).toHaveClass("unread");
});
it("calls Notifications.decrementCount on a read cell at stream/notification element", function() {
notifications.clickSuccess(JSON.stringify({guid:1,unread:false}));
expect(notifications.decrementCount).toHaveBeenCalled();
});
it("calls Notifications.incrementCount on a unread cell at stream/notification element", function() {
Steven Fuchs
a validé
notifications.clickSuccess({guid:1,unread:true});
expect(notifications.incrementCount).toHaveBeenCalled();
});
Dan Hansen
a validé
});
Dan Hansen
a validé
describe("decrementCount", function() {
it("wont decrement Notifications.count below zero", function() {
var originalCount = notifications.count;
notifications.decrementCount();
expect(originalCount).toEqual(0);
expect(notifications.count).toEqual(0);
});
Dan Hansen
a validé
it("decrements Notifications.count", function() {
notifications.incrementCount();
notifications.incrementCount();
Dan Hansen
a validé
var originalCount = notifications.count;
notifications.decrementCount();
expect(notifications.count).toBeLessThan(originalCount);
});
Dan Hansen
a validé
it("calls Notifications.changeNotificationCount", function() {
notifications.decrementCount();
expect(notifications.changeNotificationCount).toHaveBeenCalled();
})
});
Dan Hansen
a validé
describe("incrementCount", function() {
it("increments Notifications.count", function() {
var originalCount = notifications.count;
notifications.incrementCount();
expect(notifications.count).toBeGreaterThan(originalCount);
});
Dan Hansen
a validé
it("calls Notifications.changeNotificationCount", function() {
notifications.incrementCount();
expect(notifications.changeNotificationCount).toHaveBeenCalled();
});
});
Dan Hansen
a validé
describe("showNotification", function() {
it("prepends a div to div#notifications", function() {
expect(this.view.$(".notifications div").length).toEqual(1);
Dan Hansen
a validé
notifications.showNotification({
html: '<div class="notification_element"></div>'
Dan Hansen
a validé
});
expect(this.view.$(".notifications div").length).toEqual(2);
Dan Hansen
a validé
});
Dan Hansen
a validé
it("only increments the notification count if specified to do so", function() {
var originalCount = notifications.count;
Dan Hansen
a validé
notifications.showNotification({
html: '<div class="notification"></div>',
incrementCount: false
Dan Hansen
a validé
expect(notifications.count).toEqual(originalCount);