repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/features/config/fixtures/suite.mjs
Raw// Generic renderer driven by Registry declarations; native execution is proved
// separately in production.mjs. Never reads or serializes editable field values.
export default async function configSuite({ assert, snapshot, open, check, click, key, screenshot, call, fixture, delay, focusedWindow, within }) {
const config = value => value.features.config;
const service = value => config(value).service;
const control = (value, name) => config(value).controls[name];
const text = (value, line) => config(value).texts.includes(line);
const brightness = value => value.features.brightness.service;
async function focus(name) {
for (let i = 0; i < 24; i++) {
if (control(snapshot(), name)?.focused) return snapshot();
key('Tab');
await delay(50);
}
assert.fail(name + ' is not keyboard reachable');
}
async function activate(name) {
let previous = '';
const state = await check('Config ' + name + ' has settled pointer geometry', value => {
const target = control(value, name);
if (!target?.enabled || !fits(value)) return false;
const geometry = JSON.stringify([value.popup.card, config(value).controls]);
const settled = geometry === previous;
previous = geometry;
return settled;
});
click(control(state, name).rect);
}
function fits(value) {
const surface = config(value).surface, card = value.popup.card;
const controls = Object.values(config(value).controls);
return surface && card && card.width <= 680 && card.height <= 600 &&
controls.every(({rect}) => rect.x >= surface.x && rect.y >= surface.y &&
rect.x + rect.width <= surface.x + surface.width && rect.y + rect.height <= surface.y + surface.height) &&
controls.every(({rect: a}, index) => controls.slice(index + 1).every(({rect: b}) =>
a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y));
}
fixture('focus-target');
await check('focus target active before Config', value => value.focusTargetActive);
const focusId = focusedWindow().id;
let state = await open('config', value => control(value, 'appearance')?.rect);
state = await check('Config focuses selected section', value => control(value, 'appearance').focused && control(value, 'appearance').checked);
assert(control(state, 'dark mode').checked && fits(state));
await screenshot('config-appearance');
await activate('vertical bar');
await check('Config preference changes actual Bar and popup geometry', value =>
value.orientation === 'vertical' && value.barWidth === value.barThickness && control(value, 'vertical bar')?.checked &&
value.popup.card.x >= value.barThickness && fits(value));
await screenshot('config-orientation-vertical');
await activate('horizontal bar');
await check('same declaration restores horizontal Bar geometry', value =>
value.orientation === 'horizontal' && value.barWidth === value.width && control(value, 'horizontal bar')?.checked);
state = await focus('light mode');
key('Return');
state = await check('appearance sends one keyboard intent and exposes pending without changing observed mode', value =>
service(value).writes === 1 && service(value).busy && service(value).mode === 'dark' &&
!control(value, 'light mode').enabled && control(value, 'dark mode').checked && text(value, 'applying appearance'));
key('Return');
assert.equal(service(snapshot()).writes, 1);
await screenshot('config-appearance-pending');
call('config', 'finishMode', true);
state = await check('partial publication keeps selected light with actionable failure', value =>
service(value).mode === 'light' && control(value, 'light mode').checked &&
text(value, 'desktop preference incomplete; retry selected mode') && control(value, 'retry appearance')?.enabled);
await screenshot('config-appearance-partial');
await activate('retry appearance');
await check('retry sends the same selected mode exactly once', value =>
service(value).writes === 2 && service(value).requestedMode === 'light' && service(value).busy);
call('config', 'finishMode', false);
state = await check('retry settles without a stale failure', value =>
!service(value).busy && !service(value).error && !control(value, 'retry appearance') && control(value, 'light mode').checked);
call('config', 'externalUpdate', 'dark');
await check('external authority update rebinds choice without an intent', value =>
control(value, 'dark mode').checked && service(value).writes === 2);
const stages = ['preflight', 'authorization', 'installation', 'detection', 'reading', 'verification', 'ready'];
const setup = {
displays: [{ id: 'ddc:DP-1', name: 'fixture monitor', controllable: false, issue: 'needs setup' }],
global: { mode: 'none', level: 0, levels: [] },
setup: { needed: true, available: true, running: false, expanded: false, stages: stages.map(id => ({id, status: 'waiting', error: ''})) }
};
call('brightness', 'setState', setup);
// Arrow navigation selects sections; Shift+Tab returns through the same controls.
state = await focus('appearance');
key('Up');
state = await check('section arrows enter only Light form', value =>
service(value).selectedSection === 'light' && control(value, 'light').focused &&
control(value, 'set up monitor control') && !control(value, 'dark mode'));
key('Tab');
await check('Tab enters focused form', value => control(value, 'set up monitor control')?.focused);
key('shift+Tab');
await check('reverse Tab returns to sections', value => control(value, 'light')?.focused);
key('Down');
await check('reverse section arrow restores appearance', value => service(value).selectedSection === 'appearance' && control(value, 'dark mode'));
state = await open('brightness', value => value.features.brightness.controls['configure light']?.rect);
click(state.features.brightness.controls['configure light'].rect);
state = await check('real feature signal switches to its declared section', value =>
value.popup.name === 'config' && value.popup.windowActive && service(value).selectedSection === 'light' &&
control(value, 'set up monitor control')?.enabled && !brightness(value).sensorMonitoring);
await activate('set up monitor control');
await check('setup declaration routes once to Brightness preflight', value =>
brightness(value).setups === 1 && brightness(value).setup.running && control(value, 'cancel setup')?.enabled);
call('brightness', 'advanceSetup', 'authorization');
state = await check('authorization boundary is explicitly pending', value => text(value, 'step 2 of 7 · allow access'));
await activate('appearance');
await check('leaving Light does not cancel authorization or demand sensor', value =>
service(value).selectedSection === 'appearance' && brightness(value).setup.running &&
brightness(value).cancellations === 0 && !brightness(value).sensorMonitoring);
key('Escape');
await check('Escape closes Config without fabricating setup completion', value => !value.popup.open && brightness(value).setup.running);
await check('Escape returns native focus', value => value.focusTargetActive && focusedWindow()?.id === focusId);
state = await open('config', value => control(value, 'appearance')?.rect);
assert.equal(service(state).selectedSection, 'appearance');
await activate('light');
state = await check('Light re-entry keeps authorization state', value => control(value, 'cancel setup')?.enabled && text(value, 'step 2 of 7 · allow access'));
await activate('cancel setup');
await check('pre-install authorization cancellation stops the double operation', value =>
brightness(value).cancellations === 1 && !brightness(value).setup.running && control(value, 'retry setup')?.enabled);
await activate('retry setup');
call('brightness', 'setState', {
...setup,
setup: { ...setup.setup, expanded: true, running: true, privilegedEntered: true,
stages: stages.map((id, i) => ({id, status: i < 2 ? 'done' : i === 2 ? 'running' : 'waiting', error: ''})) }
});
state = await check('installer boundary displays current stage', value => text(value, 'step 3 of 7 · install ddcutil'));
await activate('cancel setup');
state = await check('installer cancellation keeps busy guard until native exit', value =>
brightness(value).setup.running && brightness(value).setup.cancelRequested &&
control(value, 'cancelling') && !control(value, 'cancelling').enabled && !control(value, 'retry setup') &&
text(value, 'cancel requested; waiting for package setup'));
await screenshot('config-installer-cancelling');
await activate('appearance');
key('Escape');
await check('dismissed Config continues tracking installer', value => !value.popup.open && brightness(value).setup.running);
call('brightness', 'finishCancellation');
state = await open('config', value => control(value, 'appearance')?.rect);
await activate('light');
state = await check('native exit unlocks retry in retained section with fitted content', value => !brightness(value).setup.running && control(value, 'retry setup')?.enabled && fits(value));
assert(fits(state));
await screenshot('config-light');
// Real long domain failure, not a synthetic renderer-only field contract.
call('brightness', 'setState', {
...setup,
setup: { ...setup.setup, expanded: true, error: Array(32).fill('monitor access interrupted; retry setup').join('\n') }
});
await focus('retry setup');
state = await check('keyboard reveals last action in a long section', value =>
service(value).sectionScroll > 0 && control(value, 'retry setup')?.focused &&
within(control(value, 'retry setup').rect, value.width, value.height));
const lightScroll = service(state).sectionScroll;
await screenshot('config-section-scroll');
// Navigation column remains fixed while only the section form scrolls.
// activate()'s all-content fit check intentionally applies only to short forms.
click(control(state, 'appearance').rect);
state = await check('appearance has independent scroll', value =>
service(value).selectedSection === 'appearance' && service(value).sectionScroll === 0 && control(value, 'dark mode'));
click(control(state, 'light').rect);
state = await check('section switch restores long-form scroll', value =>
service(value).selectedSection === 'light' && Math.abs(service(value).sectionScroll - lightScroll) <= 1 &&
control(value, 'retry setup'));
key('Escape');
await check('long section dismisses', value => !value.popup.open);
state = await open('config', value => control(value, 'retry setup')?.rect);
await check('reopen restores per-section action focus and scroll', value =>
control(value, 'retry setup')?.focused && Math.abs(service(value).sectionScroll - lightScroll) <= 1);
call('brightness', 'setState', setup);
// Restore the short cancelled form for orientation/fit assertions.
call('brightness', 'setupDdc');
call('brightness', 'cancelSetup');
await check('short form settles after long failure', value => control(value, 'retry setup')?.enabled && fits(value));
key('Escape');
await check('Config closes before orientation change', value => !value.popup.open);
fixture('vertical');
await check('vertical Bar geometry settles before pointer activation', value => value.orientation === 'vertical' && value.barWidth === value.barThickness && Object.values(value.chips).every(chip => within(chip.rect, value.width, value.height)));
state = await open('config', value => control(value, 'retry setup')?.rect);
assert(service(state).selectedSection === 'light' && fits(state));
await screenshot('config-light-vertical');
const outside = { x: state.width - 12, y: state.height - 12, width: 4, height: 4 };
click(outside);
await check('outside dismisses Config and returns focus', value =>
!value.popup.open && value.focusTargetActive && focusedWindow()?.id === focusId);
fixture('horizontal');
call('brightness', 'setState', null);
}