import { describe, it, expect } from 'vitest'; import { PathnameInterpreter } from './PathnameInterpreter'; describe('PathnameInterpreter', () => { describe('interpret() - no locale prefix cases', () => { it('should handle root path', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/'); expect(result).toEqual({ locale: null, logicalPathname: '/', }); }); it('should handle simple path without locale', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/dashboard'); expect(result).toEqual({ locale: null, logicalPathname: '/dashboard', }); }); it('should handle dynamic route without locale', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/leagues/123'); expect(result).toEqual({ locale: null, logicalPathname: '/leagues/123', }); }); it('should handle nested path without locale', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/auth/login'); expect(result).toEqual({ locale: null, logicalPathname: '/auth/login', }); }); }); describe('interpret() - with locale prefix', () => { it('should strip valid 2-letter locale prefix', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/de/dashboard'); expect(result).toEqual({ locale: 'de', logicalPathname: '/dashboard', }); }); it('should handle locale prefix with dynamic route', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/en/leagues/456'); expect(result).toEqual({ locale: 'en', logicalPathname: '/leagues/456', }); }); it('should handle locale prefix with root path', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/fr/'); expect(result).toEqual({ locale: 'fr', logicalPathname: '/', }); }); it('should handle locale prefix with nested path', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/es/auth/settings'); expect(result).toEqual({ locale: 'es', logicalPathname: '/auth/settings', }); }); }); describe('interpret() - edge cases', () => { it('should not strip invalid locale (numeric)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/999/dashboard'); expect(result).toEqual({ locale: null, logicalPathname: '/999/dashboard', }); }); it('should not strip invalid locale (3 letters)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/eng/dashboard'); expect(result).toEqual({ locale: null, logicalPathname: '/eng/dashboard', }); }); it('should not strip invalid locale (uppercase)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/DE/dashboard'); expect(result).toEqual({ locale: null, logicalPathname: '/DE/dashboard', }); }); it('should not strip invalid locale (with special chars)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/d-/dashboard'); expect(result).toEqual({ locale: null, logicalPathname: '/d-/dashboard', }); }); it('should handle empty path', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret(''); expect(result).toEqual({ locale: null, logicalPathname: '', }); }); it('should handle path with only locale (no trailing slash)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/de'); expect(result).toEqual({ locale: 'de', logicalPathname: '/', }); }); it('should handle path with only locale (with trailing slash)', () => { const interpreter = new PathnameInterpreter(); const result = interpreter.interpret('/de/'); expect(result).toEqual({ locale: 'de', logicalPathname: '/', }); }); }); });