// `just ui-test media`: the registry media feature in the real Bar inside nested // niri, driven by real pointer and keyboard against the feature's Media double. // The suite contract (snapshot shape, helpers) is documented in .system/RULES.md. export default async function mediaSuite({ assert, snapshot, open, check, click, key, screenshot, within, call, fixture }) { const media = value => value.features.media; const service = value => media(value).service; const control = (value, name) => media(value).controls[name]; const play = value => control(value, service(value).playing ? 'pause' : 'play'); const seek = value => media(value).items['mpris-progress']; const emptyState = value => media(value).items.mediaEmptyState; const transport = ['shuffle', 'previous track', 'next track', 'repeat']; const rowRects = value => JSON.stringify([...transport.map(name => control(value, name)?.rect), play(value)?.rect]); const focusedNames = value => Object.entries(media(value).controls).filter(([, item]) => item.focused).map(([name]) => name); const onlyFocused = (value, name) => focusedNames(value).join() === name; const centered = (rect, card) => Math.abs(rect.x + rect.width / 2 - (card.x + card.width / 2)) <= 1; // A full player at the first track of its list: every control is there, // previous is only off for now and says why in its tooltip. let state = await open('media', value => play(value)?.rect); state = await check('opening focuses play or pause', value => play(value)?.focused); assert.equal(snapshot().popup.name, 'media'); assert.equal(control(state, 'previous track').enabled, false, 'the first track has no previous track'); assert.equal(control(state, 'previous track').tooltipText, 'no previous track', 'a briefly disabled control names its reason in its tooltip'); for (const name of ['next track', 'shuffle', 'repeat']) assert.equal(control(state, name).enabled, true, `${name} enabled`); assert.equal(play(state).enabled, true); const fullHeight = state.popup.card.height; const firstRow = rowRects(state); // The disabled click is dropped: only the later next track counts. click(control(state, 'previous track').rect); click(control(state, 'next track').rect); state = await check('next track dispatches once by pointer and enables previous in place', value => service(value).actions === 1 && service(value).lastAction === 'next' && control(value, 'previous track').enabled && rowRects(value) === firstRow && value.popup.card.height === fullHeight); click(play(state).rect); key('space'); state = await check('media play control supports pointer and keyboard activation', value => service(value).actions === 3 && service(value).lastAction === 'playPause'); assert.equal(service(state).osdEchoes, 0, 'panel transport must not raise the OSD over the open panel'); key('Tab'); await check('Tab moves from play to next track', value => control(value, 'next track').focused); key('Tab'); await check('Tab reaches repeat', value => control(value, 'repeat').focused); for (const name of ['next track', service(state).playing ? 'pause' : 'play', 'previous track']) { key('shift+Tab'); await check(`shift+Tab returns to ${name}`, value => control(value, name)?.focused); } state = snapshot(); const fullTexts = media(state).texts; key('Escape'); await check('Escape closes the full player', value => !value.popup.open); // A player without a track list, seeking, shuffle or repeat shows play alone, // centred, and says nothing about what it lacks. call('media', 'setCapabilities', 'limited'); state = await open('media', value => play(value)?.rect); state = await check('a limited player shows only play, centred and focused', value => onlyFocused(value, service(value).playing ? 'pause' : 'play') && play(value).enabled && transport.every(name => !control(value, name)) && !seek(value).enabled && centered(play(value).rect, value.popup.card) && media(value).texts.every(text => fullTexts.includes(text))); key('Tab'); await check('Tab keeps focus on play: hidden controls are not in the Tab order', value => onlyFocused(value, service(value).playing ? 'pause' : 'play')); key('shift+Tab'); state = await check('shift+Tab keeps focus on play', value => onlyFocused(value, service(value).playing ? 'pause' : 'play')); await screenshot('media-limited-player'); // A player that cannot be controlled has no transport row; the card ends // below the progress rail and still fits its content. call('media', 'setCapabilities', 'none'); state = await check('an uncontrollable player shows no transport row and no narration', value => !media(value).items.transportActions && !play(value) && transport.every(name => !control(value, name)) && media(value).texts.includes('fixture track') && media(value).texts.every(text => fullTexts.includes(text)) && value.popup.card.height < fullHeight && value.popup.card.height === value.popup.panelHeight + 32 && within(value.popup.card, value.width, value.height)); await screenshot('media-uncontrollable-player'); click(state.chips.media.rect); await check('the media chip closes the uncontrollable player', value => !value.popup.open); call('media', 'setCapabilities', 'full'); await open('media', value => play(value)?.rect); call('media', 'setEmpty', true); state = await check('last player disappearing shrinks media and removes dead controls', value => emptyState(value) && !play(value) && value.popup.card.width === 352 && value.popup.card.height === 88); assert(within(emptyState(state).rect, state.width, state.height), 'empty media state outside output'); await screenshot('media-empty'); key('Escape'); await check('Escape dismisses empty media', value => !value.popup.open); await open('media', value => emptyState(value)?.rect); call('media', 'setEmpty', false); await check('player arrival restores media controls and size without reopening', value => play(value) && !emptyState(value) && value.popup.card.height === fullHeight && value.popup.panelHeight + 32 === fullHeight && within(value.popup.card, value.width, value.height)); // The shared slider stays immediate for seeking with motion enabled. Media is // still open; clicking its chip again would be the bar-toggle close. fixture('motion-on'); state = await check('media seek slider is shown with motion enabled', value => value.popup.name === 'media' && seek(value)?.enabled && seek(value).rect); let seeks = service(state).seeks; click({ ...seek(state).rect, width: seek(state).rect.width * 1.2 }); state = await check('media shared slider retains immediate pointer seeking', value => service(value).seeks === seeks + 1 && service(value).position > 65 && Math.abs(seek(value).value - service(value).position / 120) < 0.001); seeks = service(state).seeks; key('Right'); state = await check('media shared slider retains immediate keyboard seeking', value => service(value).seeks === seeks + 1 && service(value).position > 70 && Math.abs(seek(value).value - service(value).position / 120) < 0.001); assert.equal(service(state).osdEchoes, 0, 'panel seeking must not raise the OSD over the open panel'); seeks = service(state).seeks; call('media', 'updatePosition', 15); await check('external media position redraws without another seek or tween', value => service(value).position === 15 && seek(value).value === 0.125 && service(value).seeks === seeks); await screenshot('media-slider-regression'); fixture('motion-off'); key('Escape'); await check('Escape closes media', value => !value.popup.open); // A player known only by its bus name reads as the app behind it. call('media', 'setAnonymous', true); state = await open('media', value => play(value)?.rect); state = await check('a player without identity or title shows its app name', value => media(value).texts.filter(text => text === 'firefox').length === 2 && seek(value) && !media(value).texts.some(text => /mpris|instance/.test(text))); assert(control(state, 'playback position for firefox'), 'the seek slider names the app'); await screenshot('media-player-name'); key('Escape'); await check('Escape closes the anonymous player', value => !value.popup.open); call('media', 'setAnonymous', false); // A media key (the IPC route) still echoes its change on the OSD. call('media', 'action', 'next'); await check('media key action still raises the OSD', value => service(value).osdEchoes === 1); }