diff options
Diffstat (limited to 'frontend-vanilla/src/router.test.ts')
| -rw-r--r-- | frontend-vanilla/src/router.test.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/frontend-vanilla/src/router.test.ts b/frontend-vanilla/src/router.test.ts new file mode 100644 index 0000000..d79abc1 --- /dev/null +++ b/frontend-vanilla/src/router.test.ts @@ -0,0 +1,37 @@ +import { describe, it, expect, vi } from 'vitest'; +import { router } from './router'; + +describe('Router', () => { + it('should parse simple paths', () => { + // Mock window.location + vi.stubGlobal('location', { + href: 'http://localhost/v3/feed/123', + pathname: '/v3/feed/123' + }); + + const route = router.getCurrentRoute(); + expect(route.path).toBe('/feed'); + expect(route.params.feedId).toBe('123'); + }); + + it('should parse tags correctly', () => { + vi.stubGlobal('location', { + href: 'http://localhost/v3/tag/Tech%20News', + pathname: '/v3/tag/Tech%20News' + }); + + const route = router.getCurrentRoute(); + expect(route.path).toBe('/tag'); + expect(route.params.tagName).toBe('Tech News'); + }); + + it('should parse query parameters', () => { + vi.stubGlobal('location', { + href: 'http://localhost/v3/?filter=starred', + pathname: '/v3/' + }); + + const route = router.getCurrentRoute(); + expect(route.query.get('filter')).toBe('starred'); + }); +}); |
