test: cover users/[id], admin/ocr/global, geschichten/[id] page branches

users/[id]: full-name derivation across all four branches
(both/firstName-only/lastName-only/email fallback), avatar initials
matrix, email/contact row visibility tied to data presence.

admin/ocr/global: heading + back link, runs prop pass-through,
defensive default for missing history fields.

geschichten/[id]: title rendering, author full-name vs email fallback
vs null, publishedAt suffix conditional, persons and documents sections
gated on array length, edit/delete actions gated on canBlogWrite. Mocks
the confirm service since it requires a ConfirmDialog mounted in layout.

26 tests across three files.

Refs #496.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-09 20:58:25 +02:00
committed by marcel
parent 00a8878146
commit e5256c89a1
3 changed files with 289 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import UserProfilePage from './+page.svelte';
afterEach(cleanup);
const baseData = (overrides: Record<string, unknown> = {}) => ({
profileUser: {
firstName: 'Anna',
lastName: 'Schmidt',
email: 'anna@example.com',
contact: 'Telefon: 030-12345',
...overrides
}
});
describe('users/[id] page', () => {
it('renders the heading and back link', async () => {
render(UserProfilePage, { props: { data: baseData() } });
await expect.element(page.getByRole('heading', { level: 1 })).toBeVisible();
await expect.element(page.getByRole('link', { name: /zurück/i })).toHaveAttribute('href', '/');
});
it('renders the full name when both firstName and lastName are present', async () => {
render(UserProfilePage, { props: { data: baseData() } });
await expect.element(page.getByRole('heading', { level: 2 })).toHaveTextContent('Anna Schmidt');
});
it('renders firstName-only when lastName is missing', async () => {
render(UserProfilePage, {
props: { data: baseData({ firstName: 'Anna', lastName: '' }) }
});
await expect.element(page.getByRole('heading', { level: 2 })).toHaveTextContent('Anna');
});
it('renders lastName-only when firstName is missing', async () => {
render(UserProfilePage, {
props: { data: baseData({ firstName: '', lastName: 'Schmidt' }) }
});
await expect.element(page.getByRole('heading', { level: 2 })).toHaveTextContent('Schmidt');
});
it('falls back to email when both firstName and lastName are missing', async () => {
render(UserProfilePage, {
props: { data: baseData({ firstName: '', lastName: '', email: 'fallback@example.com' }) }
});
await expect
.element(page.getByRole('heading', { level: 2 }))
.toHaveTextContent('fallback@example.com');
});
it('renders avatar initials when both names are present', async () => {
render(UserProfilePage, { props: { data: baseData() } });
await expect.element(page.getByText('AS')).toBeVisible();
});
it('renders avatar firstName initial when only firstName is present', async () => {
render(UserProfilePage, {
props: { data: baseData({ firstName: 'Anna', lastName: '' }) }
});
const avatarInitial = document.querySelector('.h-16.w-16 span.font-serif');
expect(avatarInitial?.textContent).toBe('A');
});
it('renders avatar lastName initial when only lastName is present', async () => {
render(UserProfilePage, {
props: { data: baseData({ firstName: '', lastName: 'Schmidt' }) }
});
const avatarInitial = document.querySelector('.h-16.w-16 span.font-serif');
expect(avatarInitial?.textContent).toBe('S');
});
it('omits the email row when email is empty', async () => {
render(UserProfilePage, {
props: { data: baseData({ email: '' }) }
});
await expect.element(page.getByText('E-Mail')).not.toBeInTheDocument();
});
it('omits the contact row when contact is empty', async () => {
render(UserProfilePage, {
props: { data: baseData({ contact: '' }) }
});
await expect.element(page.getByText('Kontakt')).not.toBeInTheDocument();
});
it('renders both email and contact rows when populated', async () => {
render(UserProfilePage, { props: { data: baseData() } });
await expect.element(page.getByText('E-Mail')).toBeVisible();
await expect.element(page.getByText('Kontakt')).toBeVisible();
await expect.element(page.getByText('anna@example.com')).toBeVisible();
await expect.element(page.getByText('Telefon: 030-12345')).toBeVisible();
});
});