Fix 4: useHashTab navigate() uses history.replaceState instead of window.location.hash assignment — no spurious history entries, no anchor-jump scroll side-effect. Fix 5: Tabs ArrowLeft/ArrowRight keyboard nav (WAI-ARIA tabs pattern). Fix 6: TabId union type in EngagementDetailPage, cast from string for type-safe switch on activeTab without breaking Tabs.onChange signature. Fix 7: intentional comment on UsersAdminPage reset-password aerated row. Tests: 236/236 (+2 arrow-key assertions in Tabs.test.tsx). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
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 hash via replaceState (no history entry)', () => {
|
|
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');
|
|
});
|
|
});
|