Fix number of new notifications
We were displaying the total number of notifications with a message "You have N unread notifications", but were using the total number of notifications instead of the unread ones.
This commit is contained in:
@@ -9,7 +9,7 @@ class Layout::NotificationItemComponent < ApplicationComponent
|
||||
|
||||
def text
|
||||
if unread_notifications?
|
||||
t("layouts.header.notification_item.new_notifications", count: user.notifications_count)
|
||||
t("layouts.header.notification_item.new_notifications", count: unread_notifications.count)
|
||||
else
|
||||
t("layouts.header.notification_item.no_notifications")
|
||||
end
|
||||
@@ -24,6 +24,10 @@ class Layout::NotificationItemComponent < ApplicationComponent
|
||||
end
|
||||
|
||||
def unread_notifications?
|
||||
user.notifications.unread.count > 0
|
||||
unread_notifications.count > 0
|
||||
end
|
||||
|
||||
def unread_notifications
|
||||
user.notifications.unread
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,8 @@ shared_examples "notifiable in-app" do |factory_name|
|
||||
let(:author) { create(:user, :verified) }
|
||||
let!(:notifiable) { create(factory_name, author: author) }
|
||||
|
||||
before { create(:notification, :read, notifiable: notifiable, user: author) }
|
||||
|
||||
scenario "Notification message is shown" do
|
||||
create(:notification, notifiable: notifiable, user: author)
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ describe "Proposal Notifications" do
|
||||
login_as user1
|
||||
visit root_path
|
||||
|
||||
find(".unread-notifications").click
|
||||
click_link "You have a new notification"
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
|
||||
@@ -210,7 +210,7 @@ describe "Proposal Notifications" do
|
||||
login_as user2
|
||||
visit root_path
|
||||
|
||||
find(".unread-notifications").click
|
||||
click_link "You have a new notification"
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
|
||||
@@ -303,7 +303,7 @@ describe "Proposal Notifications" do
|
||||
login_as user
|
||||
visit root_path
|
||||
|
||||
find(".unread-notifications").click
|
||||
click_link "You have a new notification"
|
||||
|
||||
expect(page).to have_css ".notification", count: 1
|
||||
expect(page).to have_content "This resource is not available anymore"
|
||||
|
||||
Reference in New Issue
Block a user