repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/features/audio/fixtures/suite.mjs
Raw// `just ui-test audio`: the registry audio feature in the real Bar inside nested
// niri, driven by real pointer and keyboard against the feature's Audio double.
// The suite contract (snapshot shape, helpers) is documented in .system/RULES.md.
const slider = 'fixture output output volume';
const card = 'fixture output options';
export default async function audioSuite({ assert, snapshot, open, check, click, input, key, screenshot, within, call }) {
const audio = value => value.features.audio;
const control = (value, name) => audio(value).controls[name];
const service = value => audio(value).service;
let state = snapshot();
assert.equal(state.chips.audio.label, 'audio', 'registry bar label');
assert.equal(state.chips.audio.active, false, 'registry bar activity');
// Retained device expansion through the real loader.
state = await open('audio', value => control(value, slider)?.rect && control(value, card)?.rect);
await check('opening focuses the default output volume', value => control(value, slider)?.focused);
click(control(state, card).rect);
await check('audio device card expands its options', value => audio(value).retained.expandedSink === 'sink-fixture');
key('Escape');
await check('Escape closes the expanded audio panel', value => !value.popup.open);
state = await open('audio', value => control(value, slider)?.rect);
await check('registry-retained device expansion survives close and reopen', value => audio(value).retained.expandedSink === 'sink-fixture');
click(control(state, card).rect);
state = await check('audio device options collapse again', value => audio(value).retained.expandedSink === '' && control(value, slider)?.rect);
// Mute is on the row itself, not behind the options.
const mute = control(state, 'mute fixture output');
assert(mute && mute.rect.width >= 24 && mute.rect.height >= 24, 'each device row shows a mute button with a 24 px target');
click(mute.rect);
state = await check('the row mute button mutes without opening the options', value => service(value).muteWrites === 1 && audio(value).retained.expandedSink === '');
assert.equal(service(state).osdRequests, 0, 'muting in the open panel asks for no volume overlay');
// Slider drag keeps its delegate through an external update.
const drag = control(state, slider);
const at = ratio => [String(Math.round(drag.rect.x + drag.rect.width * ratio)), String(Math.round(drag.rect.y + drag.rect.height / 2))];
const held = value => control(value, slider)?.pressed && control(value, slider).id === drag.id;
input('mousemove', ...at(0.2));
input('mousedown', '1');
input('mousemove', ...at(0.58));
state = await check('audio slider drag writes while retaining the real delegate', value => held(value) && service(value).volumeWrites > 0);
const writesDuringDrag = service(state).volumeWrites;
call('audio', 'externalUpdate');
await check('external audio update does not interrupt the held drag', value => held(value) && service(value).externalUpdates === 1 && service(value).volumeWrites === writesDuringDrag);
input('mousemove', ...at(0.82));
input('mouseup', '1');
state = await check('audio drag completes after the external update', value =>
!control(value, slider)?.pressed && control(value, slider)?.id === drag.id && service(value).volumeWrites > writesDuringDrag && service(value).volume > 0.8);
await screenshot('audio-drag-update');
assert.equal(service(state).osdRequests, 0, 'dragging in the open panel asks for no volume overlay');
// Keys and IPC reach the service without the panel's quiet flag.
call('audio', 'setVolume', 'sink-fixture', 0.9);
state = await check('a volume change from outside the panel asks for the overlay', value => service(value).osdRequests === 1);
// A device known only by its ALSA node name reads as its kind.
call('audio', 'setMachineNames', true);
state = await check('a nameless input device reads as input device, never its node name', value =>
control(value, 'input device options') && control(value, 'mute input device') && control(value, 'input device input volume') &&
audio(value).texts.includes('input device · default') && !audio(value).texts.some(text => text.includes('alsa_')));
await screenshot('audio-device-names');
call('audio', 'setMachineNames', false);
state = await check('the nameless input leaves again', value => !control(value, 'input device options') && control(value, slider)?.rect);
// Keyboard traversal reveals every focused control in a long list.
call('audio', 'showManyDevices');
for (let i = 0; i < 27; i++) {
key('Tab');
state = await check(`audio keyboard traversal keeps control visible ${i}`, value => {
const focused = Object.values(audio(value).controls).find(item => item.focused);
const panel = audio(value).surface;
return focused && panel && focused.rect.y >= panel.y && focused.rect.y + focused.rect.height <= panel.y + panel.height;
});
}
const retainedScroll = audio(state).retained.scrollY;
assert(retainedScroll > 0, 'long audio list must actually scroll');
await screenshot('audio-keyboard-scroll');
// Retained scroll survives switching to another popup and back.
state = await open('media', value => value.features.media.items.transportActions?.rect);
click(state.chips.audio.rect);
await check('registry-retained audio scroll survives switching away and back', value => value.popup.name === 'audio' && value.popup.windowActive && audio(value).retained.scrollY === retainedScroll);
// Microphone use keeps the chip's name and width; the dot and the name say it.
key('Escape');
state = await check('Escape closes audio before the privacy chip', value => !value.popup.open);
const restingChip = state.chips.audio.rect;
call('audio', 'setMicActive', true);
await check('microphone use marks the audio chip with its dot and names it', value =>
value.chips.audio.label === 'audio' && value.chips.audio.active === true && value.chips.audio.mark === 'activity' &&
value.chips.audio.accessibleName === 'microphone in use' && value.chips.audio.rect.width === restingChip.width);
await screenshot('audio-privacy-chip');
call('audio', 'setMicActive', false);
await check('a closed microphone quiets the audio chip', value => !value.chips.audio.active && value.chips.audio.accessibleName === 'audio');
state = await open('audio', value => value.popup.windowActive && control(value, slider)?.rect);
// No devices: one sentence with its next step in the compact empty popup.
const emptyState = value => audio(value).items.audioEmptyState;
const compactEmpty = value => emptyState(value)?.rect && !control(value, slider) && value.popup.card.width === 352 && value.popup.card.height === 88;
call('audio', 'setNoDevices', true);
state = await check('no audio devices shrinks the popup to one sentence with a next step', value =>
compactEmpty(value) && audio(value).texts.includes('no audio devices') && audio(value).texts.includes('connect speakers or a microphone'));
assert(within(emptyState(state).rect, state.width, state.height), 'empty audio state outside output');
await screenshot('audio-no-devices');
call('audio', 'setPipewireReady', false);
state = await check('a missing audio service says so in words', value =>
compactEmpty(value) && audio(value).texts.includes('audio service not running') && audio(value).texts.includes('start pipewire to control sound'));
await screenshot('audio-no-service');
call('audio', 'setPipewireReady', true);
call('audio', 'setNoDevices', false);
await check('arriving devices restore the audio sections without reopening', value =>
!emptyState(value) && control(value, slider)?.rect && value.popup.name === 'audio' &&
// The long device list outgrows the 520 px registry maximum and scrolls inside it.
value.popup.card.height === 504 && value.popup.panelHeight + 48 > 520 && within(value.popup.card, value.width, value.height));
}