release / linux-x64 (push) Failing after 59s
ci / linux-x64 (push) Failing after 1m9s
ci / linux-arm64-cross (push) Failing after 4m15s
release / linux-arm64 (push) Successful in 4m36s
release / appimage-startup (push) Skipped
release / publish (push) Skipped
418 lines
24 KiB
JavaScript
418 lines
24 KiB
JavaScript
// Local recording UI state, notification policy and lock-mute scoping. Fake DOM/bridge only: no sound is played
|
|
// (the fake environment has no audio decoder or output), no dialog, no OS API.
|
|
import { test, beforeEach } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
import { env } from './fixtures/renderer-env.mjs';
|
|
|
|
const requests = [];
|
|
let answer = async () => ({ ok: true, result: {} });
|
|
globalThis.teamspeach.request = (connectionId, cmd, args) => {
|
|
requests.push({ connectionId, cmd, args });
|
|
return answer(connectionId, cmd, args);
|
|
};
|
|
const prefs = {};
|
|
globalThis.teamspeach.setPrefs = async (partial) => ({ ok: true, prefs: { ...Object.assign(prefs, partial) } });
|
|
|
|
const { S, newConnection } = await import('../app/renderer/js/state.js');
|
|
const notifications = await import('../app/renderer/js/notifications.js');
|
|
const recording = await import('../app/renderer/js/recording.js');
|
|
const os = await import('../app/renderer/js/os-settings.js');
|
|
|
|
const { STATE, soundAllowed, settingState, eventLog, GROUPS, EVENTS, SOUNDS, EVENT_SOUNDS } = notifications;
|
|
|
|
function connection(id, { away = false, outputMuted = false, channel = 1 } = {}) {
|
|
const conn = newConnection(id);
|
|
conn.conn = { state: 'connected', address: 'fixture.invalid', reason: null };
|
|
conn.audio = { input_muted: false, output_muted: outputMuted, transmitting: false };
|
|
conn.snap = {
|
|
own_client_id: 1,
|
|
own_channel_id: channel,
|
|
channels: [{ id: 1, name: 'Lobby' }, { id: 2, name: 'Other' }],
|
|
clients: [
|
|
{ id: 1, uid: 'me=', nickname: 'Me', channel_id: channel, is_self: true, away, output_muted: outputMuted, server_groups: [8], is_recording: false },
|
|
{ id: 5, uid: 'alice=', nickname: 'Alice', channel_id: 1, is_self: false, is_recording: false },
|
|
],
|
|
};
|
|
S.connections.set(id, conn);
|
|
return conn;
|
|
}
|
|
|
|
beforeEach(() => {
|
|
S.connections.clear();
|
|
S.prefs = { notificationStates: {}, recordingMode: 3, osMuteWhenLocked: true };
|
|
requests.length = 0;
|
|
answer = async () => ({ ok: true, result: {} });
|
|
});
|
|
|
|
test('sound policy matches the official isNotificationSoundAllowed expression', () => {
|
|
const official = (n, d, h, l, c) => !(n === 0) && !((d || h) && n !== 2 && (!l || h) && (!c || d));
|
|
for (const state of [0, 1, 2]) {
|
|
for (const away of [false, true]) {
|
|
for (const outputMuted of [false, true]) {
|
|
for (const sound of ['ClientMove.SomeoneJoinedYourChannel', 'ClientUpdate.YouAway', 'ClientUpdate.YouPlaybackMuted']) {
|
|
assert.equal(soundAllowed('x', state, { away, outputMuted }, sound), official(state, away, outputMuted, sound === 'ClientUpdate.YouAway', sound === 'ClientUpdate.YouPlaybackMuted'), `${state}/${away}/${outputMuted}/${sound}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('defaults follow the official table: everything on except "talking while muted"', () => {
|
|
for (const [, items] of GROUPS) for (const { id } of items) assert.equal(settingState(id), id === 'talking_while_muted' ? STATE.DISABLED : STATE.ENABLED, id);
|
|
S.prefs.notificationStates = { connected: 2, error: 0 };
|
|
assert.equal(settingState('connected'), STATE.IMPORTANT);
|
|
assert.equal(settingState('error'), STATE.DISABLED);
|
|
assert.ok(!GROUPS.some(([g]) => g === 'call'), 'calls need a myTeamSpeak account and are not offered');
|
|
});
|
|
|
|
test('every mapped sound is a local, decodable-size PCM wave and every bundled sound is mapped', () => {
|
|
const dir = new URL('../app/renderer/assets/sounds/', import.meta.url);
|
|
const files = new Set(Object.values(SOUNDS).map((s) => s.file));
|
|
assert.deepEqual(readdirSync(dir).sort(), [...files].map((f) => `${f}.wav`).sort());
|
|
for (const file of files) {
|
|
const bytes = readFileSync(new URL(`${file}.wav`, dir));
|
|
assert.ok(bytes.length <= 1024 * 1024, file);
|
|
assert.equal(bytes.toString('latin1', 0, 4), 'RIFF', file);
|
|
assert.equal(bytes.toString('latin1', 8, 12), 'WAVE', file);
|
|
let fmt = null;
|
|
let data = 0;
|
|
for (let at = 12; at + 8 <= bytes.length;) {
|
|
const id = bytes.toString('latin1', at, at + 4);
|
|
const size = bytes.readUInt32LE(at + 4);
|
|
if (id === 'fmt ') fmt = { format: bytes.readUInt16LE(at + 8), channels: bytes.readUInt16LE(at + 10), rate: bytes.readUInt32LE(at + 12), bits: bytes.readUInt16LE(at + 22) };
|
|
if (id === 'data') data = size;
|
|
at += 8 + size + (size & 1);
|
|
}
|
|
assert.equal(fmt?.format, 1, `${file} is PCM`);
|
|
assert.ok(fmt.channels >= 1 && fmt.channels <= 2 && fmt.bits === 16 && [44100, 48000].includes(fmt.rate), file);
|
|
const seconds = data / (fmt.channels * 2) / fmt.rate;
|
|
assert.ok(seconds > 0 && seconds <= 10, `${file} ${seconds} s`);
|
|
}
|
|
});
|
|
|
|
test('Listen and advanced events name official sounds; only others\' non-current-channel edits are silent', () => {
|
|
const { PREVIEW_SOUND } = notifications._test;
|
|
for (const [, items] of GROUPS) for (const { id } of items) assert.ok(SOUNDS[PREVIEW_SOUND[id]], id);
|
|
for (const [id, events] of Object.entries(EVENTS)) {
|
|
for (const event of events) {
|
|
const silent = id === 'edited_other' && event !== 'channel_edited';
|
|
assert.equal(Boolean(SOUNDS[EVENT_SOUNDS[id]?.[event]]), !silent, `${id}/${event}`);
|
|
}
|
|
}
|
|
for (const events of Object.values(EVENT_SOUNDS)) for (const key of Object.values(events)) assert.ok(SOUNDS[key], key);
|
|
});
|
|
|
|
test('server events become the right settings and event-log entries (log is independent of sound)', () => {
|
|
const conn = connection('c1');
|
|
S.prefs.notificationStates = { someone_moved_in: 0 };
|
|
notifications._test.onServerEvent({ kind: 'client_move', client_id: 5, nickname: 'Bob', from_channel_id: 2, to_channel_id: 1, reason: 'none', invoker: null, is_self: false }, conn);
|
|
notifications._test.onServerEvent({ kind: 'client_leave', client_id: 5, nickname: 'Alice', from_channel_id: 1, reason: 'ban', invoker: { id: 9, name: 'Admin' }, is_self: false }, conn);
|
|
notifications._test.onServerEvent({ kind: 'client_move', client_id: 1, nickname: 'Me', from_channel_id: 1, to_channel_id: 2, reason: 'moved', invoker: { id: 9, name: 'Admin' }, is_self: true }, conn);
|
|
notifications._test.onServerEvent({ kind: 'channel_edited', channel_id: 2, name: 'Other', invoker: { id: 1, name: 'Me' } }, conn);
|
|
const keys = eventLog(conn).map((e) => e.key);
|
|
assert.deepEqual(keys, ['notify.log.moved_in', 'notify.log.banned_other', 'notify.log.you_were_moved', 'notify.log.channel_edited']);
|
|
assert.equal(eventLog(conn)[1].params.invoker, 'Admin');
|
|
});
|
|
|
|
test('snapshot diff reports recording in your channel and switching into a recorded channel', () => {
|
|
const conn = connection('c2');
|
|
notifications._test.onSnapshot(conn.snap, conn);
|
|
const next = structuredClone(conn.snap);
|
|
next.clients[1].is_recording = true;
|
|
conn.snap = next;
|
|
notifications._test.onSnapshot(next, conn);
|
|
const moved = structuredClone(next);
|
|
moved.clients[0].channel_id = 2;
|
|
moved.clients.push({ id: 7, uid: 'rec=', nickname: 'Rec', channel_id: 2, is_self: false, is_recording: true });
|
|
conn.snap = moved;
|
|
notifications._test.onSnapshot(moved, conn);
|
|
assert.deepEqual(eventLog(conn).map((e) => [e.key, e.params.name]), [
|
|
['notify.log.someone_started_recording', 'Alice'],
|
|
['notify.log.switched_to_recording', 'Rec'],
|
|
]);
|
|
});
|
|
|
|
test('recording state: cues on transitions only, pause/resume, connection-bound commands', async () => {
|
|
const conn = connection('c3');
|
|
S.viewId = 'c3';
|
|
S.prefs.recordingFolder = 'C:\\rec';
|
|
answer = async (_id, cmd) => ({ ok: true, result: cmd === 'recording_start' ? { isRecording: true, outputPath: 'C:\\rec\\2026-11-01_10-00-00', tracks: [] } : { isPaused: true } });
|
|
await recording.startRecording(conn);
|
|
const start = requests.find((r) => r.cmd === 'recording_start');
|
|
assert.equal(start.connectionId, 'c3');
|
|
assert.equal(start.args.directory, 'C:\\rec');
|
|
assert.equal(start.args.mode, 3);
|
|
assert.match(start.args.label, /^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$/);
|
|
assert.deepEqual(recording.recordingState(conn), { recording: true, paused: false });
|
|
await recording.togglePause(conn);
|
|
assert.deepEqual(recording.recordingState(conn), { recording: true, paused: true });
|
|
const log = eventLog(conn).map((e) => e.key);
|
|
assert.deepEqual(log.slice(-2), ['notify.log.recording_started', 'notify.log.recording_paused']);
|
|
recording._test.applyState(conn, { isRecording: false, isPaused: false });
|
|
assert.deepEqual(recording.recordingState(conn), { recording: false, paused: false });
|
|
assert.equal(eventLog(conn).at(-1).key, 'notify.log.recording_stopped');
|
|
});
|
|
|
|
test('recording without a chosen folder asks main for the folder first; cancel starts nothing', async () => {
|
|
const conn = connection('c4');
|
|
S.prefs.recordingFolder = null;
|
|
globalThis.teamspeach.pickRecordingFolder = async () => ({ ok: true, path: null });
|
|
await recording.startRecording(conn);
|
|
assert.equal(requests.filter((r) => r.cmd === 'recording_start').length, 0);
|
|
});
|
|
|
|
test('helpers', () => {
|
|
const { localLabel, formatElapsed, formatBytes } = recording._test;
|
|
assert.equal(localLabel(new Date(2026, 10, 1, 9, 5, 7)), '2026-11-01_09-05-07');
|
|
assert.equal(formatElapsed(48000 * 3725), '01:02:05');
|
|
assert.equal(formatBytes(1536), '1.5 KB');
|
|
});
|
|
|
|
test('lock mute only touches the microphone connection and never undoes a user mute', async () => {
|
|
const a = connection('ca');
|
|
const b = connection('cb');
|
|
b.inputEnabled = true;
|
|
await os._test.onLock(true);
|
|
assert.deepEqual(requests.map((r) => [r.connectionId, r.args]), [['cb', { input_muted: true }]]);
|
|
b.audio.input_muted = true;
|
|
await os._test.onLock(false);
|
|
assert.deepEqual(requests.at(-1), { connectionId: 'cb', cmd: 'set_audio', args: { input_muted: false } });
|
|
assert.equal(requests.filter((r) => r.connectionId === a.id).length, 0);
|
|
|
|
// Already muted by the user before locking: nothing to restore.
|
|
requests.length = 0;
|
|
b.audio.input_muted = true;
|
|
await os._test.onLock(true);
|
|
await os._test.onLock(false);
|
|
assert.equal(requests.length, 0);
|
|
|
|
// Microphone moved to another connection (or the session ended) while locked: stays muted.
|
|
b.audio.input_muted = false;
|
|
await os._test.onLock(true);
|
|
b.audio.input_muted = true;
|
|
b.session += 1;
|
|
await os._test.onLock(false);
|
|
assert.equal(requests.filter((r) => r.args.input_muted === false).length, 0);
|
|
|
|
// Feature off: no action at all.
|
|
requests.length = 0;
|
|
S.prefs.osMuteWhenLocked = false;
|
|
b.audio.input_muted = false;
|
|
await os._test.onLock(true);
|
|
assert.equal(requests.length, 0);
|
|
});
|
|
|
|
test('unlock waits for an in-flight lock mute and never targets another session', async () => {
|
|
const conn = connection('lock-race');
|
|
conn.inputEnabled = true;
|
|
let finishMute;
|
|
answer = async (_id, _cmd, args) => {
|
|
if (args.input_muted) await new Promise((resolve) => { finishMute = () => { conn.audio.input_muted = true; resolve(); }; });
|
|
return { ok: true, result: {} };
|
|
};
|
|
const locked = os._test.onLock(true);
|
|
await Promise.resolve();
|
|
const unlocked = os._test.onLock(false);
|
|
finishMute();
|
|
await Promise.all([locked, unlocked]);
|
|
assert.deepEqual(requests.map((r) => r.args.input_muted), [true, false]);
|
|
});
|
|
|
|
test('recording folder selection cannot start a reconnected session', async () => {
|
|
const conn = connection('folder-race');
|
|
S.prefs.recordingFolder = null;
|
|
globalThis.teamspeach.pickRecordingFolder = async () => {
|
|
conn.session += 1;
|
|
return { ok: true, path: 'C:\\rec' };
|
|
};
|
|
await recording.startRecording(conn);
|
|
assert.equal(requests.length, 0);
|
|
});
|
|
|
|
test('advanced event state overrides only that event, not its group or siblings', () => {
|
|
S.prefs.notificationStates = { message_received: 0, event_message_received_poked: 2 };
|
|
assert.equal(notifications.eventState('message_received', 'poked'), 2);
|
|
assert.equal(notifications.eventState('message_received', 'text_client'), 0);
|
|
assert.equal(settingState('message_received'), 0);
|
|
});
|
|
|
|
test('advanced options: upgrades keep overrides active, Hide needs confirmation and keeps them for Show Advanced', async () => {
|
|
const { isAdvanced, showAdvanced, hideAdvanced, eventState } = notifications;
|
|
const legacy = { message_received: 0, event_message_received_poked: 2 };
|
|
prefs.notificationStates = structuredClone(legacy);
|
|
S.prefs = { notificationStates: structuredClone(legacy) };
|
|
const flags = { away: true, outputMuted: true };
|
|
// Saved before the advanced flag existed: the override stays active instead of being discarded.
|
|
assert.equal(isAdvanced('message_received'), true);
|
|
assert.equal(eventState('message_received', 'poked'), STATE.IMPORTANT);
|
|
assert.equal(soundAllowed('message_received', eventState('message_received', 'poked'), flags, 'TextMessage.PokedFromAnotherClient'), true);
|
|
|
|
const asked = [];
|
|
const reply = (confirmed) => async (anchor, data) => { asked.push(data); return { confirmed, skipInFuture: false }; };
|
|
assert.equal(await hideAdvanced('message_received', null, reply(false)), false);
|
|
assert.equal(asked.length, 1);
|
|
assert.equal(asked[0].requiresConfirmationCheckbox, false);
|
|
assert.deepEqual(S.prefs.notificationStates, legacy, 'cancel writes nothing');
|
|
assert.equal(eventState('message_received', 'poked'), STATE.IMPORTANT);
|
|
|
|
assert.equal(await hideAdvanced('message_received', null, reply(true)), true);
|
|
assert.equal(isAdvanced('message_received'), false);
|
|
assert.deepEqual(S.prefs.notificationStates, { ...legacy, advanced_message_received: 0 }, 'the event state stays stored, as in the original');
|
|
assert.equal(eventState('message_received', 'poked'), STATE.DISABLED, 'confirmed hide makes the coalesced state decide');
|
|
assert.equal(soundAllowed('message_received', eventState('message_received', 'poked'), flags, 'TextMessage.PokedFromAnotherClient'), false);
|
|
|
|
await showAdvanced('message_received');
|
|
assert.equal(isAdvanced('message_received'), true);
|
|
assert.equal(eventState('message_received', 'poked'), STATE.IMPORTANT, 'Show Advanced restores the stored choice');
|
|
assert.equal(eventState('message_received', 'text_client'), STATE.DISABLED, 'events without a choice follow the setting');
|
|
assert.deepEqual(prefs.notificationStates, S.prefs.notificationStates, 'every change went through the preference bridge');
|
|
|
|
});
|
|
|
|
test('appearance defaults and exact dataset choices do not use page zoom', async () => {
|
|
const { applyAppearance } = await import('../app/renderer/js/appearance.js');
|
|
assert.deepEqual(applyAppearance({}), { displaySize: 'medium', treeStyle: 'detailed', chatStyle: 'detailed' });
|
|
assert.deepEqual(applyAppearance({ displaySize: 'small', treeStyle: 'compact', chatStyle: 'compact' }), { displaySize: 'small', treeStyle: 'compact', chatStyle: 'compact' });
|
|
assert.equal(document.documentElement.dataset.displaySize, 'small');
|
|
assert.equal(document.documentElement.dataset.treeStyle, 'compact');
|
|
});
|
|
|
|
test('notification output preferences configure an independent device without opening audio', async () => {
|
|
const { notificationOutputState, notificationSink } = await import('../app/renderer/js/audio/notify-output.js');
|
|
S.prefs.notificationDeviceId = 'fixture-notifications';
|
|
S.prefs.notificationLevelDb = -31;
|
|
S.prefs.outputDeviceId = 'fixture-voice';
|
|
notifications.applyNotificationOutputPreferences();
|
|
assert.equal(notificationOutputState().deviceId, 'fixture-notifications');
|
|
assert.equal(notificationOutputState().levelDb, -31);
|
|
assert.equal(notificationSink(), 'fixture-notifications');
|
|
S.prefs.notificationDeviceId = 'voice';
|
|
notifications.applyNotificationOutputPreferences();
|
|
assert.equal(notificationSink(), 'fixture-voice');
|
|
S.prefs.notificationDeviceId = 'none';
|
|
notifications.applyNotificationOutputPreferences();
|
|
assert.equal(notificationSink(), null);
|
|
});
|
|
|
|
test('preference saves unwrap the bridge envelope and retain prior state on failure', async () => {
|
|
const setPrefs = globalThis.teamspeach.setPrefs;
|
|
const osApply = globalThis.teamspeach.osApply;
|
|
try {
|
|
let applied = 0;
|
|
globalThis.teamspeach.osApply = async () => { applied++; return { ok: true }; };
|
|
for (const save of [notifications._test.saveNotificationPrefs, os._test.savePrefs]) {
|
|
S.prefs = { theme: 'light', recordingMode: 3 };
|
|
globalThis.teamspeach.setPrefs = async (partial) => ({ ok: true, prefs: { ...S.prefs, ...partial } });
|
|
await save({ notificationDeviceId: 'none' });
|
|
assert.deepEqual(S.prefs, { theme: 'light', recordingMode: 3, notificationDeviceId: 'none' });
|
|
assert.equal(S.prefs.ok, undefined);
|
|
const previous = S.prefs;
|
|
const beforeApply = applied;
|
|
globalThis.teamspeach.setPrefs = async () => ({ ok: false, error: { message: 'fixture write failure' } });
|
|
await assert.rejects(save({ theme: 'dark' }), /fixture write failure/);
|
|
assert.equal(S.prefs, previous);
|
|
assert.equal(applied, beforeApply);
|
|
}
|
|
} finally {
|
|
globalThis.teamspeach.setPrefs = setPrefs;
|
|
globalThis.teamspeach.osApply = osApply;
|
|
}
|
|
});
|
|
|
|
test('events request the official sound file of their sub type, with the official per-file throttle', () => {
|
|
const conn = connection('s1');
|
|
S.prefs.notificationDeviceId = 'voice';
|
|
S.prefs.notificationStates = { talking_while_muted: STATE.ENABLED };
|
|
notifications.applyNotificationOutputPreferences();
|
|
const { lastPlayed, onServerEvent, onState, onText, onAudioState, onSnapshot } = notifications._test;
|
|
// Every requested file passes through lastPlayed.set; throttle state is kept between cases.
|
|
const requested = [];
|
|
lastPlayed.clear();
|
|
lastPlayed.set = function set(file, time) { requested.push(file); return Map.prototype.set.call(this, file, time); };
|
|
const files = (fn) => { requested.length = 0; fn(); return [...requested]; };
|
|
const other = (kind, reason, from, to, extra = {}) => onServerEvent({ kind, client_id: 5, nickname: 'Bob', from_channel_id: from, to_channel_id: to, reason, invoker: null, is_self: false, ...extra }, conn);
|
|
const self = (kind, reason) => onServerEvent({ kind, client_id: 1, nickname: 'Me', from_channel_id: 1, to_channel_id: 2, reason, invoker: { id: 9, name: 'Admin' }, is_self: true }, conn);
|
|
const cases = [
|
|
[() => other('client_move', 'none', 2, 1), 'neutral_switched_tocurrentchannel'],
|
|
[() => other('client_move', 'moved', 2, 1), 'neutral_moved_tocurrentchannel'],
|
|
[() => other('client_move', 'kick_channel', 2, 1), 'neutral_kicked_channel_tocurrentchannel'],
|
|
[() => other('client_move', 'subscription', 2, 1), null],
|
|
[() => other('client_move', 'none', 1, 2), 'neutral_switched_awayfromcurrentchannel'],
|
|
[() => other('client_move', 'moved', 1, 2), 'neutral_moved_awayfromcurrentchannel'],
|
|
[() => other('client_move', 'kick_channel', 1, 2), 'neutral_kicked_channel_awayfromcurrentchannel'],
|
|
[() => other('client_enter', 'none', 0, 1), 'neutral_connection_connected_currentchannel'],
|
|
[() => other('client_leave', 'disconnect', 1, 0), 'neutral_connection_disconnected_currentchannel'],
|
|
[() => other('client_leave', 'lost_connection', 1, 0), 'neutral_connection_connectionlost_currentchannel'],
|
|
[() => other('client_leave', 'kick_server', 1, 0), 'neutral_kicked_server_currentchannel'],
|
|
[() => other('client_leave', 'ban', 1, 0), 'neutral_banned_server_currentchannel'],
|
|
[() => self('client_move', 'none'), 'channel_switched'],
|
|
[() => self('client_move', 'moved'), 'you_were_moved'],
|
|
[() => self('client_move', 'kick_channel'), 'you_kicked_channel'],
|
|
[() => self('client_leave', 'kick_server'), 'you_kicked_server'],
|
|
[() => self('client_leave', 'ban'), 'you_were_banned'],
|
|
[() => onServerEvent({ kind: 'channel_edited', channel_id: 1, name: 'Lobby', invoker: { id: 9, name: 'Admin' } }, conn), 'your_channel_was_edited'],
|
|
[() => onServerEvent({ kind: 'channel_edited', channel_id: 2, name: 'Other', invoker: { id: 9, name: 'Admin' } }, conn), null],
|
|
[() => onServerEvent({ kind: 'channel_created', channel_id: 3, name: 'New', invoker: { id: 1, name: 'Me' } }, conn), 'channel_created'],
|
|
[() => onServerEvent({ kind: 'server_edited', invoker: { id: 1, name: 'Me' } }, conn), 'you_edited_server'],
|
|
[() => onServerEvent({ kind: 'server_edited', invoker: { id: 9, name: 'Admin' } }, conn), null],
|
|
[() => onServerEvent({ kind: 'talk_request', client_id: 5, requested: true, invoker: null }, conn), 'talkpower_requested'],
|
|
[() => onServerEvent({ kind: 'talker_changed', client_id: 1, is_talker: true, invoker: null }, conn), 'talkpower_granted'],
|
|
[() => onText({ target: 'poke', from_client_id: 5, from_nickname: 'Alice', message: 'hi' }, conn), 'you_were_poked'],
|
|
[() => onText({ target: 'channel', from_client_id: 5, from_nickname: 'Alice', message: 'hi' }, conn), 'chat_message_inbound'],
|
|
[() => notifications.notify('message_sent', conn), 'chat_message_outbound'],
|
|
[() => onState({ state: 'connected', address: 'fixture.invalid' }, conn), 'connected'],
|
|
[() => onState({ state: 'disconnected', reason: { code: 'x', detail: { reason: 'timeout' } } }, conn), 'connection_lost'],
|
|
[() => onState({ state: 'disconnected', reason: { code: 'connect_failed' } }, conn), 'error'],
|
|
[() => onAudioState({ input_muted: false, output_muted: false }, conn), null],
|
|
[() => onAudioState({ input_muted: true, output_muted: false }, conn), 'mic_muted'],
|
|
[() => onAudioState({ input_muted: false, output_muted: false }, conn), 'mic_activated'],
|
|
[() => notifications.notify('whisper_while_muted', conn), 'stop_talking'],
|
|
[() => notifications.notify('whisper_while_muted', conn), null],
|
|
[() => notifications.notify('talking_while_muted', conn), 'stop_talking'],
|
|
[() => notifications.notify('whisper_error', conn), 'no_whisper_target_found'],
|
|
[() => notifications.notify('whisper_received', conn), 'whisper_received'],
|
|
[() => notifications.notify('stream_started', conn), 'stream_started'],
|
|
[() => notifications.playEventSound('recording_paused', conn), 'recording_paused'],
|
|
[() => notifications.playEventSound('recording_paused', conn), null],
|
|
];
|
|
try {
|
|
for (const [fn, file] of cases) assert.deepEqual(files(fn), file ? [file] : [], `${fn}`);
|
|
onSnapshot(conn.snap, conn);
|
|
const assigned = structuredClone(conn.snap);
|
|
assigned.clients[0].server_groups = [8, 9];
|
|
conn.snap = assigned;
|
|
assert.deepEqual(files(() => onSnapshot(assigned, conn)), ['servergroup_assigned']);
|
|
const channelGroup = structuredClone(assigned);
|
|
channelGroup.clients[0].channel_group_id = 5;
|
|
conn.snap = channelGroup;
|
|
assert.deepEqual(files(() => onSnapshot(channelGroup, conn)), ['channelgroup_changed']);
|
|
const away = structuredClone(channelGroup);
|
|
away.clients[0].away = true;
|
|
conn.snap = away;
|
|
assert.deepEqual(files(() => onSnapshot(away, conn)), ['away_activated']);
|
|
S.prefs.notificationDeviceId = 'none';
|
|
notifications.applyNotificationOutputPreferences();
|
|
assert.deepEqual(files(() => notifications.notify('message_sent', conn)), [], 'device "none" never requests a file');
|
|
} finally {
|
|
delete lastPlayed.set;
|
|
}
|
|
});
|
|
|
|
void env;
|
|
|
|
test('category mute overrides important event sounds without erasing per-event choices or logs', () => {
|
|
const conn = connection('c1');
|
|
S.prefs.notificationStates = { group_messaging: 0, message_received: 2, event_message_received_poked: 2, connected: 2 };
|
|
const before = structuredClone(S.prefs.notificationStates);
|
|
const flags = { away: false, outputMuted: false };
|
|
assert.equal(soundAllowed('message_received', notifications.eventState('message_received', 'poked'), flags, 'TextMessage.PokedFromAnotherClient'), false);
|
|
assert.equal(soundAllowed('connected', settingState('connected'), flags, 'ConnectStatus.Connected'), true);
|
|
assert.equal(notifications.notify('message_received', conn, { sound: 'TextMessage.PokedFromAnotherClient', logKey: 'notify.log.poked', params: { name: 'Peer', message: 'Hello' } }), false);
|
|
assert.equal(notifications.eventLog(conn).at(-1).params.message, 'Hello');
|
|
assert.deepEqual(S.prefs.notificationStates, before);
|
|
S.prefs.notificationStates.group_messaging = 1;
|
|
assert.equal(notifications.eventState('message_received', 'poked'), 2);
|
|
assert.equal(soundAllowed('message_received', 2, { away: true, outputMuted: true }, 'TextMessage.PokedFromAnotherClient'), true);
|
|
});
|