2026-09-12 02:08:03 -04:00
|
|
|
import { test } from 'node:test';
|
|
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import { RoomNotificationMode } from '../../hooks/useRoomsNotificationPreferences';
|
2026-10-17 20:33:32 -04:00
|
|
|
import { muteTimersContent, parseMuteTimers, shouldResetMuteOnUnmute } from './muteTimers';
|
2026-09-12 02:08:03 -04:00
|
|
|
|
|
|
|
|
test('resets to Unset when the room is still Mute at expiry', () => {
|
|
|
|
|
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.Mute), true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('does not reset when the user switched to All messages during the mute window', () => {
|
|
|
|
|
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.AllMessages), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('does not reset when the user switched to Special messages during the mute window', () => {
|
|
|
|
|
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.SpecialMessages), false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('does not reset when the mode is already Unset', () => {
|
|
|
|
|
assert.equal(shouldResetMuteOnUnmute(RoomNotificationMode.Unset), false);
|
|
|
|
|
});
|
2026-10-17 20:33:32 -04:00
|
|
|
|
|
|
|
|
test('parseMuteTimers / muteTimersContent round-trip and tolerate garbage (#333)', () => {
|
|
|
|
|
const entries = [
|
|
|
|
|
{ roomId: '!a:x', unmuteAt: 1000 },
|
|
|
|
|
{ roomId: '!b:x', unmuteAt: 2000 },
|
|
|
|
|
];
|
|
|
|
|
assert.deepEqual(parseMuteTimers(muteTimersContent(entries)), entries);
|
|
|
|
|
assert.deepEqual(parseMuteTimers({ timers: { '!a:x': 'soon', '!b:x': 5 } }), [
|
|
|
|
|
{ roomId: '!b:x', unmuteAt: 5 },
|
|
|
|
|
]);
|
|
|
|
|
assert.deepEqual(parseMuteTimers(undefined), []);
|
|
|
|
|
assert.deepEqual(parseMuteTimers({ timers: null }), []);
|
|
|
|
|
});
|