bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 1 | import assert from 'node:assert/strict'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 2 | import { test } from 'node:test'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 3 | import { paneBadges } from '../src/lib/pane-badges.ts'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 4 | import type { RoomSummary } from '../src/lib/types.ts'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 5 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 6 | function room(id: string, extra: Partial<RoomSummary> = {}): RoomSummary { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 7 | return { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 8 | room_id: id, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 9 | name: id, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 10 | membership: 'Joined', |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 11 | space: false, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 12 | direct: false, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 13 | unread_messages: 0, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 14 | unread_mentions: 0, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 15 | notification_mode: 'AllMessages', |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 16 | notification_mode_custom: false, |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 17 | parent_spaces: [], |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 18 | children: [], |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 19 | ...extra |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 20 | } as RoomSummary; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 21 | } |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 22 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 23 | const isMuted = (r: RoomSummary) => r.notification_mode === 'Mute'; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 24 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 25 | const rooms = [ |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 26 | room('!a', { unread_messages: 5, unread_mentions: 1 }), |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 27 | room('!b', { unread_messages: 4, unread_mentions: 2 }), |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 28 | room('!quiet', { unread_messages: 9 }), |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 29 | room('!dm', { direct: true, unread_messages: 3 }), |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 30 | room('!muted', { unread_mentions: 4, notification_mode: 'Mute' }), |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 31 | room('!left', { unread_mentions: 4, membership: 'Left' }) |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 32 | ]; |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 33 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 34 | test('mentions in the shown space go on channels, others and DMs on the rail', () => { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 35 | const badges = paneBadges(rooms, new Set(['!a', '!quiet']), null, isMuted); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 36 | assert.deepEqual(badges.channels, { count: 1, mention: true }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 37 | assert.deepEqual(badges.rail, { count: 5, mention: true }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 38 | }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 39 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 40 | test('home lists every room, so a DM goes on channels', () => { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 41 | const badges = paneBadges(rooms, new Set(rooms.map((r) => r.room_id)), null, isMuted); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 42 | assert.deepEqual(badges.channels, { count: 6, mention: true }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 43 | assert.deepEqual(badges.rail, { count: 0, mention: false }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 44 | }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 45 | |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 46 | test('the open room, muted rooms and plain unread channels count for nothing', () => { |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 47 | const badges = paneBadges(rooms, new Set(), '!b', (r) => isMuted(r) || r.room_id === '!a'); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 48 | assert.deepEqual(badges.rail, { count: 3, mention: false }); |
bcf2234c33f6 | atagen | 2026-10-27 03:55 UTC | 49 | }); |