skillhub/web/src/app/router.test.ts
Danny 7cf9f22182
feat(cli): add OAuth device flow login (#857)
* feat(cli): add OAuth device flow login

Signed-off-by: Danny5487401 <64348131+Danny5487401@users.noreply.github.com>

* fix(cli): avoid browser launch in headless login

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

* fix(cli): complete device flow runtime path

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>

---------

Signed-off-by: Danny5487401 <64348131+Danny5487401@users.noreply.github.com>
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
Co-authored-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-09-17 16:29:20 +08:00

54 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
// The router module captures window.location.search at module load time.
// We test the exported ORIGINAL_URL_SEARCH constant and the buildReturnTo
// helper (tested indirectly via the route tree structure).
vi.mock('./layout', () => ({
Layout: () => null,
}))
vi.mock('@/api/client', () => ({
getCurrentUser: vi.fn().mockResolvedValue(null),
}))
vi.mock('@/shared/components/role-guard', () => ({
RoleGuard: ({ children }: { children: unknown }) => children,
}))
vi.mock('@/shared/lib/search-query', () => ({
normalizeSearchQuery: (q: string) => q.trim(),
}))
import { ORIGINAL_URL_SEARCH, router } from './router'
describe('ORIGINAL_URL_SEARCH', () => {
it('is a string (captured from window.location.search at load time)', () => {
expect(typeof ORIGINAL_URL_SEARCH).toBe('string')
})
})
describe('router', () => {
it('exports a TanStack Router instance with a route tree', () => {
expect(router).toBeDefined()
expect(router.routeTree).toBeDefined()
})
it('has a routeTree structure', () => {
// The router instance exists and has the expected structure
// In test environment, flatRoutes may not be populated until router is used
expect(router.routeTree).toBeDefined()
})
it('registers the skill version compare route', () => {
const children = (router.routeTree.children ?? []) as Array<{ fullPath?: string; path?: string }>
const childPaths = children.map((route) => route.fullPath ?? route.path)
expect(childPaths).toContain('/space/$namespace/$slug/compare')
})
it('registers the device authorization route', () => {
const children = (router.routeTree.children ?? []) as Array<{ fullPath?: string; path?: string }>
const childPaths = children.map((route) => route.fullPath ?? route.path)
expect(childPaths).toContain('/device')
})
})