import { describe, it, expect, beforeEach } from 'vitest'; import { navigate, currentHash, matchRoute } from '../../js/router.js'; describe('router', () => { beforeEach(() => { window.location.hash = ''; }); it('currentHash defaults to / when empty', () => { window.location.hash = ''; expect(currentHash()).toBe('/'); }); it('currentHash strips leading hash', () => { window.location.hash = '#/dashboard'; expect(currentHash()).toBe('/dashboard'); }); it('navigate sets window hash', () => { navigate('#/login'); expect(window.location.hash).toBe('#/login'); }); it('matchRoute extracts questionnaire id', () => { const params = matchRoute('/questionnaire/:id', '/questionnaire/qn-123'); expect(params).toEqual({ id: 'qn-123' }); }); it('matchRoute returns null when path does not match', () => { expect(matchRoute('/questionnaire/:id', '/users')).toBeNull(); }); });