Files
yellowjacket/frontend/test/components/keyboard-reach.test.ts
T
logan 43d78a731a feat(shell): draw only the destinations the user kept
The navigation reads the resolved map from the backend rather than
holding a copy of the defaults, which would be the copy that shipped in
the binary rather than the one being edited.

Hiding takes away the nav item and nothing else: `navigate` still
resolves a hidden view, which detail views and the launch page depend
on. No special case was needed for the highlight, because #72 moved
that onto `active-view-store` -- the sidebar asks `isActive(id)` per
*rendered* item, so a hidden view lights nothing exactly as a detail
view does.

Downloads is gated at the nav on `downloadStore.available` rather than
in the config, so switching it on in Settings still means what it says
once a client exists, and the tab appears without a restart. `available`
is false until the providers have loaded, which makes the item appear on
a fresh launch rather than appearing and then vanishing.

The tab bar honours the toggles too, and the reason is local rather than
a general rule about phones: "More" opens the *same* `<app-sidebar>`,
which filters, so an unfiltered bar would contradict its own drawer one
tap away. Which four tabs is still plan 016's subset; this only removes
from it, and "More" is never filtered.

`services/view-meta.ts` is the destination list, on `shortcut-meta.ts`'s
pattern, because Settings is now a second reader of the same labels in
the same order.

Two existing sidebar tests had to say which world they describe: eleven
destinations now assumes a configured download client.
2026-08-19 19:33:44 -04:00

127 lines
3.7 KiB
TypeScript

/**
* Keyboard reachability.
*
* Tabbing through the whole app used to yield fourteen stops, every one
* of them chrome: the sidebar was a list of `<li @click>`, a track list
* had no tab stop at all, and the *closed* queue panel still had two
* (`.planning/audits/2026-08-11-ui/hands-on.md`, H-5).
*/
import { describe, expect, it, beforeEach } from 'vitest';
import '@components/sidebar/app-sidebar';
import '@components/queue-panel/queue-panel';
import '@components/track-list/track-list';
import { stub, emit, flush } from '@test/support/harness';
import { Events } from '../../src/events';
import { fixture, shadow, shadowAll, update } from '@test/support/render';
/** Two fixture tracks, enough to move a focus ring between. */
const TRACKS = [
{
FilePath: '/music/a.mp3',
TrackName: 'Alpha',
ArtistName: 'One',
Album: 'First',
Duration: 100,
},
{
FilePath: '/music/b.mp3',
TrackName: 'Beta',
ArtistName: 'Two',
Album: 'First',
Duration: 120,
},
] as never[];
describe('<app-sidebar> is reachable', () => {
// Eleven destinations assumes a configured download client, since
// Downloads is not offered without one (#25).
beforeEach(async () => {
stub('download.Service.ListProviders', [
{ id: 1, kind: 'slskd', name: 'Sound', enabled: true, priority: 50 },
]);
emit(Events.DownloadProvidersChanged);
await flush();
});
it('renders every destination as a button, not a bare list item', async () => {
const el = await fixture('app-sidebar');
const items = shadowAll(el, 'li button');
expect(items).toHaveLength(11);
expect(items.every((item) => item.tagName === 'BUTTON')).toBe(true);
});
it('puts the nav in a landmark, so it can be jumped to', async () => {
const el = await fixture('app-sidebar');
expect(shadow(el, 'nav')?.getAttribute('aria-label')).toBe('Main');
});
});
describe('<queue-panel> when closed', () => {
it('is inert, so its buttons are not tab stops', async () => {
const el = await fixture('queue-panel');
expect(el.inert).toBe(true);
});
it('is not inert once opened', async () => {
const el = await fixture('queue-panel');
await update(el, { open: true });
expect(el.inert).toBe(false);
});
});
describe('<track-list> roving tabindex', () => {
beforeEach(() => {
stub('library.Library.GetTracks', TRACKS);
});
it('offers exactly one tab stop, however many rows there are', async () => {
const el = await fixture('track-list', { externalTracks: TRACKS });
const stops = shadowAll(el, '.track-row[tabindex="0"]');
expect(stops).toHaveLength(1);
});
it('gives the rows grid semantics rather than none', async () => {
const el = await fixture('track-list', { externalTracks: TRACKS });
const row = shadow(el, '.track-row');
expect({
row: row?.getAttribute('role'),
grid: shadow(el, '.table-container')?.getAttribute('role'),
cell: shadow(el, '.track-row .cell')?.getAttribute('role'),
}).toEqual({ row: 'row', grid: 'grid', cell: 'gridcell' });
});
it('moves the tab stop with the arrow keys', async () => {
const el = await fixture('track-list', { externalTracks: TRACKS });
shadow(el, '.table-container')?.dispatchEvent(
new KeyboardEvent('keydown', {
key: 'ArrowDown',
bubbles: true,
cancelable: true,
}),
);
await el.updateComplete;
expect(
shadow(el, '.track-row[tabindex="0"]')?.getAttribute('data-index'),
).toBe('1');
});
it('claims the tracklist shortcut scope while it is on screen', async () => {
const el = await fixture('track-list', { externalTracks: TRACKS });
expect(el.dataset['shortcutScope']).toBe('tracklist');
});
});