cc-haha/desktop/src/lib/previewLinkRouter.test.ts
程序员阿江(Relakkes) 8c4e8073ab feat(desktop): add classifyPreviewLink classifier
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 17:40:45 +08:00

30 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { classifyPreviewLink } from './previewLinkRouter'
describe('classifyPreviewLink', () => {
it('classifies loopback urls as browser-localhost', () => {
expect(classifyPreviewLink('http://localhost:5173/').kind).toBe('browser-localhost')
expect(classifyPreviewLink('http://127.0.0.1:8080/x').kind).toBe('browser-localhost')
})
it('classifies html file paths as browser-file', () => {
expect(classifyPreviewLink('file:///Users/x/index.html').kind).toBe('browser-file')
expect(classifyPreviewLink('/Users/x/page.htm').kind).toBe('browser-file')
expect(classifyPreviewLink('./out/index.html').kind).toBe('browser-file')
})
it('classifies relative previewable docs as file-preview', () => {
expect(classifyPreviewLink('docs/report.md').kind).toBe('file-preview')
expect(classifyPreviewLink('src/app.ts').kind).toBe('file-preview')
})
it('classifies remote http(s) as remote', () => {
expect(classifyPreviewLink('https://example.com').kind).toBe('remote')
})
it('ignores anchors and empty', () => {
expect(classifyPreviewLink('#section').kind).toBe('ignored')
expect(classifyPreviewLink('').kind).toBe('ignored')
})
it('exposes a normalized path for file kinds', () => {
expect(classifyPreviewLink('file:///Users/x/index.html').path).toBe('/Users/x/index.html')
expect(classifyPreviewLink('docs/report.md').path).toBe('docs/report.md')
})
})