39 lines
1.9 KiB
JavaScript
39 lines
1.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { buildDeviceOptions } from '../app/renderer/js/audio/devices.js';
|
|
|
|
test('without media permission Chromium returns one anonymous entry: reported as redacted, not as a device', () => {
|
|
const r = buildDeviceOptions([{ deviceId: '', label: '' }], '');
|
|
assert.equal(r.redacted, true);
|
|
assert.equal(r.physical, 0);
|
|
assert.deepEqual(r.options.map((o) => o.value), ['']);
|
|
});
|
|
|
|
test('aliases are folded into the default option, physical endpoints listed with real ids', () => {
|
|
const list = [
|
|
{ deviceId: 'default', label: '\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e - Mic/Line/Inst 1-2 (MiniFuse 4)' },
|
|
{ deviceId: 'communications', label: '\u0421\u0432\u044f\u0437\u044c - Mic/Line/Inst 1-2 (MiniFuse 4)' },
|
|
{ deviceId: 'a1b2c3d4e5', label: 'Mic/Line/Inst 1-2 (MiniFuse 4)' },
|
|
{ deviceId: 'f6g7h8i9j0', label: '\u041c\u0438\u043a\u0440\u043e\u0444\u043e\u043d (DroidCam Audio)' },
|
|
];
|
|
const r = buildDeviceOptions(list, '');
|
|
assert.equal(r.redacted, false);
|
|
assert.equal(r.physical, 2);
|
|
assert.ok(r.options[0].label.includes(list[2].label));
|
|
assert.equal(r.options[2].label, list[3].label);
|
|
assert.deepEqual(r.options.slice(1).map((o) => o.value), ['a1b2c3d4e5', 'f6g7h8i9j0']);
|
|
});
|
|
|
|
test('an unnamed physical device keeps its real id and an honest label', () => {
|
|
const r = buildDeviceOptions([{ deviceId: 'zz99yy88xx77', label: '' }], '');
|
|
assert.equal(r.options[1].value, 'zz99yy88xx77');
|
|
assert.ok(r.options[1].label.includes('zz99yy88'));
|
|
});
|
|
|
|
test('a saved device that is currently absent stays selectable and is labelled as missing', () => {
|
|
const r = buildDeviceOptions([{ deviceId: 'a1', label: 'A' }], 'gone-device');
|
|
assert.equal(r.options.at(-1).value, 'gone-device');
|
|
assert.ok(r.options.at(-1).label.length > 0);
|
|
assert.equal(r.options.length, 3);
|
|
});
|