mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-21 06:49:37 +00:00
- Remove navigator fallback since systemStatsStore is the standard - Default to Windows when OS info not available - Simplify tests to match new behavior - More consistent with app architecture
164 lines
5.5 KiB
TypeScript
164 lines
5.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { COMFY_BASE_DOMAIN, COMFY_WEBSITE_URLS } from '@/config/comfyDomain'
|
|
import { PYPI_MIRROR, PYTHON_MIRROR } from '@/constants/mirrors'
|
|
import {
|
|
COMFY_URLS,
|
|
DEVELOPER_TOOLS,
|
|
GITHUB_REPOS,
|
|
MODEL_SOURCES,
|
|
getDesktopGuideUrl
|
|
} from '@/constants/urls'
|
|
|
|
describe('URL Constants', () => {
|
|
describe('URL Format Validation', () => {
|
|
it('should have valid HTTPS URLs throughout', () => {
|
|
const httpsPattern =
|
|
/^https:\/\/[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,}(:[0-9]{1,5})?(\/.*)?$/i
|
|
|
|
// Test COMFY_URLS
|
|
expect(COMFY_URLS.website.base).toMatch(httpsPattern)
|
|
expect(COMFY_URLS.docs.base).toMatch(httpsPattern)
|
|
expect(COMFY_URLS.community.discord).toMatch(httpsPattern)
|
|
|
|
// Test GITHUB_REPOS
|
|
Object.values(GITHUB_REPOS).forEach((url) => {
|
|
expect(url).toMatch(httpsPattern)
|
|
})
|
|
|
|
// Test MODEL_SOURCES
|
|
Object.values(MODEL_SOURCES.repos).forEach((url) => {
|
|
expect(url).toMatch(httpsPattern)
|
|
})
|
|
|
|
// Test DEVELOPER_TOOLS
|
|
Object.values(DEVELOPER_TOOLS).forEach((url) => {
|
|
expect(url).toMatch(httpsPattern)
|
|
})
|
|
})
|
|
|
|
it('should have proper GitHub URL format', () => {
|
|
const githubPattern = /^https:\/\/github\.com\/[\w-]+\/[\w-]+(\/[\w-]+)?$/
|
|
|
|
expect(GITHUB_REPOS.comfyui).toMatch(githubPattern)
|
|
expect(GITHUB_REPOS.comfyuiIssues).toMatch(githubPattern)
|
|
expect(GITHUB_REPOS.frontend).toMatch(githubPattern)
|
|
})
|
|
})
|
|
|
|
describe('Mirror Configuration', () => {
|
|
it('should have valid mirror URLs', () => {
|
|
const urlPattern =
|
|
/^https?:\/\/[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,}(:[0-9]{1,5})?(\/.*)?$/i
|
|
|
|
expect(PYTHON_MIRROR.mirror).toMatch(urlPattern)
|
|
expect(PYTHON_MIRROR.fallbackMirror).toMatch(urlPattern)
|
|
expect(PYPI_MIRROR.mirror).toMatch(urlPattern)
|
|
expect(PYPI_MIRROR.fallbackMirror).toMatch(urlPattern)
|
|
})
|
|
})
|
|
|
|
describe('Domain Configuration', () => {
|
|
it('should have valid domain format', () => {
|
|
const domainPattern = /^[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,}$/i
|
|
expect(COMFY_BASE_DOMAIN).toMatch(domainPattern)
|
|
})
|
|
|
|
it('should construct proper website URLs from base domain', () => {
|
|
const expectedBase = `https://www.${COMFY_BASE_DOMAIN}`
|
|
expect(COMFY_WEBSITE_URLS.base).toBe(expectedBase)
|
|
expect(COMFY_WEBSITE_URLS.termsOfService).toBe(
|
|
`${expectedBase}/terms-of-service`
|
|
)
|
|
expect(COMFY_WEBSITE_URLS.privacy).toBe(`${expectedBase}/privacy`)
|
|
})
|
|
})
|
|
|
|
describe('Localization', () => {
|
|
it('should handle valid language codes in getLocalized', () => {
|
|
const validLanguageCodes = ['en', 'zh', 'ja', 'ko', 'es', 'fr', 'de']
|
|
|
|
validLanguageCodes.forEach((lang) => {
|
|
const result = COMFY_URLS.docs.getLocalized('test-path', lang)
|
|
expect(result).toMatch(
|
|
/^https:\/\/docs\.comfy\.org\/(([a-z]{2}-[A-Z]{2}\/)?test-path)$/
|
|
)
|
|
})
|
|
})
|
|
|
|
it('should properly format localized paths', () => {
|
|
expect(COMFY_URLS.docs.getLocalized('test-path', 'en')).toBe(
|
|
'https://docs.comfy.org/test-path'
|
|
)
|
|
expect(COMFY_URLS.docs.getLocalized('test-path', 'zh')).toBe(
|
|
'https://docs.comfy.org/zh-CN/test-path'
|
|
)
|
|
expect(COMFY_URLS.docs.getLocalized('', 'en')).toBe(
|
|
'https://docs.comfy.org/'
|
|
)
|
|
expect(COMFY_URLS.docs.getLocalized('', 'zh')).toBe(
|
|
'https://docs.comfy.org/zh-CN/'
|
|
)
|
|
})
|
|
|
|
it('should generate platform and locale-aware desktop guide URLs', () => {
|
|
// Test default (no OS provided) - should default to Windows
|
|
const defaultUrl = getDesktopGuideUrl('en')
|
|
expect(defaultUrl).toBe(
|
|
'https://docs.comfy.org/installation/desktop/windows'
|
|
)
|
|
|
|
// Test with systemStats OS parameter - macOS
|
|
const macUrl = getDesktopGuideUrl('en', 'Darwin 23.1.0')
|
|
expect(macUrl).toBe('https://docs.comfy.org/installation/desktop/macos')
|
|
|
|
// Test with systemStats OS parameter - Windows
|
|
const winUrl = getDesktopGuideUrl('en', 'Windows 10')
|
|
expect(winUrl).toBe('https://docs.comfy.org/installation/desktop/windows')
|
|
|
|
// Test Chinese locale with systemStats
|
|
const zhMacUrl = getDesktopGuideUrl('zh', 'macOS 14.0')
|
|
expect(zhMacUrl).toBe(
|
|
'https://docs.comfy.org/zh-CN/installation/desktop/macos'
|
|
)
|
|
|
|
// Test Chinese locale defaults to Windows
|
|
const zhDefaultUrl = getDesktopGuideUrl('zh')
|
|
expect(zhDefaultUrl).toBe(
|
|
'https://docs.comfy.org/zh-CN/installation/desktop/windows'
|
|
)
|
|
|
|
// Test other locales default to English
|
|
const frUrl = getDesktopGuideUrl('fr', 'Windows 11')
|
|
expect(frUrl).toBe('https://docs.comfy.org/installation/desktop/windows')
|
|
})
|
|
})
|
|
|
|
describe('Security', () => {
|
|
it('should only use secure HTTPS for external URLs', () => {
|
|
const allUrls = [
|
|
...Object.values(GITHUB_REPOS),
|
|
...Object.values(MODEL_SOURCES.repos),
|
|
...Object.values(DEVELOPER_TOOLS),
|
|
COMFY_URLS.website.base,
|
|
COMFY_URLS.docs.base,
|
|
COMFY_URLS.community.discord
|
|
]
|
|
|
|
allUrls.forEach((url) => {
|
|
expect(url.startsWith('https://')).toBe(true)
|
|
expect(url.startsWith('http://')).toBe(false)
|
|
})
|
|
})
|
|
|
|
it('should have valid URL allowlist for model sources', () => {
|
|
const urlPattern =
|
|
/^https?:\/\/([a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,}|localhost)(:[0-9]+)?\/?.*$/i
|
|
|
|
MODEL_SOURCES.allowedDomains.forEach((url) => {
|
|
expect(url).toMatch(urlPattern)
|
|
})
|
|
})
|
|
})
|
|
})
|