steam-backlog-enforcer/web/src/icons/registry.test.ts
Krzysztof kuhy Rudnicki 94a0e8a1c3 Add map-installed Proton map view and apply job
GET /api/compat serves every installed game's compat-tool decision as
rows from the installer's own code (steam_installer/compat_rows.py, the
rows --map-installed now logs from), cached by file stats. The Library
page gets a Proton map view (sortable, filterable, fuzzy search, hash
state, 30 s poll) and a map-installed job: POST checks the ids, the
phrase "map N games" and the game-running guard; the job re-checks
them and streams --map-installed --apply --yes --appids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
2026-11-22 21:43:23 +01:00

59 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest'
import type { JobState } from '../api/jobContract'
import { COMMAND_HOME, commandIcon } from '../commands/catalog'
import { NAV } from '../shell/nav'
import type { Tone } from '../ui/build'
import { ICONS, iconEntry, isIconId } from './registry'
const JOB_STATES: JobState[] = ['queued', 'running', 'waiting_input', 'succeeded', 'failed', 'cancelled']
const TONES: Tone[] = ['info', 'success', 'warning', 'danger']
describe('icon registry', () => {
it('registers pass 1 first (8 nav, the palette, 29 commands, 6 job states, 4 tones), then the rest of the UI', () => {
const ids = ICONS.map((e) => e.id)
expect(new Set(ids).size).toBe(ids.length)
const pass1 = /^(nav|palette|cmd|job\.state|notice)\./
expect(ids.slice(0, 8 + 1 + 29 + 6 + 4).every((id) => pass1.test(id))).toBe(true)
expect(ids.slice(8 + 1 + 29 + 6 + 4).some((id) => pass1.test(id))).toBe(false)
expect(ids.length).toBeGreaterThan(48)
for (const n of NAV) expect(isIconId(n.icon)).toBe(true)
expect(isIconId('palette.open')).toBe(true)
for (const name of Object.keys(COMMAND_HOME) as (keyof typeof COMMAND_HOME)[]) {
expect(isIconId(commandIcon(name))).toBe(true)
}
for (const s of JOB_STATES) expect(isIconId(`job.state.${s}`)).toBe(true)
for (const t of TONES) expect(isIconId(`notice.${t}`)).toBe(true)
})
it.each(ICONS.map((e) => [e.id, e] as const))('%s: glyph, name, description, 3 words, 3 alternatives', (id, e) => {
// The server's route accepts only this id shape (_web_routes._ICON).
expect(id).toMatch(/^[a-z][a-z0-9_.-]{0,63}$/)
expect(e.glyph).not.toBe('')
expect(e.spoken).not.toBe('')
expect(e.desc.length).toBeGreaterThan(20)
expect(e.desc.split(/[.!?](\s|$)/).filter((s) => s.trim()).length).toBeLessThanOrEqual(2)
expect(e.words).toHaveLength(3)
expect(new Set(e.words.map((w) => w.toLowerCase())).size).toBe(3)
for (const w of e.words) expect(w).toMatch(/^\S+$/)
expect(e.alts).toHaveLength(3)
expect(new Set([e.glyph, ...e.alts]).size).toBe(4)
// Not the same picture twice, even when only the emoji variation selector differs.
expect(new Set([e.glyph, ...e.alts].map((g) => g.replaceAll('️', ''))).size).toBe(4)
})
it('keeps every default glyph the UI painted before the registry', () => {
expect(iconEntry('nav.dashboard').glyph).toBe('🏠')
expect(iconEntry('palette.open').glyph).toBe('🔍')
expect(iconEntry('cmd.done').glyph).toBe('🏆')
expect(iconEntry('cmd.restore-backup').glyph).toBe('🗄️')
expect(iconEntry('job.state.waiting_input').glyph).toBe('⚠️')
expect(iconEntry('notice.danger').glyph).toBe('⛔')
})
it('tells registered ids from raw glyphs', () => {
expect(isIconId('cmd.done')).toBe(true)
expect(isIconId('🏆')).toBe(false)
expect(isIconId('toString')).toBe(false)
})
})