Skip to content

Commit d2dbf64

Browse files
committed
Add factory for Noticed events
1 parent afaf155 commit d2dbf64

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

app/javascript/better_together/notifications.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ function updateUnreadNotifications(count) {
118118
}
119119
}
120120

121+
// Initialize unread notification display on page load
122+
document.addEventListener('turbo:load', () => {
123+
const badge = document.getElementById('person_notification_count');
124+
const count = badge ? parseInt(badge.textContent, 10) : 0;
125+
updateUnreadNotifications(count);
126+
});
127+
121128
export {
122129
displayFlashMessage,
123130
updateUnreadNotifications

spec/factories/noticed/events.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Noticed
4+
FactoryBot.define do
5+
factory :noticed_event, class: 'Noticed::Event' do
6+
type { 'BetterTogether::NewMessageNotifier' }
7+
params { {} }
8+
end
9+
end
10+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Noticed
4+
FactoryBot.define do
5+
factory :noticed_notification, class: 'Noticed::Notification', aliases: %i[notification] do
6+
type { 'BetterTogether::NewMessageNotifier' }
7+
event { association :noticed_event, type: type }
8+
recipient { association(:better_together_person) }
9+
end
10+
end
11+
end

spec/features/notifications/unread_badge_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,15 @@
3737
expect(page).to have_no_css('#person_notification_count')
3838
expect(page.title).to eq(original_title)
3939
end
40+
41+
it 'shows unread status in title and favicon on initial load', :js do
42+
person = BetterTogether::User.find_by(email: '[email protected]').person
43+
create(:noticed_notification, recipient: person)
44+
45+
visit conversations_path(locale: I18n.default_locale)
46+
47+
expect(page).to have_title(/^\(1\)/)
48+
expect(page).to have_css("link[rel~='icon'][href^='data:image']", visible: false)
49+
end
4050
end
4151
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)