test(frontend): add specs for Tabs, AlertBanner, BackLink, useHashTab

4 new spec files adding 21 tests (7+6+4+4). Each component spec
includes brutalism invariant assertions (no rounded-md, no transition-*,
no shadow-*).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Knacky
2026-06-21 22:11:31 +02:00
parent 1819089925
commit 5d34a5e171
4 changed files with 190 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { renderHook, act } from '@testing-library/react';
import { useHashTab } from '@/hooks/useHashTab';
beforeEach(() => {
window.location.hash = '';
});
afterEach(() => {
window.location.hash = '';
});
describe('useHashTab', () => {
it('returns the default id when hash is empty', () => {
const { result } = renderHook(() => useHashTab('schedule'));
expect(result.current[0]).toBe('schedule');
});
it('reads the hash on mount', () => {
window.location.hash = 'simulations';
const { result } = renderHook(() => useHashTab('schedule'));
expect(result.current[0]).toBe('simulations');
});
it('navigate() updates activeId and sets location.hash', () => {
const { result } = renderHook(() => useHashTab('schedule'));
act(() => {
result.current[1]('description');
});
expect(result.current[0]).toBe('description');
expect(window.location.hash).toBe('#description');
});
it('falls back to defaultId when hash becomes empty', () => {
window.location.hash = 'simulations';
const { result } = renderHook(() => useHashTab('schedule'));
act(() => {
window.location.hash = '';
window.dispatchEvent(new HashChangeEvent('hashchange'));
});
expect(result.current[0]).toBe('schedule');
});
});