test(stammbaum): cover animateView rAF tween + server 401/500 paths (#692)

Add a deterministic stubbed-rAF test for animateView's animated path (was only
covering the reduced-motion branch) and assert the server load redirects on 401
and throws on a network 500 (QA review).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-29 19:04:22 +02:00
parent 0306023610
commit 20db3d0d8f
2 changed files with 46 additions and 0 deletions

View File

@@ -16,6 +16,12 @@ function mockNetwork() {
} as unknown as ReturnType<typeof createApiClient>);
}
function mockNetworkResponse(status: number) {
vi.mocked(createApiClient).mockReturnValue({
GET: vi.fn().mockResolvedValue({ response: { ok: false, status }, error: { code: 'X' } })
} as unknown as ReturnType<typeof createApiClient>);
}
function loadEvent(query = '') {
const url = new URL(`http://localhost/stammbaum${query}`);
return {
@@ -53,4 +59,19 @@ describe('/stammbaum +page.server load — initialView', () => {
const result = await load(loadEvent('?z=99') as never);
expect(result.initialView.z).toBe(MAX_ZOOM);
});
it('redirects to /login when the network API returns 401', async () => {
mockNetworkResponse(401);
const { load } = await import('./+page.server');
await expect(load(loadEvent() as never)).rejects.toMatchObject({
status: 302,
location: '/login'
});
});
it('throws an HTTP error when the network API fails', async () => {
mockNetworkResponse(500);
const { load } = await import('./+page.server');
await expect(load(loadEvent() as never)).rejects.toMatchObject({ status: 500 });
});
});