Fix notification count change on contacts page
This commit is contained in:
parent
410ddc3cb7
commit
dafafcd680
2 changed files with 147 additions and 92 deletions
|
|
@ -52,10 +52,10 @@ app.views.Notifications = Backbone.View.extend({
|
||||||
|
|
||||||
updateView: function(guid, type, unread) {
|
updateView: function(guid, type, unread) {
|
||||||
var change = unread ? 1 : -1,
|
var change = unread ? 1 : -1,
|
||||||
allNotes = $(".list-group > a:eq(0) .badge"),
|
allNotes = $("#notifications_container .list-group > a:eq(0) .badge"),
|
||||||
typeNotes = $(".list-group > a[data-type=" + type + "] .badge"),
|
typeNotes = $("#notifications_container .list-group > a[data-type=" + type + "] .badge"),
|
||||||
headerBadge = $(".notifications-link .badge"),
|
headerBadge = $(".notifications-link .badge"),
|
||||||
note = $(".stream_element[data-guid=" + guid + "]"),
|
note = $(".notifications .stream_element[data-guid=" + guid + "]"),
|
||||||
markAllReadLink = $("a#mark_all_read_link"),
|
markAllReadLink = $("a#mark_all_read_link"),
|
||||||
translationKey = unread ? "notifications.mark_read" : "notifications.mark_unread";
|
translationKey = unread ? "notifications.mark_read" : "notifications.mark_unread";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,91 +1,139 @@
|
||||||
describe("app.views.Notifications", function(){
|
describe("app.views.Notifications", function(){
|
||||||
beforeEach(function() {
|
context("on the notificatons page", function() {
|
||||||
spec.loadFixture("notifications");
|
|
||||||
this.view = new app.views.Notifications({el: "#notifications_container"});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("mark read", function() {
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.unreadN = $(".stream_element.unread").first();
|
spec.loadFixture("notifications");
|
||||||
this.guid = this.unreadN.data("guid");
|
this.view = new app.views.Notifications({el: "#notifications_container"});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls 'setRead'", function() {
|
describe("mark read", function() {
|
||||||
spyOn(this.view, "setRead");
|
|
||||||
this.unreadN.find(".unread-toggle").trigger("click");
|
|
||||||
|
|
||||||
expect(this.view.setRead).toHaveBeenCalledWith(this.guid);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("mark unread", function() {
|
|
||||||
beforeEach(function() {
|
|
||||||
this.readN = $(".stream_element.read").first();
|
|
||||||
this.guid = this.readN.data("guid");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls 'setUnread'", function() {
|
|
||||||
spyOn(this.view, "setUnread");
|
|
||||||
this.readN.find(".unread-toggle").trigger("click");
|
|
||||||
|
|
||||||
expect(this.view.setUnread).toHaveBeenCalledWith(this.guid);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("updateView", function() {
|
|
||||||
beforeEach(function() {
|
|
||||||
this.readN = $(".stream_element.read").first();
|
|
||||||
this.guid = this.readN.data("guid");
|
|
||||||
this.type = this.readN.data("type");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("changes the 'all notifications' count", function() {
|
|
||||||
var badge = $(".list-group > a:eq(0) .badge");
|
|
||||||
var count = parseInt(badge.text());
|
|
||||||
|
|
||||||
this.view.updateView(this.guid, this.type, true);
|
|
||||||
expect(parseInt(badge.text())).toBe(count + 1);
|
|
||||||
|
|
||||||
this.view.updateView(this.guid, this.type, false);
|
|
||||||
expect(parseInt(badge.text())).toBe(count);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("changes the notification type count", function() {
|
|
||||||
var badge = $(".list-group > a[data-type=" + this.type + "] .badge");
|
|
||||||
var count = parseInt(badge.text());
|
|
||||||
|
|
||||||
this.view.updateView(this.guid, this.type, true);
|
|
||||||
expect(parseInt(badge.text())).toBe(count + 1);
|
|
||||||
|
|
||||||
this.view.updateView(this.guid, this.type, false);
|
|
||||||
expect(parseInt(badge.text())).toBe(count);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("toggles the unread class and changes the title", function() {
|
|
||||||
this.view.updateView(this.readN.data("guid"), this.readN.data("type"), true);
|
|
||||||
expect(this.readN.hasClass("unread")).toBeTruthy();
|
|
||||||
expect(this.readN.hasClass("read")).toBeFalsy();
|
|
||||||
expect(this.readN.find(".unread-toggle .entypo-eye").data("original-title")).toBe(
|
|
||||||
Diaspora.I18n.t("notifications.mark_read")
|
|
||||||
);
|
|
||||||
|
|
||||||
this.view.updateView(this.readN.data("guid"), this.readN.data("type"), false);
|
|
||||||
expect(this.readN.hasClass("read")).toBeTruthy();
|
|
||||||
expect(this.readN.hasClass("unread")).toBeFalsy();
|
|
||||||
expect(this.readN.find(".unread-toggle .entypo-eye").data("original-title")).toBe(
|
|
||||||
Diaspora.I18n.t("notifications.mark_unread")
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
context("with a header", function() {
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}, notifications_count: 2, guid: "foo"});
|
this.unreadN = $(".stream_element.unread").first();
|
||||||
gon.appConfig = {settings: {podname: "MyPod"}};
|
this.guid = this.unreadN.data("guid");
|
||||||
this.header = new app.views.Header();
|
|
||||||
$("header").prepend(this.header.el);
|
|
||||||
this.header.render();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("calls 'setRead'", function() {
|
||||||
|
spyOn(this.view, "setRead");
|
||||||
|
this.unreadN.find(".unread-toggle").trigger("click");
|
||||||
|
|
||||||
|
expect(this.view.setRead).toHaveBeenCalledWith(this.guid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("mark unread", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.readN = $(".stream_element.read").first();
|
||||||
|
this.guid = this.readN.data("guid");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls 'setUnread'", function() {
|
||||||
|
spyOn(this.view, "setUnread");
|
||||||
|
this.readN.find(".unread-toggle").trigger("click");
|
||||||
|
|
||||||
|
expect(this.view.setUnread).toHaveBeenCalledWith(this.guid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("updateView", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
this.readN = $(".stream_element.read").first();
|
||||||
|
this.guid = this.readN.data("guid");
|
||||||
|
this.type = this.readN.data("type");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes the 'all notifications' count", function() {
|
||||||
|
var badge = $(".list-group > a:eq(0) .badge");
|
||||||
|
var count = parseInt(badge.text());
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, true);
|
||||||
|
expect(parseInt(badge.text())).toBe(count + 1);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, false);
|
||||||
|
expect(parseInt(badge.text())).toBe(count);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes the notification type count", function() {
|
||||||
|
var badge = $(".list-group > a[data-type=" + this.type + "] .badge");
|
||||||
|
var count = parseInt(badge.text());
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, true);
|
||||||
|
expect(parseInt(badge.text())).toBe(count + 1);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, false);
|
||||||
|
expect(parseInt(badge.text())).toBe(count);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("toggles the unread class and changes the title", function() {
|
||||||
|
this.view.updateView(this.readN.data("guid"), this.readN.data("type"), true);
|
||||||
|
expect(this.readN.hasClass("unread")).toBeTruthy();
|
||||||
|
expect(this.readN.hasClass("read")).toBeFalsy();
|
||||||
|
expect(this.readN.find(".unread-toggle .entypo-eye").data("original-title")).toBe(
|
||||||
|
Diaspora.I18n.t("notifications.mark_read")
|
||||||
|
);
|
||||||
|
|
||||||
|
this.view.updateView(this.readN.data("guid"), this.readN.data("type"), false);
|
||||||
|
expect(this.readN.hasClass("read")).toBeTruthy();
|
||||||
|
expect(this.readN.hasClass("unread")).toBeFalsy();
|
||||||
|
expect(this.readN.find(".unread-toggle .entypo-eye").data("original-title")).toBe(
|
||||||
|
Diaspora.I18n.t("notifications.mark_unread")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
context("with a header", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
/* jshint camelcase: false */
|
||||||
|
loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}, notifications_count: 2, guid: "foo"});
|
||||||
|
/* jshint camelcase: true */
|
||||||
|
gon.appConfig = {settings: {podname: "MyPod"}};
|
||||||
|
this.header = new app.views.Header();
|
||||||
|
$("header").prepend(this.header.el);
|
||||||
|
this.header.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes the header notifications count", function() {
|
||||||
|
var badge1 = $(".notifications-link:eq(0) .badge");
|
||||||
|
var badge2 = $(".notifications-link:eq(1) .badge");
|
||||||
|
var count = parseInt(badge1.text(), 10);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, true);
|
||||||
|
expect(parseInt(badge1.text(), 10)).toBe(count + 1);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, false);
|
||||||
|
expect(parseInt(badge1.text(), 10)).toBe(count);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, true);
|
||||||
|
expect(parseInt(badge2.text(), 10)).toBe(count + 1);
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, false);
|
||||||
|
expect(parseInt(badge2.text(), 10)).toBe(count);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("markAllRead", function() {
|
||||||
|
it("calls setRead for each unread notification", function(){
|
||||||
|
spyOn(this.view, "setRead");
|
||||||
|
this.view.markAllRead();
|
||||||
|
expect(this.view.setRead).toHaveBeenCalledWith(this.view.$(".stream_element.unread").eq(0).data("guid"));
|
||||||
|
this.view.markAllRead();
|
||||||
|
expect(this.view.setRead).toHaveBeenCalledWith(this.view.$(".stream_element.unread").eq(1).data("guid"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
context("on the contacts page", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
spec.loadFixture("aspects_manage");
|
||||||
|
this.view = new app.views.Notifications({el: "#notifications_container"});
|
||||||
|
/* jshint camelcase: false */
|
||||||
|
loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}, notifications_count: 2, guid: "foo"});
|
||||||
|
/* jshint camelcase: true */
|
||||||
|
gon.appConfig = {settings: {podname: "MyPod"}};
|
||||||
|
this.header = new app.views.Header();
|
||||||
|
$("header").prepend(this.header.el);
|
||||||
|
this.header.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("updateView", function() {
|
||||||
it("changes the header notifications count", function() {
|
it("changes the header notifications count", function() {
|
||||||
var badge1 = $(".notifications-link:eq(0) .badge");
|
var badge1 = $(".notifications-link:eq(0) .badge");
|
||||||
var badge2 = $(".notifications-link:eq(1) .badge");
|
var badge2 = $(".notifications-link:eq(1) .badge");
|
||||||
|
|
@ -104,15 +152,22 @@ describe("app.views.Notifications", function(){
|
||||||
expect(parseInt(badge2.text(), 10)).toBe(count);
|
expect(parseInt(badge2.text(), 10)).toBe(count);
|
||||||
});
|
});
|
||||||
|
|
||||||
context("markAllRead", function() {
|
it("doesn't change the contacts count", function() {
|
||||||
it("calls setRead for each unread notification", function(){
|
expect($("#aspect_nav .badge").length).toBeGreaterThan(0);
|
||||||
spyOn(this.view, "setRead");
|
$("#aspect_nav .badge").each(function(index, el) {
|
||||||
this.view.markAllRead();
|
$(el).text(index + 1337);
|
||||||
expect(this.view.setRead).toHaveBeenCalledWith(this.view.$(".stream_element.unread").eq(0).data("guid"));
|
|
||||||
this.view.markAllRead();
|
|
||||||
expect(this.view.setRead).toHaveBeenCalledWith(this.view.$(".stream_element.unread").eq(1).data("guid"));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, true);
|
||||||
|
$("#aspect_nav .badge").each(function(index, el) {
|
||||||
|
expect(parseInt($(el).text(), 10)).toBe(index + 1337);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.view.updateView(this.guid, this.type, false);
|
||||||
|
$("#aspect_nav .badge").each(function(index, el) {
|
||||||
|
expect(parseInt($(el).text(), 10)).toBe(index + 1337);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue