Merge pull request #6718 from svbergerem/fix-contacts-page-notification-count

Fix notification count change on contacts page
This commit is contained in:
Dennis Schubert 2016-02-25 09:24:55 +01:00
commit 51eb3a79fc
3 changed files with 148 additions and 92 deletions

View file

@ -100,6 +100,7 @@ Contributions are very welcome, the hard work is done!
* Fixed a 500 when liking on mobile without JS enabled [#6683](https://github.com/diaspora/diaspora/pull/6683) * Fixed a 500 when liking on mobile without JS enabled [#6683](https://github.com/diaspora/diaspora/pull/6683)
* Fixed profile image upload in the mobile UI [#6684](https://github.com/diaspora/diaspora/pull/6684) * Fixed profile image upload in the mobile UI [#6684](https://github.com/diaspora/diaspora/pull/6684)
* Fixed eye not stopping all processes when trying to exit `script/server` [#6693](https://github.com/diaspora/diaspora/pull/6693) * Fixed eye not stopping all processes when trying to exit `script/server` [#6693](https://github.com/diaspora/diaspora/pull/6693)
* Do not change contacts count when marking notifications on the contacts page as read [#6718](https://github.com/diaspora/diaspora/pull/6718)
## Features ## Features
* Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033) * Support color themes [#6033](https://github.com/diaspora/diaspora/pull/6033)

View file

@ -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";

View file

@ -1,10 +1,11 @@
describe("app.views.Notifications", function(){ describe("app.views.Notifications", function(){
context("on the notifications page", function() {
beforeEach(function() { beforeEach(function() {
spec.loadFixture("notifications"); spec.loadFixture("notifications");
this.view = new app.views.Notifications({el: "#notifications_container"}); this.view = new app.views.Notifications({el: "#notifications_container"});
}); });
context("mark read", function() { describe("mark read", function() {
beforeEach(function() { beforeEach(function() {
this.unreadN = $(".stream_element.unread").first(); this.unreadN = $(".stream_element.unread").first();
this.guid = this.unreadN.data("guid"); this.guid = this.unreadN.data("guid");
@ -18,7 +19,7 @@ describe("app.views.Notifications", function(){
}); });
}); });
context("mark unread", function() { describe("mark unread", function() {
beforeEach(function() { beforeEach(function() {
this.readN = $(".stream_element.read").first(); this.readN = $(".stream_element.read").first();
this.guid = this.readN.data("guid"); this.guid = this.readN.data("guid");
@ -32,7 +33,7 @@ describe("app.views.Notifications", function(){
}); });
}); });
context("updateView", function() { describe("updateView", function() {
beforeEach(function() { beforeEach(function() {
this.readN = $(".stream_element.read").first(); this.readN = $(".stream_element.read").first();
this.guid = this.readN.data("guid"); this.guid = this.readN.data("guid");
@ -79,7 +80,9 @@ describe("app.views.Notifications", function(){
context("with a header", function() { context("with a header", function() {
beforeEach(function() { beforeEach(function() {
/* jshint camelcase: false */
loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}, notifications_count: 2, guid: "foo"}); loginAs({name: "alice", avatar: {small: "http://avatar.com/photo.jpg"}, notifications_count: 2, guid: "foo"});
/* jshint camelcase: true */
gon.appConfig = {settings: {podname: "MyPod"}}; gon.appConfig = {settings: {podname: "MyPod"}};
this.header = new app.views.Header(); this.header = new app.views.Header();
$("header").prepend(this.header.el); $("header").prepend(this.header.el);
@ -103,8 +106,10 @@ describe("app.views.Notifications", function(){
this.view.updateView(this.guid, this.type, false); this.view.updateView(this.guid, this.type, false);
expect(parseInt(badge2.text(), 10)).toBe(count); expect(parseInt(badge2.text(), 10)).toBe(count);
}); });
});
});
context("markAllRead", function() { describe("markAllRead", function() {
it("calls setRead for each unread notification", function(){ it("calls setRead for each unread notification", function(){
spyOn(this.view, "setRead"); spyOn(this.view, "setRead");
this.view.markAllRead(); this.view.markAllRead();
@ -114,5 +119,55 @@ describe("app.views.Notifications", function(){
}); });
}); });
}); });
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() {
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);
});
it("doesn't change the contacts count", function() {
expect($("#aspect_nav .badge").length).toBeGreaterThan(0);
$("#aspect_nav .badge").each(function(index, el) {
$(el).text(index + 1337);
});
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);
});
});
});
}); });
}); });