atagen

malice

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