Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/javascript/better_together/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ function updateUnreadNotifications(count) {
}
}

// Initialize unread notification display on page load
document.addEventListener('turbo:load', () => {
const badge = document.getElementById('person_notification_count');
const count = badge ? parseInt(badge.textContent, 10) : 0;
updateUnreadNotifications(count);
});

export {
displayFlashMessage,
updateUnreadNotifications
Expand Down
10 changes: 10 additions & 0 deletions spec/factories/noticed/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Noticed
FactoryBot.define do
factory :noticed_event, class: 'Noticed::Event' do
type { 'BetterTogether::NewMessageNotifier' }
params { {} }
end
end
end
11 changes: 11 additions & 0 deletions spec/factories/noticed/notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Noticed
FactoryBot.define do
factory :noticed_notification, class: 'Noticed::Notification', aliases: %i[notification] do
type { 'BetterTogether::NewMessageNotifier' }
event { association :noticed_event, type: type }
recipient { association(:better_together_person) }
end
end
end
10 changes: 10 additions & 0 deletions spec/features/notifications/unread_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@
expect(page).to have_title(original_title)
end
end

it 'shows unread status in title and favicon on initial load', :js do
person = BetterTogether::User.find_by(email: '[email protected]').person
create(:noticed_notification, recipient: person)

visit conversations_path(locale: I18n.default_locale)

expect(page).to have_title(/^\(1\)/)
expect(page).to have_css("link[rel~='icon'][href^='data:image']", visible: false)
end
end
Loading