test: add coverage for none check method, re-scan update, icon registry

This commit is contained in:
Pouzor
2026-03-08 01:12:32 +01:00
parent b2a6651db7
commit f93afd0646
4 changed files with 192 additions and 1 deletions
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
import { NODE_TYPE_LABELS, STATUS_COLORS, EDGE_TYPE_LABELS } from '@/types'
import type { CheckMethod } from '@/types'
describe('NODE_TYPE_LABELS', () => {
it('has an entry for every node type', () => {
@@ -33,3 +34,14 @@ describe('EDGE_TYPE_LABELS', () => {
})
})
})
describe('CheckMethod', () => {
it('includes none as a valid check method', () => {
const methods: CheckMethod[] = ['none', 'ping', 'http', 'https', 'tcp', 'ssh', 'prometheus', 'health']
// All values are valid CheckMethod — this is a compile-time type check;
// runtime test just ensures the array is well-formed
expect(methods).toContain('none')
expect(methods).toContain('ping')
expect(methods.length).toBe(8)
})
})
@@ -0,0 +1,85 @@
import { describe, it, expect } from 'vitest'
import { Globe } from 'lucide-react'
import { ICON_REGISTRY, ICON_CATEGORIES, ICON_MAP, resolveNodeIcon } from '../nodeIcons'
describe('ICON_REGISTRY', () => {
it('has entries', () => {
expect(ICON_REGISTRY.length).toBeGreaterThan(0)
})
it('every entry has required fields', () => {
for (const entry of ICON_REGISTRY) {
expect(typeof entry.key).toBe('string')
expect(entry.key.length).toBeGreaterThan(0)
expect(typeof entry.label).toBe('string')
expect(typeof entry.category).toBe('string')
expect(entry.icon).toBeTruthy()
}
})
it('all keys are unique', () => {
const keys = ICON_REGISTRY.map((e) => e.key)
expect(new Set(keys).size).toBe(keys.length)
})
it('contains expected well-known icons', () => {
const keys = ICON_REGISTRY.map((e) => e.key)
expect(keys).toContain('home') // Home Assistant
expect(keys).toContain('play') // Jellyfin
expect(keys).toContain('shield') // Pi-hole
expect(keys).toContain('anchor') // Portainer
expect(keys).toContain('key') // Vaultwarden
expect(keys).toContain('database') // DB services
})
})
describe('ICON_CATEGORIES', () => {
it('has at least one category', () => {
expect(ICON_CATEGORIES.length).toBeGreaterThan(0)
})
it('every entry in ICON_REGISTRY belongs to a known category', () => {
for (const entry of ICON_REGISTRY) {
expect(ICON_CATEGORIES).toContain(entry.category)
}
})
})
describe('ICON_MAP', () => {
it('contains an entry for every registry key', () => {
for (const entry of ICON_REGISTRY) {
expect(ICON_MAP[entry.key]).toBeDefined()
expect(ICON_MAP[entry.key]).toBe(entry.icon)
}
})
it('returns undefined for unknown keys', () => {
expect(ICON_MAP['__nonexistent__']).toBeUndefined()
})
})
describe('resolveNodeIcon', () => {
it('returns typeIcon when no custom_icon set', () => {
expect(resolveNodeIcon(Globe)).toBe(Globe)
})
it('returns typeIcon when custom_icon is undefined', () => {
expect(resolveNodeIcon(Globe, undefined)).toBe(Globe)
})
it('returns typeIcon when custom_icon key is unknown', () => {
expect(resolveNodeIcon(Globe, '__nonexistent__')).toBe(Globe)
})
it('returns the custom icon when key is valid', () => {
const homeEntry = ICON_REGISTRY.find((e) => e.key === 'home')!
expect(resolveNodeIcon(Globe, 'home')).toBe(homeEntry.icon)
})
it('custom icon overrides typeIcon', () => {
const playEntry = ICON_REGISTRY.find((e) => e.key === 'play')!
const result = resolveNodeIcon(Globe, 'play')
expect(result).toBe(playEntry.icon)
expect(result).not.toBe(Globe)
})
})