atagen

malice

public
Star0
Watch0
61382e376b154e5b03d5e65195237ccd3ddfcd14
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git
web/test/message-sound.test.tsTypescript26 lines1.4 KB
1
import assert from 'node:assert/strict';
2
import { test } from 'node:test';
3
import { parseMessageSound, shouldPlaySound, SOUND_THROTTLE_MS } from '../src/lib/message-sound-model.ts';
4
5
test('parse falls back to defaults', () => {
6
  assert.deepEqual(parseMessageSound(null), { mode: 'mentions_dms', sound: null });
7
  assert.deepEqual(parseMessageSound({ mode: 'bogus', sound: 'http://x' }), { mode: 'mentions_dms', sound: null });
8
  assert.deepEqual(parseMessageSound({ mode: 'all', sound: 'mxc://h/a' }), { mode: 'all', sound: 'mxc://h/a' });
9
});
10
11
test('mode decides which arrivals play', () => {
12
  const room = { direct: false };
13
  const dm = { direct: true };
14
  const plain = { mention: false };
15
  assert.equal(shouldPlaySound('off', dm, { mention: true }, 0, 10_000), false);
16
  assert.equal(shouldPlaySound('all', room, plain, 0, 10_000), true);
17
  assert.equal(shouldPlaySound('mentions_dms', room, plain, 0, 10_000), false);
18
  assert.equal(shouldPlaySound('mentions_dms', room, { mention: true }, 0, 10_000), true);
19
  assert.equal(shouldPlaySound('mentions_dms', dm, plain, 0, 10_000), true);
20
});
21
22
test('throttles repeated plays', () => {
23
  const room = { direct: true };
24
  assert.equal(shouldPlaySound('all', room, { mention: false }, 10_000, 10_000 + SOUND_THROTTLE_MS - 1), false);
25
  assert.equal(shouldPlaySound('all', room, { mention: false }, 10_000, 10_000 + SOUND_THROTTLE_MS), true);
26
});