Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/idle/fixtures/suite.mjs

Raw
// `just ui-test idle`: the registry keep-awake toggle in the real Bar inside nested
// niri, driven by real pointer input against the feature's Idle double.
// A toggle entry has no surface: its chip records usage and toggles the service,
// never opening, closing or replacing a popup.
// The suite contract (snapshot shape, helpers) is documented in .system/RULES.md.
export default async function idleSuite({ assert, snapshot, open, check, click, key, screenshot, fixture }) {
    const chip = value => value.chips.idle;
    const service = value => value.features.idle.service;
    const recorded = value => value.usage.filter(name => name === 'idle').length;
    const quiet = value => !chip(value).active && !chip(value).strong && !service(value).inhibited;
    const awake = value => chip(value).active && chip(value).strong && service(value).inhibited;

    let state = snapshot();
    assert.equal(state.features.idle.kind, 'toggle');
    assert.equal(state.features.idle.open, false, 'a toggle entry has no surface');
    assert.equal(chip(state).label, 'idle');
    assert.equal(chip(state).icon, '', 'the horizontal Bar keeps the word');
    assert.equal(chip(state).accessibleName, 'keep awake');
    assert.equal(chip(state).role, 'ui.accent');
    assert(quiet(state), 'keep-awake starts off with a quiet chip');

    // Pointer activation keeps the system awake and pops the chip, without a popup.
    click(chip(state).rect);
    state = await check('idle chip keeps the system awake', value => awake(value) && service(value).toggles === 1 && recorded(value) === 1);
    assert.equal(state.popup.open, false, 'the toggle opens no popup');
    assert.equal(state.popup.name, '');
    await screenshot('idle-awake');

    // With a popup open, the toggle leaves that popup alone.
    state = await open('power', value => value.features.power.controls.reboot?.rect);
    click(chip(state).rect);
    state = await check('idle chip restores normal idle while a popup stays open', value => quiet(value) && service(value).toggles === 2 && recorded(value) === 2 && value.popup.windowActive);
    assert.equal(state.popup.open, true, 'the toggle never closes the open popup');
    assert.equal(state.popup.name, 'power', 'the toggle never replaces the open popup');
    await screenshot('idle-normal-with-popup');
    key('Escape');
    await check('Escape still closes the popup after the toggle', value => !value.popup.open && value.popup.lastCloseReason === 'escape-key');

    // The vertical Bar shows the glyph instead of the word and keeps the strong emphasis.
    fixture('vertical');
    state = await check('vertical idle chip shows its glyph', value => value.orientation === 'vertical' && chip(value).icon === '\u{F0176}' && chip(value).label === 'idle' && quiet(value));
    click(chip(state).rect);
    state = await check('vertical idle chip keeps the system awake', value => awake(value) && service(value).toggles === 3 && recorded(value) === 3);
    assert.equal(state.popup.open, false, 'the vertical toggle opens no popup');
    await screenshot('idle-awake-vertical');
    click(chip(state).rect);
    await check('vertical idle chip restores normal idle', value => quiet(value) && service(value).toggles === 4 && recorded(value) === 4);
    fixture('horizontal');
    await check('horizontal Bar returns', value => value.orientation === 'horizontal' && chip(value).label === 'idle' && chip(value).icon === '');
}