Files
minstrel/web/src/lib/components/RequestRow.test.ts
T
bvandeusenandClaude Opus 5.5 10d50dccbd docs: web comments say what the app does, not how it came to be (#6277)
Rewrites the web app's comments to rule 32. Task, milestone, rule and
spec ids are gone; regression stories are restated as the trap they
guard (public auth routes, the menu's stopPropagation, universal loads
under adapter-static, metric deltas with their margin). Flutter and
Tauri mentions now name the Android app or a native shell, operator
quotes and dates are dropped, and one library's counts no longer
appear outside test fixtures. Verified with a TypeScript-scanner token
comparison (template literals and regex literals re-scanned): only
comment text changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:42:12 -04:00

61 lines
2.4 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import type { MusicRequest } from '#lib/api/types.js';
import RequestRow, { requestName } from './RequestRow.svelte';
function req(over: Partial<MusicRequest> = {}): MusicRequest {
return {
id: 'r1',
user_id: 'u1',
status: 'approved',
kind: 'album',
artist_mbid: 'art-mbid',
artist_name: 'Boards of Canada',
album_title: 'Geogaddi',
track_title: null,
requested_at: '2026-04-28T12:00:00Z',
updated_at: '2026-04-28T12:00:00Z',
imported_album_count: 0,
imported_track_count: 0,
...over
};
}
const text = (el: HTMLElement) => (el.textContent ?? '').replace(/\s+/g, ' ').trim();
// The row both Requests pages draw: the admin queue and the
// requester's own list read the same request the same way.
describe('RequestRow', () => {
test('says what was asked for, where it stands, and who or when', () => {
render(RequestRow, { request: req(), meta: 'by Boards of Canada · 4/28/2026', testid: 'request-row' });
const row = screen.getByTestId('request-row');
expect(row.dataset.status).toBe('approved');
expect(text(row)).toMatch(/^Album Approved · downloading Geogaddi by Boards of Canada · 4\/28\/2026$/);
});
test('says how much has arrived, in the words for each kind', () => {
const { unmount } = render(RequestRow, {
request: req({ kind: 'artist', imported_album_count: 3, imported_track_count: 41 }),
meta: '',
testid: 'r'
});
expect(text(screen.getByTestId('ingest-progress'))).toBe('3 albums · 41 tracks ingested');
unmount();
render(RequestRow, { request: req({ kind: 'track', track_title: 'Roygbiv', imported_track_count: 1 }), meta: '', testid: 'r' });
expect(text(screen.getByTestId('ingest-progress'))).toBe('Track ingested');
});
test('nothing arrived yet says nothing about it', () => {
render(RequestRow, { request: req(), meta: '', testid: 'r' });
expect(screen.queryByTestId('ingest-progress')).toBeNull();
});
test('a request with no title still has a name a screen reader can say', () => {
render(RequestRow, { request: req({ album_title: null }), meta: '', testid: 'r' });
expect(text(screen.getByTestId('r'))).toMatch(/—/);
expect(requestName(req({ album_title: null }))).toBe('this album by Boards of Canada');
expect(requestName(req({ kind: 'artist' }))).toBe('Boards of Canada');
});
});