Files
hermes-ui/tests/client/router-login-redirect.test.ts
T
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

53 lines
1.4 KiB
TypeScript

// @vitest-environment jsdom
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const mockHasApiKey = vi.hoisted(() => vi.fn())
const mockIsStoredSuperAdmin = vi.hoisted(() => vi.fn())
vi.mock('@/api/client', () => ({
hasApiKey: mockHasApiKey,
isStoredSuperAdmin: mockIsStoredSuperAdmin,
}))
async function loadRouter() {
vi.resetModules()
return (await import('@/router')).default
}
describe('router login redirect', () => {
beforeEach(() => {
mockHasApiKey.mockReturnValue(false)
mockIsStoredSuperAdmin.mockReturnValue(true)
if (!document.queryCommandSupported) {
document.queryCommandSupported = vi.fn(() => false)
}
delete (window as any).hermesDesktop
window.location.hash = ''
})
afterEach(() => {
delete (window as any).hermesDesktop
})
it('keeps the web login redirect when a token exists', async () => {
mockHasApiKey.mockReturnValue(true)
const router = await loadRouter()
await router.push('/')
await router.isReady()
expect(router.currentRoute.value.name).toBe('hermes.chat')
}, 60_000)
it('does not redirect desktop login when a stale token exists', async () => {
mockHasApiKey.mockReturnValue(true)
;(window as any).hermesDesktop = { isDesktop: true }
const router = await loadRouter()
await router.push('/')
await router.isReady()
expect(router.currentRoute.value.name).toBe('login')
})
})