feat(nav): add BackButton component calling history.back()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-22 10:46:41 +02:00
parent fd93f1a4da
commit 781c4ffebb
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { describe, it, expect, afterEach, vi } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import BackButton from './BackButton.svelte';
afterEach(cleanup);
describe('BackButton', () => {
it('renders a button with "Zurück" text', async () => {
render(BackButton);
await expect.element(page.getByRole('button', { name: /zurück/i })).toBeInTheDocument();
});
it('calls history.back() when clicked', async () => {
const backSpy = vi.spyOn(history, 'back').mockImplementation(() => {});
render(BackButton);
await page.getByRole('button', { name: /zurück/i }).click();
expect(backSpy).toHaveBeenCalledOnce();
backSpy.mockRestore();
});
it('has min-h-[44px] for touch target compliance', async () => {
render(BackButton);
const btn = document.querySelector('button');
expect(btn?.className).toContain('min-h-[44px]');
});
});