atagen

malice

public
Star0
Watch0
f499972067e75178cb090fa6f5b44c8c4e7d3d79
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: web/test/pane-badges.test.ts

bcf2234c33f6atagen2026-10-27 03:55 UTC1
import assert from 'node:assert/strict';
bcf2234c33f6atagen2026-10-27 03:55 UTC2
import { test } from 'node:test';
bcf2234c33f6atagen2026-10-27 03:55 UTC3
import { paneBadges } from '../src/lib/pane-badges.ts';
bcf2234c33f6atagen2026-10-27 03:55 UTC4
import type { RoomSummary } from '../src/lib/types.ts';
bcf2234c33f6atagen2026-10-27 03:55 UTC5
bcf2234c33f6atagen2026-10-27 03:55 UTC6
function room(id: string, extra: Partial<RoomSummary> = {}): RoomSummary {
bcf2234c33f6atagen2026-10-27 03:55 UTC7
  return {
bcf2234c33f6atagen2026-10-27 03:55 UTC8
    room_id: id,
bcf2234c33f6atagen2026-10-27 03:55 UTC9
    name: id,
bcf2234c33f6atagen2026-10-27 03:55 UTC10
    membership: 'Joined',
bcf2234c33f6atagen2026-10-27 03:55 UTC11
    space: false,
bcf2234c33f6atagen2026-10-27 03:55 UTC12
    direct: false,
bcf2234c33f6atagen2026-10-27 03:55 UTC13
    unread_messages: 0,
bcf2234c33f6atagen2026-10-27 03:55 UTC14
    unread_mentions: 0,
bcf2234c33f6atagen2026-10-27 03:55 UTC15
    notification_mode: 'AllMessages',
bcf2234c33f6atagen2026-10-27 03:55 UTC16
    notification_mode_custom: false,
bcf2234c33f6atagen2026-10-27 03:55 UTC17
    parent_spaces: [],
bcf2234c33f6atagen2026-10-27 03:55 UTC18
    children: [],
bcf2234c33f6atagen2026-10-27 03:55 UTC19
    ...extra
bcf2234c33f6atagen2026-10-27 03:55 UTC20
  } as RoomSummary;
bcf2234c33f6atagen2026-10-27 03:55 UTC21
}
bcf2234c33f6atagen2026-10-27 03:55 UTC22
bcf2234c33f6atagen2026-10-27 03:55 UTC23
const isMuted = (r: RoomSummary) => r.notification_mode === 'Mute';
bcf2234c33f6atagen2026-10-27 03:55 UTC24
bcf2234c33f6atagen2026-10-27 03:55 UTC25
const rooms = [
bcf2234c33f6atagen2026-10-27 03:55 UTC26
  room('!a', { unread_messages: 5, unread_mentions: 1 }),
bcf2234c33f6atagen2026-10-27 03:55 UTC27
  room('!b', { unread_messages: 4, unread_mentions: 2 }),
bcf2234c33f6atagen2026-10-27 03:55 UTC28
  room('!quiet', { unread_messages: 9 }),
bcf2234c33f6atagen2026-10-27 03:55 UTC29
  room('!dm', { direct: true, unread_messages: 3 }),
bcf2234c33f6atagen2026-10-27 03:55 UTC30
  room('!muted', { unread_mentions: 4, notification_mode: 'Mute' }),
bcf2234c33f6atagen2026-10-27 03:55 UTC31
  room('!left', { unread_mentions: 4, membership: 'Left' })
bcf2234c33f6atagen2026-10-27 03:55 UTC32
];
bcf2234c33f6atagen2026-10-27 03:55 UTC33
bcf2234c33f6atagen2026-10-27 03:55 UTC34
test('mentions in the shown space go on channels, others and DMs on the rail', () => {
bcf2234c33f6atagen2026-10-27 03:55 UTC35
  const badges = paneBadges(rooms, new Set(['!a', '!quiet']), null, isMuted);
bcf2234c33f6atagen2026-10-27 03:55 UTC36
  assert.deepEqual(badges.channels, { count: 1, mention: true });
bcf2234c33f6atagen2026-10-27 03:55 UTC37
  assert.deepEqual(badges.rail, { count: 5, mention: true });
bcf2234c33f6atagen2026-10-27 03:55 UTC38
});
bcf2234c33f6atagen2026-10-27 03:55 UTC39
bcf2234c33f6atagen2026-10-27 03:55 UTC40
test('home lists every room, so a DM goes on channels', () => {
bcf2234c33f6atagen2026-10-27 03:55 UTC41
  const badges = paneBadges(rooms, new Set(rooms.map((r) => r.room_id)), null, isMuted);
bcf2234c33f6atagen2026-10-27 03:55 UTC42
  assert.deepEqual(badges.channels, { count: 6, mention: true });
bcf2234c33f6atagen2026-10-27 03:55 UTC43
  assert.deepEqual(badges.rail, { count: 0, mention: false });
bcf2234c33f6atagen2026-10-27 03:55 UTC44
});
bcf2234c33f6atagen2026-10-27 03:55 UTC45
bcf2234c33f6atagen2026-10-27 03:55 UTC46
test('the open room, muted rooms and plain unread channels count for nothing', () => {
bcf2234c33f6atagen2026-10-27 03:55 UTC47
  const badges = paneBadges(rooms, new Set(), '!b', (r) => isMuted(r) || r.room_id === '!a');
bcf2234c33f6atagen2026-10-27 03:55 UTC48
  assert.deepEqual(badges.rail, { count: 3, mention: false });
bcf2234c33f6atagen2026-10-27 03:55 UTC49
});