import { describe, expect, it } from 'vitest'; import { groupNotificationsByScope, type NotificationScope } from './notificationGrouping'; type Item = { id: string; scope: NotificationScope; is_read?: boolean }; describe('groupNotificationsByScope', () => { it('groups items and counts unread', () => { const items: Item[] = [ { id: '1', scope: 'photos', is_read: false }, { id: '2', scope: 'photos', is_read: true }, { id: '3', scope: 'package', is_read: false }, ]; const grouped = groupNotificationsByScope(items); expect(grouped[0]?.scope).toBe('photos'); expect(grouped[0]?.items).toHaveLength(2); expect(grouped[0]?.unread).toBe(1); expect(grouped[1]?.scope).toBe('package'); expect(grouped[1]?.unread).toBe(1); }); it('sorts groups by predefined scope order', () => { const items: Item[] = [ { id: '1', scope: 'general', is_read: true }, { id: '2', scope: 'events', is_read: true }, { id: '3', scope: 'photos', is_read: true }, ]; const grouped = groupNotificationsByScope(items); expect(grouped.map((group) => group.scope)).toEqual(['photos', 'events', 'general']); }); });