Files
yellowjacket/e2e/specs/queue-reorder.spec.ts
T
yonluandClaude Opus 5 deb3f3da7e feat(wails): move the e2e harness and headless launch onto v3
make e2e is green on chromium: 92 passed. The harness is rebuilt on
what v3 actually offers, and three of the four things it replaced turn
out to be better than what they replaced.

The headless launch is v3's own server mode. scripts/dev-headless.sh
ran a `-tags dev` binary whose app_dev.go parsed -devserver/-assetdir
out of os.Args; that file went with v2, so the harness had no server at
all. `-tags dev,server` is a first-class mode and needs no display, so
Xvfb is gone from the script and from CI.

The bridge hooks two places, neither of them EventsOn. Inbound is
window._wails.dispatchWailsEvent, wrapped by pre-creating the object
the runtime keeps and putting an accessor on the one property.
Outbound is fetch: v3 routes every runtime call through one POST, so
the bridge sees binding calls and event emits from any module, needs no
walk of an object graph, and cannot miss a call made before it looked.

__yjEvents.call posts to that endpoint by method name, so it depends on
nothing in the app's bundle and works on a page with no init script.
That is what lets seed-sandbox.sh drop playwright-cli entirely — it
drove AddLibrary through a browser only because window.go was v2's one
way in — and with it a global npm install and a second Chromium in CI.

measure.mjs and one spec lose their window.go walks and read the
bridge's log instead; e2e/support/method-ids.mjs derives id -> name
from frontend/bindings/ (phase 6b option 1, so it cannot go stale
silently). Plain .mjs because measure.mjs runs under bare node and one
derivation beats two that can disagree.

Four bugs surfaced, and the migration is how.

The cross-service wiring never ran headless. It hung off
Common.ApplicationStarted, which server mode never emits —
setupCommonEvents is an explicit no-op there — so the queue had no
TrackLoader and playing a track changed the queue and then silently did
nothing. It is a service registered last now (backend/startup.go):
services start in registration order, which is the ordering the wiring
needs, in every mode.

Six specs called SetQueue with 3 of its 4 arguments. v2 accepted that
and filled the gap; v3 answers "expects 4 arguments, got 3".

requested-badge's cleanup read window.go and returned early on
`if (!svc)` — the silent cleanup its own comment was written to
prevent, one migration later. It posts to the runtime endpoint now,
which any page can do.

SearchIndex.Search trusted a startup latch, so rows a spec staged
afterwards were unsearchable and three specs passed only when an
earlier one happened to flip it. shelves.go fixed exactly this and left
hasCatalogRows behind; the search path now uses it as the fallback,
with the latch still the fast path.

Two spec edits are deletions of assertions about v2. harness.spec
checked Object.keys(window.go) and that a bad call *hung*; it now
checks the real runtime is loaded and that the backend rejects with a
TypeError naming the argument. album-actions asserted a tracklist
legend that dcc40b1 deleted on main — that spec has been failing since,
and what replaced it is covered in frontend/test/components.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UDCbcCZQepnpSQYJ6SxxZm
2026-08-14 20:58:20 -04:00

126 lines
4.2 KiB
TypeScript

import {
test,
expect,
callBinding,
NO_QUEUE_SOURCE,
} from '../support/fixtures.js';
import type { Page } from '@playwright/test';
/**
* `a11y.11` — the queue's order can be changed without a mouse.
*
* The component tier pins the arithmetic against a faked binding. This
* one is here because the arithmetic is only half of it: `toIndex` is
* interpreted by `Queue.MoveQueueTracks`, whose contiguous-block guard
* turns the plausible-looking `i + 1` into a silent no-op. Nothing but
* the real backend can say whether the order actually moved.
*
* Reproduced first: with a row focused, Alt/Ctrl/Shift/Meta + arrows all
* left the order untouched.
*/
/** The queue's order, asked of the backend rather than of the DOM. */
async function order(app: Page): Promise<string[]> {
const state = await callBinding<{ tracks: { title: string }[] }>(
app,
'queue.Queue.GetState',
);
return state.tracks.map((t) => t.title);
}
async function queueFourAndOpen(app: Page): Promise<string[]> {
const paths: string[] = await app.evaluate(async () => {
const tracks = await window.__yjEvents.call(
'library.Library.GetAllTracks',
[],
10_000,
);
return (tracks as { FilePath: string }[]).slice(0, 4).map((t) => t.FilePath);
});
await callBinding(app, 'queue.Queue.SetQueue', [paths, 0, false, NO_QUEUE_SOURCE]);
// A closed panel renders no list at all, so there is no row to focus.
await app.locator('#queue-button').click();
await expect(app.locator('queue-panel .track-item').first()).toBeVisible();
return order(app);
}
test.describe('reordering the queue from the keyboard', () => {
// The 36 specs share one backend process in file order, and these
// leave two things behind that outlive the page: a reordered queue
// and an open panel. Both are put back, because a spec that spends
// state fails the *next* one, in a list that reads like a regression
// in whatever you are holding.
test.afterEach(async ({ app }) => {
await callBinding(app, 'queue.Queue.Clear').catch(() => {
/* nothing queued is the state we wanted anyway */
});
const open = await app.locator('queue-panel[open]').count();
if (open > 0) await app.locator('#queue-button').click();
});
test('Alt+Arrow moves the focused row, and puts it back', async ({ app }) => {
const start = await queueFourAndOpen(app);
expect(start.length).toBe(4);
await app.locator('queue-panel .track-item').nth(1).focus();
await app.keyboard.press('Alt+ArrowUp');
await expect.poll(() => order(app)).toEqual([start[1], start[0], ...start.slice(2)]);
// Down is the direction the obvious index arithmetic gets wrong: it
// has to ask for i + 2, because i + 1 is a no-op once the row's own
// removal is accounted for. A spec that only moved up would pass
// against a build where down does nothing.
await app.keyboard.press('Alt+ArrowDown');
await expect.poll(() => order(app)).toEqual(start);
});
test('says where the row went', async ({ app }) => {
await queueFourAndOpen(app);
await app.locator('queue-panel .track-item').nth(1).focus();
await app.keyboard.press('Alt+ArrowUp');
await expect(
app.locator('queue-panel [role="status"]'),
).toHaveText(/Moved to position 1 of 4/);
});
test('refuses at the ends without reordering anything', async ({ app }) => {
const start = await queueFourAndOpen(app);
await app.locator('queue-panel .track-item').first().focus();
await app.keyboard.press('Alt+ArrowUp');
await expect(
app.locator('queue-panel [role="status"]'),
).toHaveText(/Already first/);
expect(await order(app)).toEqual(start);
});
// The plain arrows belong to the roving tab stop, and must not reach
// the global volume binding from a focused row.
test('leaves the unmodified arrows roving', async ({ app }) => {
const start = await queueFourAndOpen(app);
await app.locator('queue-panel .track-item').first().focus();
await app.keyboard.press('ArrowDown');
const focused = await app.evaluate(
() =>
document
.querySelector('queue-panel')
?.shadowRoot?.activeElement?.getAttribute('data-index') ?? null,
);
expect([focused, await order(app)]).toEqual(['1', start]);
});
});