refactor(web): every cover thumbnail goes through Cover, so a failed load falls back (DRY W2)
Seven places drew their own cover image. The Missing, Suspect sources, Hidden and Reports rows showed a Music2 icon only when the track had no album; a cover that failed to load (not fetched yet, or gone) showed a broken image. The queue row, play bar and Now Playing each set the placeholder in their own onerror, and the playlist card's images had no fallback at all. Cover gains fallback="track" (the Music2 icon a track row uses), and all seven go through it, so each one handles a missing src and a failed load the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { render, fireEvent } from '@testing-library/svelte';
|
||||
import Cover from './Cover.svelte';
|
||||
|
||||
describe('Cover', () => {
|
||||
test('a track row with no cover shows the track icon, not an image', () => {
|
||||
const { container } = render(Cover, { props: { src: undefined, fallback: 'track' } });
|
||||
expect(container.querySelector('img')).toBeNull();
|
||||
expect(container.querySelector('svg')).not.toBeNull();
|
||||
});
|
||||
|
||||
test('a track cover that fails to load gives way to the track icon', async () => {
|
||||
const { container } = render(Cover, { props: { src: '/api/albums/a1/cover', fallback: 'track' } });
|
||||
const img = container.querySelector('img');
|
||||
expect(img).not.toBeNull();
|
||||
await fireEvent.error(img!);
|
||||
expect(container.querySelector('img')).toBeNull();
|
||||
expect(container.querySelector('svg')).not.toBeNull();
|
||||
});
|
||||
|
||||
test('an image cover that fails to load shows the placeholder cover', async () => {
|
||||
const { container } = render(Cover, { props: { src: '/api/albums/a1/cover' } });
|
||||
await fireEvent.error(container.querySelector('img')!);
|
||||
expect(container.querySelector('img')!.getAttribute('src')).not.toBe('/api/albums/a1/cover');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user