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:
@@ -139,13 +139,32 @@ const topDerived = $derived(
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex h-full flex-col p-5">
|
<div class="flex h-full flex-col p-5">
|
||||||
<div class="mb-4">
|
<div class="mb-4 flex items-start justify-between gap-2">
|
||||||
<h2 class="font-serif text-lg text-ink">{node.displayName}</h2>
|
<div class="min-w-0">
|
||||||
{#if node.birthYear || node.deathYear}
|
<h2 class="font-serif text-lg text-ink">{node.displayName}</h2>
|
||||||
<p class="font-sans text-xs text-ink-3">
|
{#if node.birthYear || node.deathYear}
|
||||||
{node.birthYear ?? '?'}–{node.deathYear ?? ''}
|
<p class="font-sans text-xs text-ink-3">
|
||||||
</p>
|
{node.birthYear ?? '?'}–{node.deathYear ?? ''}
|
||||||
{/if}
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick={onClose}
|
||||||
|
aria-label={m.comp_dismiss()}
|
||||||
|
class="shrink-0 rounded-sm p-1 text-ink-3 transition hover:bg-muted hover:text-ink focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:outline-none"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
class="h-4 w-4"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<path stroke-linecap="round" d="M3 3l10 10M13 3L3 13" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user