diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7ac8679b1..29a7fdf2e 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -67,7 +67,7 @@ - if current_user :javascript app.user({ - current_user: #{current_user.person.as_api_response(:backbone).to_json} + current_user: _.extend(#{current_user.person.as_api_response(:backbone).to_json}, {notifications_count : #{@notification_count}, unread_messages_count : #{@unread_message_count}}) }); = yield(:head) diff --git a/app/views/templates/header.jst b/app/views/templates/header.jst index 90636c840..935a084a7 100644 --- a/app/views/templates/header.jst +++ b/app/views/templates/header.jst @@ -19,8 +19,8 @@
<%= Diaspora.I18n.t('header.notifications') %> - @@ -28,8 +28,8 @@
<%= Diaspora.I18n.t('header.messages') %> - diff --git a/spec/javascripts/app/views/header_view_spec.js b/spec/javascripts/app/views/header_view_spec.js index 712cdb5d6..09ba258d7 100644 --- a/spec/javascripts/app/views/header_view_spec.js +++ b/spec/javascripts/app/views/header_view_spec.js @@ -7,6 +7,38 @@ describe("app.views.Header", function() { this.view = new app.views.Header().render(); }); + describe("render", function(){ + context("notifications badge", function(){ + it("displays a count when the current user has a notification", function(){ + window.current_user = _.extend(window.current_user, {notifications_count : 1}) + this.view.render(); + expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(false); + expect(this.view.$("#notification_badge .badge_count").text()).toContain("1"); + }) + + it("does not display a count when the current user has a notification", function(){ + window.current_user = _.extend(window.current_user, {notifications_count : 0}) + this.view.render(); + expect(this.view.$("#notification_badge .badge_count").hasClass('hidden')).toBe(true); + }) + }) + + context("messages badge", function(){ + it("displays a count when the current user has a notification", function(){ + window.current_user = _.extend(window.current_user, {unread_messages_count : 1}) + this.view.render(); + expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(false); + expect(this.view.$("#message_inbox_badge .badge_count").text()).toContain("1"); + }) + + it("does not display a count when the current user has a notification", function(){ + window.current_user = _.extend(window.current_user, {unread_messages_count : 0}) + this.view.render(); + expect(this.view.$("#message_inbox_badge .badge_count").hasClass('hidden')).toBe(true); + }) + }) + }) + describe("#toggleDropdown", function() { it("adds the class 'active'", function() { expect(this.view.$(".dropdown")).not.toHaveClass("active");