repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/features/clipboard/fixtures/suite.mjs
Raw// `just ui-test clipboard`: the registry clipboard feature in the real Bar inside
// nested niri, driven by real pointer and keyboard against the feature's
// Clipboard double. Query, selection and scroll live in the host's session
// object, so a draft survives close and reopen.
// The suite contract (snapshot shape, helpers) is documented in .system/RULES.md.
export default async function clipboardSuite({ assert, open, check, click, input, key, screenshot, within, call, fixture }) {
const clipboard = value => value.features.clipboard;
const service = value => clipboard(value).service;
const retained = value => clipboard(value).retained;
const item = (value, name) => clipboard(value).items[name];
const control = (value, name) => clipboard(value).controls[name];
const search = value => item(value, 'searchField');
const filtered = value => retained(value).query === 'needle' && control(value, 'needle document') && !control(value, 'other document');
function focusSearch(state) {
click(search(state).rect);
key('End');
}
let state = await open('clipboard', value => search(value)?.rect);
assert(search(state).focused, 'clipboard search must receive initial focus');
assert(control(state, 'needle document') && control(state, 'other document'), 'both history rows render');
assert(within(item(state, 'clipboardActionRail').rect, state.width, state.height), 'action rail inside output');
await screenshot('clipboard-history');
// Copied temp paths, file uris and ids read as what they are, even when the file is gone.
call('clipboard', 'setMachineRows', true);
state = await check('copied paths and ids render as human titles', value =>
['image', 'image what is in this picture?', 'report.pdf', 'copied text'].every(name => control(value, name)) &&
['image', 'image what is in this picture?', 'report.pdf', 'copied text'].every(name => clipboard(value).texts.includes(name)) &&
!clipboard(value).texts.some(text => /\/tmp\/|file:|23965d8a/.test(text)));
await screenshot('clipboard-human-titles');
call('clipboard', 'setMachineRows', false);
state = await check('the adversarial rows leave the history', value => !control(value, 'report.pdf') && control(value, 'needle document') && control(value, 'other document'));
input('type', 'needle');
state = await check('clipboard query filters without exposing editable text', value => filtered(value) && retained(value).selectedId === 'clip-needle');
click(item(state, 'clipboardCopy').rect);
state = await check('clipboard copy preserves the active filter', value => service(value).copies === 1 && filtered(value));
click(item(state, 'clipboardPin').rect);
state = await check('clipboard pin preserves query and selected identity', value => service(value).pins === 1 && service(value).pinned === 1 && retained(value).selectedId === 'clip-needle' && control(value, 'unpin selected item') && filtered(value));
call('clipboard', 'externalUpdate');
state = await check('external clipboard update remains filtered after copy and pin', value => service(value).externalUpdates === 1 && control(value, 'needle external update') && filtered(value) && retained(value).selectedId === 'clip-needle');
await screenshot('clipboard-filtered');
focusSearch(state);
key('Down');
state = await check('Down selects the next match from the search field', value => retained(value).selectedId === 'clip-external-1');
key('Return');
state = await check('Enter pastes the selected item exactly once', value => service(value).pastes === 1);
click(item(state, 'clipboardPaste').rect);
state = await check('pointer paste reaches the service once', value => service(value).pastes === 2);
click(item(state, 'clipboardDelete').rect);
state = await check('delete removes the selected item and reselects the first match', value => service(value).deletes === 1 && !control(value, 'needle external update') && retained(value).selectedId === 'clip-needle' && filtered(value));
assert.equal(service(state).pastes, 2, 'keyboard and pointer each pasted exactly once');
assert.equal(state.chips.clipboard.active, false, 'capturing clipboard keeps a quiet chip');
assert(!item(state, 'clipboardCaptureState') && !clipboard(state).texts.includes('capture paused'), 'capturing hides the paused line');
click(control(state, 'private clipboard mode').rect);
state = await check('private mode pauses capture, says so under search and marks the chip', value =>
service(value).privateMode === true && value.chips.clipboard.active === true && clipboard(value).texts.includes('capture paused') && within(item(value, 'clipboardCaptureState').rect, value.width, value.height));
await screenshot('clipboard-private');
key('Escape');
// A pause is not routine activity: the warning mark, not the dot, and a name that says it.
await check('closed clipboard keeps its paused chip marked', value => !value.popup.open && value.chips.clipboard.active === true &&
value.chips.clipboard.role === 'warning' && value.chips.clipboard.mark === 'warning' && value.chips.clipboard.accessibleName === 'clipboard paused');
await screenshot('clipboard-private-chip');
fixture('vertical');
await check('the vertical chip keeps the paused mark', value => value.orientation === 'vertical' && value.chips.clipboard.active === true && value.chips.clipboard.icon === '\u{F161B}' && value.chips.clipboard.mark === 'warning' && within(value.chips.clipboard.rect, value.width, value.height));
await screenshot('clipboard-private-vertical');
fixture('horizontal');
await check('the bar returns to horizontal', value => value.orientation === 'horizontal');
state = await open('clipboard', value => control(value, 'private clipboard mode')?.rect);
click(control(state, 'private clipboard mode').rect);
state = await check('private mode toggles back and quiets the chip', value => service(value).privateMode === false && value.chips.clipboard.active === false && value.chips.clipboard.mark === '' && value.chips.clipboard.accessibleName === 'clipboard' && !clipboard(value).texts.includes('capture paused'));
const restingRail = ['clipboardPaste', 'clipboardCopy', 'clipboardPin', 'clipboardDelete'].map(name => JSON.stringify(item(state, name).rect));
const railHolds = value => ['clipboardPaste', 'clipboardCopy', 'clipboardPin', 'clipboardDelete'].every((name, index) => JSON.stringify(item(value, name).rect) === restingRail[index]);
call('clipboard', 'pasteOutcome', true);
state = await check('a pending paste disables paste, names its destination once and keeps the rail still', value =>
item(value, 'clipboardPaste').enabled === false && item(value, 'clipboardPaste').text === 'paste' && clipboard(value).texts.includes('pasting into editor') && railHolds(value));
await screenshot('clipboard-paste-pending');
call('clipboard', 'pasteOutcome', false);
state = await check('a settled paste enables paste again', value => item(value, 'clipboardPaste').enabled === true && item(value, 'clipboardPaste').text === 'paste' && !clipboard(value).texts.some(text => text.startsWith('pasting')) && railHolds(value));
focusSearch(state);
input('type', 'x');
const texts = value => clipboard(value).texts;
state = await check('a query without matches names it, offers clear search and disables actions', value =>
retained(value).query === 'needlex' && !control(value, 'needle document') && item(value, 'clipboardActionRail').enabled === false && texts(value).includes('no items match "needlex"') && control(value, 'clear search')?.enabled === true);
assert(within(control(state, 'clear search').rect, state.width, state.height), 'clear search inside output');
await screenshot('clipboard-no-matches');
key('BackSpace');
state = await check('clearing the extra character restores the match', value => filtered(value) && item(value, 'clipboardActionRail').enabled === true);
key('Escape');
await check('Escape closes clipboard', value => !value.popup.open && value.popup.lastCloseReason === 'escape-key');
state = await open('clipboard', value => search(value)?.rect);
assert(filtered(state), 'clipboard draft must survive close and reopen');
assert.equal(retained(state).selectedId, 'clip-needle', 'selection survives close and reopen');
focusSearch(state);
input('type', 'x');
state = await check('the miss returns with clear search', value => retained(value).query === 'needlex' && control(value, 'clear search')?.enabled === true);
click(control(state, 'clear search').rect);
state = await check('pointer clear search empties the query, restores every row and refocuses search', value =>
retained(value).query === '' && control(value, 'needle document') && control(value, 'other document') && !item(value, 'clipboardEmptyState') && search(value).focused);
click(item(state, 'clipboardDelete').rect);
state = await check('delete removes the first row', value => service(value).rows === 1);
click(item(state, 'clipboardDelete').rect);
state = await check('an empty history says how it fills, without clear search', value =>
service(value).rows === 0 && item(value, 'clipboardEmptyState')?.rect && texts(value).includes('nothing copied yet') && texts(value).includes('copied text appears here') && !control(value, 'clear search') && item(value, 'clipboardActionRail').enabled === false);
assert(within(item(state, 'clipboardEmptyState').rect, state.width, state.height), 'empty state inside output');
await screenshot('clipboard-empty');
}