repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/features/tray/fixtures/suite.mjs
Raw// `just ui-test tray`: the registry tray feature in the real Bar inside nested
// niri, driven by real pointer and keyboard against the feature's Tray double.
// Shared `bar` suite also checks the vertical-layout empty state.
// The suite contract (snapshot shape, helpers) is documented in .system/RULES.md.
const primary = 'activate fixture tray';
const secondary = 'middle click fixture tray';
const menu = 'menu for fixture tray';
export default async function traySuite({ assert, snapshot, open, check, click, key, screenshot, within, call }) {
const tray = value => value.features.tray;
const control = (value, name) => tray(value).controls[name];
const service = value => tray(value).service;
const emptyState = value => tray(value).items.trayEmptyState;
// A point on the output but off the popup card, for outside dismissal.
function outsideRect(state) {
const card = state.popup.card;
const candidates = [
{ x: state.width - 14, y: state.height - 14, width: 6, height: 6 },
{ x: 8, y: state.height - 14, width: 6, height: 6 },
{ x: state.width - 14, y: 40, width: 6, height: 6 },
];
const result = candidates.find(rect => rect.x + rect.width < card.x || rect.x > card.x + card.width || rect.y + rect.height < card.y || rect.y > card.y + card.height);
assert(result && within(result, state.width, state.height), 'mapped output must contain an outside-click target');
return result;
}
let state = snapshot();
assert.equal(state.chips.tray.label, 'tray', 'attention never changes the chip label width');
assert.equal(state.chips.tray.active, true, 'registry bar activity follows attention');
assert.equal(state.chips.tray.role, 'warning', 'bar attention matches the panel warning card');
// Pointer then keyboard activation of every action.
state = await open('tray', value => control(value, primary)?.rect);
state = await check('opening focuses the attention item primary action', value => control(value, primary)?.focused);
// One item: the card fits its row instead of the 440 px registry maximum.
assert.equal(state.popup.card.height, 92, 'populated tray fits its one item');
assert.equal(state.popup.panelHeight + 32, state.popup.card.height, 'the card fits the panel content');
assert(within(state.popup.card, state.width, state.height), 'populated tray card on the output');
const fallback = tray(state).items.trayIconFallback;
assert(fallback?.rect && within(fallback.rect, state.width, state.height), 'an item without an icon shows the generic app glyph');
assert(control(state, primary).attention, 'attention item card is warning-tinted');
click(control(state, primary).rect);
await check('tray primary action is keyboard focusable after pointer activation', value => service(value).primaryCount === 1 && control(value, primary)?.focused);
key('Return');
await check('tray card activates with Enter', value => service(value).primaryCount === 2);
key('Tab');
await check('Tab reaches tray secondary action', value => control(value, secondary)?.focused);
key('space');
await check('tray secondary action activates with Space', value => service(value).secondaryCount === 1);
key('Tab');
await check('Tab reaches tray menu action', value => control(value, menu)?.focused);
key('Return');
await check('tray menu action activates with Enter', value => service(value).menuCount === 1);
await screenshot('tray-keyboard');
// An item with only a generated id reads as an app, never as its id.
call('tray', 'setIdOnly', true);
await check('an id-only tray item renders as an app', value =>
control(value, 'activate app') && control(value, 'middle click app') && tray(value).texts.includes('app') && !tray(value).texts.some(text => text.includes('status_icon')));
await screenshot('tray-id-only');
call('tray', 'setIdOnly', false);
state = await check('the titled item returns', value => control(value, primary) && !control(value, 'activate app'));
// An item without a menu has no menu button: the rail keeps its right edge
// and Tab goes from the secondary action back to the item.
const menuRight = control(state, menu).rect.x + control(state, menu).rect.width;
call('tray', 'setNoMenu', true);
state = await check('an item without a menu shows no menu button', value =>
!control(value, menu) && control(value, secondary)?.rect.x + control(value, secondary).rect.width === menuRight);
const primaries = service(state).primaryCount;
click(control(state, primary).rect);
await check('the item takes focus by pointer', value => service(value).primaryCount === primaries + 1 && control(value, primary)?.focused);
key('Tab');
await check('Tab reaches the secondary action', value => control(value, secondary)?.focused);
key('Tab');
await check('Tab skips the absent menu and returns to the item', value => control(value, primary)?.focused);
await screenshot('tray-no-menu');
call('tray', 'setNoMenu', false);
await check('the menu button returns with the menu', value => control(value, menu));
// The last item disappearing shrinks the open popup to the empty state.
call('tray', 'setEmpty', true);
state = await check('last tray item disappearing shrinks tray and removes actions', value =>
emptyState(value)?.rect && !control(value, primary) && !control(value, menu) && value.popup.card.width === 352 && value.popup.card.height === 88);
assert(within(emptyState(state).rect, state.width, state.height), 'empty tray state outside output');
assert(within(state.popup.card, state.width, state.height), 'empty tray popup card outside output');
await check('empty tray clears the bar attention', value => value.chips.tray.label === 'tray' && value.chips.tray.active === false && value.chips.tray.role === 'ui.accent');
await screenshot('tray-empty');
click(outsideRect(state));
await check('outside click dismisses empty tray', value => !value.popup.open && value.popup.lastCloseReason === 'outside');
// An item arriving while open restores actions and size without reopening.
await open('tray', value => emptyState(value)?.rect);
call('tray', 'setEmpty', false);
await check('tray item arrival restores actions and size without reopening', value =>
control(value, primary) && !emptyState(value) && value.popup.card.height === 92 && value.popup.panelHeight + 32 === 92 &&
within(value.popup.card, value.width, value.height) && value.chips.tray.label === 'tray' && value.chips.tray.active === true);
await screenshot('tray-populated');
}