skillhub/web/src/app/router.test.ts
dongmucat 5c95ab2b38 feat(skill): add version compare page with unified diff
Introduce a dedicated `/space/$namespace/$slug/compare` page that compares
two published skill versions GitHub-style: left file list + right unified
diff. Backend exposes `GET /versions/compare` returning structured diff
(computed via java-diff-utils) with per-file hunks, binary placeholder,
and truncation flags. Frontend uses two version selectors scoped to
PUBLISHED versions, a file search box, active-file highlighting, and
whitespace-preserving unified view. E2E covers the publish + rerelease
+ approve round trip; controller/domain tests cover happy path and
same-version rejection.
2026-05-07 09:45:26 +08:00

48 lines
1.6 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')
})
})