diff --git a/gerbil-manager-web/e2e/juvenile-details.spec.ts b/gerbil-manager-web/e2e/juvenile-details.spec.ts index 28ede90..92a3d7a 100644 --- a/gerbil-manager-web/e2e/juvenile-details.spec.ts +++ b/gerbil-manager-web/e2e/juvenile-details.spec.ts @@ -1,4 +1,4 @@ -/** LITTER-JUVENILE-DETAILS: Jungtier-Felder (Farbschlag/Abgabe/Verstorben) im Wurf-Detail. */ +/** LITTER-JUVENILE-DETAILS + JUVENILE-AVATARS: Jungtier-Felder und Foto-Avatare im Wurf-Detail. */ import { de, expect, skipUnlessMock, test } from './fixtures' const t = de.pages.litters @@ -28,3 +28,18 @@ test('Jungtier-Liste zeigt Farbschlag, Abgabedatum, Abnehmer, Todesdatum und Tod await expect(bennyCard).toContainText(t.detail.juvenileFields.dateOfDeath) await expect(bennyCard).toContainText(`${t.detail.juvenileFields.causeOfDeath}: Altersschwäche`) }) + +test('JUVENILE-AVATARS: Pippa zeigt Foto-Avatar, Benny zeigt GerbilIcon', async ({ page }) => { + skipUnlessMock() + await page.goto('/wuerfe/w-kruemel') + await expect(page.getByRole('heading', { name: 'Wurf K' })).toBeVisible() + + // Pippa hat profilePhotoUrl → sichtbar + const pippaCard = page.getByRole('link', { name: /Pippa/ }) + await expect(pippaCard.locator('.juvenile-photo__avatar')).toBeVisible() + + // Benny hat kein Foto → kein img, SVG-Icon (GerbilIcon) sichtbar + const bennyCard = page.getByRole('link', { name: /Benny/ }) + await expect(bennyCard.locator('.juvenile-photo__avatar')).not.toBeVisible() + await expect(bennyCard.locator('svg')).toBeVisible() +}) diff --git a/gerbil-manager-web/e2e/mock-data.ts b/gerbil-manager-web/e2e/mock-data.ts index 66a3c4c..5fa5877 100644 --- a/gerbil-manager-web/e2e/mock-data.ts +++ b/gerbil-manager-web/e2e/mock-data.ts @@ -153,11 +153,13 @@ export function seedDb(): MockDb { notes: 'neugieriger Entdecker', }, // LITTER-JUVENILE-DETAILS: Jungtiere für Wurf K mit Zusatzinfos. + // JUVENILE-AVATARS: Pippa hat profilePhotoUrl (1×1-PNG data-URI) → Avatar-Img sichtbar. { ...gerbil('pup-abgabe', 'Pippa', 'female', '2025-03-12', 'w-kruemel', 'cv-gold'), status: 'GivenAway' as const, goHomeDate: '2025-05-01', receiverContactId: 'con-huber', + profilePhotoUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==', }, { ...gerbil('pup-verstorben', 'Benny', 'male', '2025-03-12', 'w-kruemel', null), diff --git a/gerbil-manager-web/src/pages/StammbaumPage.tsx b/gerbil-manager-web/src/pages/StammbaumPage.tsx index 4612121..8a3b994 100644 --- a/gerbil-manager-web/src/pages/StammbaumPage.tsx +++ b/gerbil-manager-web/src/pages/StammbaumPage.tsx @@ -381,14 +381,13 @@ function PedigreeCard({ const g = node.gerbil const chip = farbschlag ? chipColorFor(farbschlag) : null const dob = g.dateOfBirth ? formatDate(g.dateOfBirth) : null - const [imgError, setImgError] = useState(false) - useEffect(() => setImgError(false), [g.id]) - const photoUrl = - !imgError && g.profilePhotoUrl - ? /^(https?:|data:|\/\/)/.test(g.profilePhotoUrl) - ? g.profilePhotoUrl - : `${API_BASE_URL}${g.profilePhotoUrl}` - : null + const [failedUrl, setFailedUrl] = useState(null) + const rawUrl = g.profilePhotoUrl + ? /^(https?:|data:|\/\/)/.test(g.profilePhotoUrl) + ? g.profilePhotoUrl + : `${API_BASE_URL}${g.profilePhotoUrl}` + : null + const photoUrl = rawUrl !== failedUrl ? rawUrl : null return (
setImgError(true)} + onError={() => setFailedUrl(rawUrl)} /> ) : (