Files
yellowjacket/frontend/test/components/empty-states.test.ts
T
yonlu 7a1412383f perf(library): send the track list as a dictionary-encoded column table
GetTracks answered with one JSON object per track: 20.5 MB at 26k
tracks, ~350 bytes a row of repeated key names, four cover URLs that
are identical across an album, and the album, artist and genre strings
repeated on every track. Encoding it was ~170 MB of transient Go
allocation, and parsing it the WebView's memory peak.

GetTrackTable replaces it: one array per column, every repeated
string stored once and sent as an index, genre lists interned, and only
the fields the Tracks view reads. LastPlayed and the three larger cover
tiers are left to the details dialog, which now fetches whole tracks by
path. Each row still goes through trackFromRow, so this is an encoding
of the one projection, not a second one. 167 bytes a track against 929
in the test library; a Go test holds it under a quarter of the object
encoding, and a Vitest test reads the Go columns and the generated
Track interface and fails if they drift.

An empty library is now an empty table rather than the "no tracks in
library" error the old binding returned.

Closes #281
2026-10-05 23:30:37 -04:00

70 lines
2.2 KiB
TypeScript

/**
* "Loading tracks…" used to be what the track list said when it was
* loading, when it was empty, and when the query had failed — including
* on the first screen a new user ever sees, behind the first-run wizard
* (errors.M2, H-12). Three situations, three different things to say.
*/
import { describe, expect, it, beforeEach } from 'vitest';
import type { LitElement } from 'lit';
import '@components/track-list/track-list';
import { Events } from '../../src/events';
import { emit, stub, stubFailure, flush, resetHarness } from '@test/support/harness';
import { fixture, shadow, text } from '@test/support/render';
import { trackTable } from '@test/support/track-table';
/** Drop the library store's cache so the list has to fetch. */
async function emptyLibrary(): Promise<void> {
resetHarness();
stub('library.Library.GetTrackTable', trackTable([]));
stub('library.Library.GetAlbums', []);
stub('library.Library.GetArtists', []);
stub('library.Library.GetGenres', []);
emit(Events.LibraryScanComplete);
await flush();
}
describe('<track-list> empty, loading and failed', () => {
beforeEach(async () => {
await emptyLibrary();
});
it('says the library is empty when it is empty', async () => {
const el = await fixture<LitElement>('track-list');
await flush();
await el.updateComplete;
expect(text(el, '[data-testid="track-list-empty"]')).toContain(
'No tracks yet',
);
});
it('says the query failed, and offers to try again', async () => {
stubFailure('library.Library.GetTrackTable', 'sql: database is locked');
emit(Events.LibraryScanComplete);
await flush();
const el = await fixture<LitElement>('track-list');
await flush();
await el.updateComplete;
expect([
text(el, '[data-testid="track-list-error"]'),
shadow(el, '[data-testid="track-list-loading"]'),
]).toEqual([expect.stringContaining('busy'), null]);
});
it('does not claim to be loading a list it was handed', async () => {
const el = await fixture<LitElement>('track-list', { externalTracks: [] });
await flush();
await el.updateComplete;
expect(text(el, '[data-testid="track-list-empty"]')).toBe(
'Nothing here yet.',
);
});
});