fix(stammbaum): add × dismiss button with aria-label to StammbaumSidePanel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-28 17:33:31 +02:00
committed by marcel
parent fa1dfbc99d
commit 0e9fa157e5
2 changed files with 72 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
import { describe, it, expect, afterEach, vi, beforeEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import StammbaumSidePanel from './StammbaumSidePanel.svelte';
vi.mock('$app/navigation', () => ({ invalidateAll: vi.fn() }));
vi.mock('$lib/components/PersonTypeahead.svelte', () => ({ default: () => null }));
const makeNode = () => ({
id: 'person-1',
displayName: 'Alice Müller',
birthYear: 1900,
deathYear: null,
familyMember: true
});
function stubFetch(directRels: unknown[] = [], inferredRels: unknown[] = []) {
let callCount = 0;
vi.stubGlobal(
'fetch',
vi.fn().mockImplementation(() => {
callCount++;
const body = callCount % 2 === 1 ? directRels : inferredRels;
return Promise.resolve({ ok: true, json: () => Promise.resolve(body) });
})
);
}
beforeEach(() => stubFetch());
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});
describe('StammbaumSidePanel', () => {
it('calls onClose when dismiss button is clicked', async () => {
const onClose = vi.fn();
render(StammbaumSidePanel, { node: makeNode(), onClose, canWrite: false });
await expect.element(page.getByRole('button', { name: 'Schließen' })).toBeInTheDocument();
const btn = [...document.querySelectorAll<HTMLButtonElement>('button')].find(
(b) => b.getAttribute('aria-label') === 'Schließen'
);
btn!.click();
expect(onClose).toHaveBeenCalledOnce();
});
});