Add searchable lyrics index

This commit is contained in:
Jonathan Sykes
2026-10-14 02:10:02 +08:00
parent e3821621f3
commit 11b10e38e2
6 changed files with 209 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
const { test, expect } = require('@playwright/test');
test('lyrics full-text search highlights matches, filters, rebuilds and opens the editor', async ({ page }) => {
const requests = [];
await page.route('**/api/**', async route => {
const request = route.request(), url = new URL(request.url()); requests.push({ path: url.pathname, query: url.search, method: request.method() });
let body = { ok: true };
if (url.pathname === '/api/admin/me') body = { ok: true, enabled: true, admin: true };
if (url.pathname === '/api/admin/lyrics/search' && request.method() === 'GET') body = { ok: true, query: url.searchParams.get('q') || '', hasLyrics: 'yes', hasChapters: 'all', total: 1, limit: 30, offset: 0, results: [{ videoId: 'dQw4w9WgXcQ', title: 'Amazing grace', channel: 'Choir', snippet: '\u0001Amazing grace\u0002 will lead me home', hasChapters: true, rev: 2 }] };
if (url.pathname === '/api/admin/lyrics/search/rebuild') body = { ok: true, indexed: 42 };
if (url.pathname === '/api/notes/dQw4w9WgXcQ') body = { ok: true, lyrics: { rev: 2, data: { lines: [{ t: 1, text: 'Amazing grace', kind: 'line' }] } }, chapters: null };
if (url.pathname === '/api/streams') body = { ok: true, data: { meta: { title: 'Amazing grace', duration: 30 }, qualities: [] } };
if (url.pathname === '/api/admin/flags') body = { ok: true, open: 0, flags: [] };
if (url.pathname.startsWith('/api/admin/transcriptions/')) body = { ok: true, job: null };
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(body) });
});
await page.goto('/admin.html#lyric-search');
await expect(page.locator('#lyricsSearchTable')).toContainText('Amazing grace');
await expect(page.locator('#lyricsSearchTable mark')).toHaveText('Amazing grace');
await page.locator('#lyricsSearchQuery').fill('amazing grace'); await page.locator('#lyricsSearchHasChapters').selectOption('yes');
await page.locator('#lyricsSearchForm button[type=submit]').click();
await expect.poll(() => requests.some(item => item.path === '/api/admin/lyrics/search' && item.query.includes('hasChapters=yes'))).toBe(true);
await page.locator('#lyricsSearchRebuild').click();
await expect.poll(() => requests.some(item => item.path === '/api/admin/lyrics/search/rebuild' && item.method === 'POST')).toBe(true);
await expect(page.locator('#lyricsSearchTable')).toContainText('Amazing grace');
await page.locator('[data-lyrics-search-open="dQw4w9WgXcQ"]').click();
await expect(page.locator('#songTitle')).toHaveText('Amazing grace');
});