added notification and unread mesasge count back to the header

This commit is contained in:
danielgrippi 2012-01-04 15:30:53 -08:00 committed by Dennis Collinson
parent 933299e31c
commit f72edbc039
3 changed files with 37 additions and 5 deletions

View file

@ -67,7 +67,7 @@
- if current_user - if current_user
:javascript :javascript
app.user({ 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) = yield(:head)

View file

@ -19,8 +19,8 @@
<div class="badge" id="notification_badge"> <div class="badge" id="notification_badge">
<a href="/notifications" title="<%= Diaspora.I18n.t('header.notifications') %>"> <a href="/notifications" title="<%= Diaspora.I18n.t('header.notifications') %>">
<img alt="<%= Diaspora.I18n.t('header.notifications') %>" id="notification-flag" src="/images/icons/notifications_grey.png"> <img alt="<%= Diaspora.I18n.t('header.notifications') %>" id="notification-flag" src="/images/icons/notifications_grey.png">
<div class="badge_count hidden"> <div class="badge_count <%= current_user.notifications_count > 0 ? '' : 'hidden' %>">
0 <%= current_user.notifications_count %>
</div> </div>
</a> </a>
</div> </div>
@ -28,8 +28,8 @@
<div class="badge" id="message_inbox_badge"> <div class="badge" id="message_inbox_badge">
<a href="/conversations" title="<%= Diaspora.I18n.t('header.messages') %>"> <a href="/conversations" title="<%= Diaspora.I18n.t('header.messages') %>">
<img alt="<%= Diaspora.I18n.t('header.messages') %>" src="/images/icons/mail_grey.png"> <img alt="<%= Diaspora.I18n.t('header.messages') %>" src="/images/icons/mail_grey.png">
<div class="badge_count hidden"> <div class="badge_count <%= current_user.unread_messages_count > 0 ? '' : 'hidden' %>">
0 <%= current_user.unread_messages_count %>
</div> </div>
</a> </a>
</div> </div>

View file

@ -7,6 +7,38 @@ describe("app.views.Header", function() {
this.view = new app.views.Header().render(); 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() { describe("#toggleDropdown", function() {
it("adds the class 'active'", function() { it("adds the class 'active'", function() {
expect(this.view.$(".dropdown")).not.toHaveClass("active"); expect(this.view.$(".dropdown")).not.toHaveClass("active");