repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/test-fixtures/ui/controls.mjs
Rawimport assert from 'node:assert/strict';
export default async function runControls({ ipc, input, key, click, check, screenshot, delay }) {
let state;
state = await check('initial bindings and focus', s => !s.muted && !s.checked && s.volume === 0.3 && s.sliderValue === 0.3 && s.focus === 'mute');
assert.equal(state.width, 1280, 'headless output width');
assert.equal(state.height, 720, 'headless output height');
for (const name of ['surface', 'mute', 'slider', 'field']) {
const rect = state[name];
assert(rect.x >= 0 && rect.y >= 0 && rect.width > 0 && rect.height > 0 && rect.x + rect.width <= state.width && rect.y + rect.height <= state.height, `${name} outside mapped surface`);
}
await screenshot('initial');
click(state.mute);
state = await check('pointer toggles owner and checked state', s => s.muted && s.checked && s.writes === 1);
key('space');
await check('space activates focused button', s => !s.muted && !s.checked && s.writes === 2);
key('Return');
await check('enter activates focused button', s => s.muted && s.checked && s.writes === 3);
key('Tab');
await check('tab reaches slider', s => s.focus === 'slider');
key('Right');
await check('arrow updates slider owner', s => Math.abs(s.volume - 0.35) < 0.001 && s.sliderValue === s.volume);
click({ ...state.slider, width: state.slider.width * 1.5 });
await check('pointer updates slider owner', s => Math.abs(s.volume - 0.75) < 0.02 && s.sliderValue === s.volume);
key('Left');
await check('left arrow decreases slider owner', s => Math.abs(s.volume - 0.7) < 0.02 && s.sliderValue === s.volume);
key('Tab');
await check('tab reaches text input', s => s.focus === 'field');
input('type', 'headphones');
await check('text input updates fixture query', s => s.queryIsHeadphones && s.queryMatchesInput);
key('Return');
await check('enter accepts text field', s => s.accepted === 1);
key('Escape');
await check('escape cancels text field', s => s.cancelled === 1);
key('shift+Tab');
await check('reverse traversal reaches slider', s => s.focus === 'slider');
key('shift+Tab');
state = await check('reverse traversal reaches button', s => s.focus === 'mute');
const writes = state.writes;
ipc('external', 'true', '0.6', 'false');
state = await check('external state updates controls without writeback', s => s.muted && s.checked && s.volume === 0.6 && s.sliderValue === 0.6 && !s.enabled && s.writes === writes);
click(state.mute);
key('space');
click(state.slider);
key('Right');
click(state.field);
input('type', ' test');
await check('disabled controls reject input before the next field edit', s => s.queryIsEdited && s.queryMatchesInput && s.writes === writes);
input('mousemove', String(state.width - 10), String(state.height - 10));
await check('pointer leaves button tooltip', s => !s.tooltipVisible);
await screenshot('external-disabled');
for (const value of [0, 0.25, 0.75, 1]) {
ipc('external', 'false', String(value), 'true');
state = await check(`external slider value ${value} is visible`, s => s.sliderValue === value);
const before = state.writes;
click(state.sliderThumb);
state = await check(`pressing thumb at ${value} does not jump or write`, s => s.writes === before && s.volume === value && s.focus === 'slider');
}
input('mousemove', String(state.sliderThumb.x + state.sliderThumb.width / 2), String(state.sliderThumb.y + state.sliderThumb.height / 2));
input('mousedown', '1');
await check('thumb drag holds pointer grab', s => s.sliderPressed);
for (const value of [0.75, 0.25, 0]) {
input('mousemove', String(Math.round(state.slider.x + 8 + (state.slider.width - 16) * value)), String(state.slider.y + state.slider.height / 2));
await check(`continuous thumb drag reaches ${value}`, s => s.sliderPressed && Math.abs(s.volume - value) < 0.01);
}
input('mouseup', '1');
await check('thumb release ends drag', s => !s.sliderPressed);
assert(state.extras.cardSelectionMarked, 'an active interactive card marks its selection beyond the tint');
click({ ...state.extras.card, width: 36 });
state = await check('interactive card primary activation is focused', s => s.extras.cardWrites === 1 && s.extras.cardFocused);
key('Tab');
await check('Tab reaches nested card action without focusing its parent', s => s.extras.nestedFocused && !s.extras.cardFocused);
key('space');
state = await check('nested action dispatches without parent activation', s => s.extras.nestedWrites === 1 && s.extras.cardWrites === 1);
key('Tab');
state = await check('Tab reaches named icon action', s => s.extras.iconFocused && s.extras.iconName === 'refresh devices' && s.extras.sliderName === 'output volume');
input('mousemove', String(state.width - 10), String(state.height - 10));
await check('keyboard focus exposes themed icon tooltip', s => s.extras.iconTooltipVisible);
await screenshot('keyboard-tooltip');
input('mousemove', ...[state.extras.longButton.x + 8, state.extras.longButton.y + 8].map(String));
await check('a hovered tooltip replaces the focused one', s => s.extras.longTooltipVisible && !s.extras.iconTooltipVisible && s.extras.iconFocused);
await screenshot('single-tooltip');
input('mousemove', String(state.width - 10), String(state.height - 10));
await check('leaving the hovered control leaves no tooltip', s => !s.extras.longTooltipVisible && !s.extras.iconTooltipVisible);
input('keydown', 'Return');
await delay(800);
state = await check('held Enter does not repeatedly dispatch', s => s.extras.iconWrites === 0);
input('keyup', 'Return');
await check('Enter release dispatches exactly once', s => s.extras.iconWrites === 1);
input('keydown', 'space');
await delay(800);
await check('held Space does not repeatedly dispatch', s => s.extras.iconWrites === 1);
input('keyup', 'space');
await check('Space release dispatches exactly once', s => s.extras.iconWrites === 2);
click(state.extras.disabled);
await check('disabled control never dispatches', s => s.extras.disabledWrites === 0);
click({ ...state.extras.field, width: 4 });
await check('field padding focuses editor with its empty hint', s => s.extras.fieldFocused && s.extras.fieldHintVisible);
input('type', 'padding');
await check('typing after padding click edits normally', s => s.extras.fieldEdited && !s.extras.fieldHintVisible);
input('mousemove', ...[state.extras.longButton.x + 8, state.extras.longButton.y + 8].map(String));
await check('long useful tooltip opens on pointer hover', s => s.extras.longTooltipVisible);
await screenshot('wrapped-tooltip');
input('mousemove', String(state.width - 10), String(state.height - 10));
await check('leaving tooltip trigger dismisses it', s => !s.extras.longTooltipVisible);
await screenshot('controls-repaired');
console.log('shared-control UI assertions passed; screenshots require visual review');
}