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:
43
frontend/tests/hooks/useHashTab.test.tsx
Normal file
43
frontend/tests/hooks/useHashTab.test.tsx
Normal 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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user