test: address latest review feedback

This commit is contained in:
2026-03-22 20:28:45 -07:00
parent 415c758840
commit ba9bae63e4
3 changed files with 43 additions and 6 deletions

View File

@@ -2317,15 +2317,18 @@ test('handleMediaChange stores youtube metadata for new youtube sessions', async
let tracker: ImmersionTrackerService | null = null; let tracker: ImmersionTrackerService | null = null;
const originalFetch = globalThis.fetch; const originalFetch = globalThis.fetch;
const originalPath = process.env.PATH; const originalPath = process.env.PATH;
let fakeBinDir: string | null = null;
try { try {
const fakeBinDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-yt-dlp-bin-')); fakeBinDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-yt-dlp-bin-'));
const ytDlpOutput = const ytDlpOutput =
'{"id":"abc123","title":"Video Name","webpage_url":"https://www.youtube.com/watch?v=abc123","thumbnail":"https://i.ytimg.com/vi/abc123/hqdefault.jpg","channel_id":"UCcreator123","channel":"Creator Name","channel_url":"https://www.youtube.com/channel/UCcreator123","uploader_id":"@creator","uploader_url":"https://www.youtube.com/@creator","description":"Video description","channel_follower_count":12345,"thumbnails":[{"url":"https://i.ytimg.com/vi/abc123/hqdefault.jpg"},{"url":"https://yt3.googleusercontent.com/channel-avatar=s88"}]}'; '{"id":"abc123","title":"Video Name","webpage_url":"https://www.youtube.com/watch?v=abc123","thumbnail":"https://i.ytimg.com/vi/abc123/hqdefault.jpg","channel_id":"UCcreator123","channel":"Creator Name","channel_url":"https://www.youtube.com/channel/UCcreator123","uploader_id":"@creator","uploader_url":"https://www.youtube.com/@creator","description":"Video description","channel_follower_count":12345,"thumbnails":[{"url":"https://i.ytimg.com/vi/abc123/hqdefault.jpg"},{"url":"https://yt3.googleusercontent.com/channel-avatar=s88"}]}';
if (process.platform === 'win32') { if (process.platform === 'win32') {
const outputPath = path.join(fakeBinDir, 'output.json');
fs.writeFileSync(outputPath, ytDlpOutput, 'utf8');
fs.writeFileSync( fs.writeFileSync(
path.join(fakeBinDir, 'yt-dlp.cmd'), path.join(fakeBinDir, 'yt-dlp.cmd'),
`@echo off\r\necho ${ytDlpOutput.replace(/"/g, '\\"')}\r\n`, '@echo off\r\ntype "%~dp0output.json"\r\n',
'utf8', 'utf8',
); );
} else { } else {
@@ -2429,6 +2432,9 @@ printf '%s\n' '${ytDlpOutput}'
globalThis.fetch = originalFetch; globalThis.fetch = originalFetch;
tracker?.destroy(); tracker?.destroy();
cleanupDbPath(dbPath); cleanupDbPath(dbPath);
if (fakeBinDir) {
fs.rmSync(fakeBinDir, { recursive: true, force: true });
}
} }
}); });

View File

@@ -90,6 +90,16 @@ test('resolveMediaArtworkUrl prefers youtube thumbnails for video and channel im
assert.equal(resolveMediaArtworkUrl(localVideo, 'channel'), null); assert.equal(resolveMediaArtworkUrl(localVideo, 'channel'), null);
}); });
test('resolveMediaArtworkUrl normalizes blank thumbnail urls to null', () => {
const item = {
videoThumbnailUrl: ' ',
channelThumbnailUrl: '',
};
assert.equal(resolveMediaArtworkUrl(item, 'video'), null);
assert.equal(resolveMediaArtworkUrl(item, 'channel'), null);
});
test('summarizeMediaLibraryGroups stays aligned with rendered group buckets', () => { test('summarizeMediaLibraryGroups stays aligned with rendered group buckets', () => {
const groups = groupMediaLibraryItems([youtubeEpisodeA, localVideo, youtubeEpisodeB]); const groups = groupMediaLibraryItems([youtubeEpisodeA, localVideo, youtubeEpisodeB]);
const summary = summarizeMediaLibraryGroups(groups); const summary = summarizeMediaLibraryGroups(groups);
@@ -100,6 +110,24 @@ test('summarizeMediaLibraryGroups stays aligned with rendered group buckets', ()
}); });
}); });
test('groupMediaLibraryItems backfills missing group artwork from later items', () => {
const first = {
...youtubeEpisodeA,
videoId: 10,
videoThumbnailUrl: null,
channelThumbnailUrl: null,
};
const second = {
...youtubeEpisodeB,
videoId: 11,
channelThumbnailUrl: null,
};
const groups = groupMediaLibraryItems([first, second]);
assert.equal(groups[0]?.imageUrl, second.videoThumbnailUrl);
});
test('CoverImage renders explicit remote artwork when src is provided', () => { test('CoverImage renders explicit remote artwork when src is provided', () => {
const markup = renderToStaticMarkup( const markup = renderToStaticMarkup(
<CoverImage <CoverImage

View File

@@ -17,10 +17,9 @@ export function resolveMediaArtworkUrl(
item: Pick<MediaLibraryItem, 'videoThumbnailUrl' | 'channelThumbnailUrl'>, item: Pick<MediaLibraryItem, 'videoThumbnailUrl' | 'channelThumbnailUrl'>,
kind: 'video' | 'channel', kind: 'video' | 'channel',
): string | null { ): string | null {
if (kind === 'channel') { const raw = kind === 'channel' ? item.channelThumbnailUrl : item.videoThumbnailUrl;
return item.channelThumbnailUrl ?? null; const normalized = raw?.trim() ?? '';
} return normalized.length > 0 ? normalized : null;
return item.videoThumbnailUrl ?? null;
} }
export function resolveMediaCoverApiUrl(videoId: number): string { export function resolveMediaCoverApiUrl(videoId: number): string {
@@ -61,6 +60,10 @@ export function groupMediaLibraryItems(items: MediaLibraryItem[]): MediaLibraryG
existing.totalActiveMs += item.totalActiveMs; existing.totalActiveMs += item.totalActiveMs;
existing.totalCards += item.totalCards; existing.totalCards += item.totalCards;
existing.lastWatchedMs = Math.max(existing.lastWatchedMs, item.lastWatchedMs); existing.lastWatchedMs = Math.max(existing.lastWatchedMs, item.lastWatchedMs);
if (!existing.imageUrl) {
existing.imageUrl =
resolveMediaArtworkUrl(item, 'channel') ?? resolveMediaArtworkUrl(item, 'video');
}
continue; continue;
} }