Merge pull request #273 from sgmap/fix_notifications_count
Fix notifications count
This commit is contained in:
commit
503f174f4b
2 changed files with 40 additions and 1 deletions
|
@ -28,7 +28,7 @@
|
||||||
- if total_new > 0
|
- if total_new > 0
|
||||||
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
|
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
|
||||||
= total_new
|
= total_new
|
||||||
- unread_notif_count = procedure.notifications.unread.count
|
- unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure)
|
||||||
- if unread_notif_count > 0
|
- if unread_notif_count > 0
|
||||||
.badge.progress-bar-warning{ title: 'Notifications' }
|
.badge.progress-bar-warning{ title: 'Notifications' }
|
||||||
= unread_notif_count
|
= unread_notif_count
|
||||||
|
|
|
@ -288,6 +288,13 @@ describe Gestionnaire, type: :model do
|
||||||
it { is_expected.to eq(1) }
|
it { is_expected.to eq(1) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when there is one notification read' do
|
||||||
|
let(:notification){ create(:notification, already_read: true) }
|
||||||
|
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(0) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when there are many notifications for one dossier' do
|
context 'when there are many notifications for one dossier' do
|
||||||
let(:notification){ create(:notification, already_read: false) }
|
let(:notification){ create(:notification, already_read: false) }
|
||||||
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
|
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
|
||||||
|
@ -305,4 +312,36 @@ describe Gestionnaire, type: :model do
|
||||||
it { is_expected.to eq(2) }
|
it { is_expected.to eq(2) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#dossier_with_notification_for' do
|
||||||
|
subject { gestionnaire.dossier_with_notification_for(procedure) }
|
||||||
|
|
||||||
|
context 'without notifications' do
|
||||||
|
it { is_expected.to eq(0) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a followed dossier' do
|
||||||
|
let!(:dossier){create(:dossier, procedure: procedure, state: 'received')}
|
||||||
|
let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) }
|
||||||
|
|
||||||
|
context 'with 1 notification' do
|
||||||
|
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with 1 read notification' do
|
||||||
|
let!(:notification){ create(:notification, already_read: true, dossier: dossier) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(0) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with 2 notification' do
|
||||||
|
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
|
||||||
|
|
||||||
|
it { is_expected.to eq(1) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue