test: add theme command registry tests and minor fixes
This commit is contained in:
@@ -51,7 +51,7 @@ export function CommandPalette({ open, commands, onClose }: CommandPaletteProps)
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setQuery('') // eslint-disable-line react-hooks/set-state-in-effect -- reset on open
|
||||
setSelectedIndex(0) // eslint-disable-line react-hooks/set-state-in-effect -- reset on open
|
||||
setSelectedIndex(0)
|
||||
setTimeout(() => inputRef.current?.focus(), 50)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
@@ -209,7 +209,6 @@ function SearchContent({
|
||||
onMouseEnter={() => onHover(i)}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* eslint-disable-next-line react-hooks/static-components -- icon from static map lookup */}
|
||||
<TypeIcon width={14} height={14} className="shrink-0" style={{ color: typeColor ?? 'var(--muted-foreground)' }} />
|
||||
<span className="min-w-0 flex-1 truncate text-[13px] font-medium text-foreground">{result.title}</span>
|
||||
{noteType && (
|
||||
|
||||
@@ -437,6 +437,46 @@ describe('useCommandRegistry', () => {
|
||||
const groups = new Set(result.current.map(c => c.group))
|
||||
expect(groups).toContain('Appearance')
|
||||
})
|
||||
|
||||
it('generates open-theme commands for each theme when onOpenTheme is provided', () => {
|
||||
const onOpenTheme = vi.fn()
|
||||
const { result } = renderHook(() => useCommandRegistry(makeConfig({
|
||||
themes: themeFixtures, activeThemeId: 'default', onOpenTheme,
|
||||
})))
|
||||
const openDefault = result.current.find(c => c.id === 'open-theme-default')
|
||||
const openDark = result.current.find(c => c.id === 'open-theme-dark')
|
||||
expect(openDefault).toBeDefined()
|
||||
expect(openDefault!.label).toBe('Edit Default Theme')
|
||||
expect(openDefault!.group).toBe('Appearance')
|
||||
expect(openDefault!.enabled).toBe(true)
|
||||
expect(openDark).toBeDefined()
|
||||
expect(openDark!.label).toBe('Edit Dark Theme')
|
||||
})
|
||||
|
||||
it('omits open-theme commands when onOpenTheme is not provided', () => {
|
||||
const { result } = renderHook(() => useCommandRegistry(makeConfig({
|
||||
themes: themeFixtures, activeThemeId: 'default',
|
||||
})))
|
||||
expect(result.current.find(c => c.id === 'open-theme-default')).toBeUndefined()
|
||||
expect(result.current.find(c => c.id === 'open-theme-dark')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('calls onOpenTheme with correct themeId when open-theme command executes', () => {
|
||||
const onOpenTheme = vi.fn()
|
||||
const { result } = renderHook(() => useCommandRegistry(makeConfig({
|
||||
themes: themeFixtures, activeThemeId: 'default', onOpenTheme,
|
||||
})))
|
||||
result.current.find(c => c.id === 'open-theme-dark')!.execute()
|
||||
expect(onOpenTheme).toHaveBeenCalledWith('dark')
|
||||
})
|
||||
|
||||
it('open-theme command is always enabled regardless of active theme', () => {
|
||||
const onOpenTheme = vi.fn()
|
||||
const { result } = renderHook(() => useCommandRegistry(makeConfig({
|
||||
themes: themeFixtures, activeThemeId: 'default', onOpenTheme,
|
||||
})))
|
||||
expect(result.current.find(c => c.id === 'open-theme-default')!.enabled).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -296,7 +296,6 @@ export function useThemeManager(
|
||||
const entry = entries.find(e => e.path === activeThemeId)
|
||||
if (!entry || !isEntryRemoved(entry)) return
|
||||
clearTheme()
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect -- sync fallback when active theme is deleted
|
||||
setActiveThemeId(null)
|
||||
if (vaultPath) tauriCall('set_active_theme', { vaultPath, themeId: null }).catch(() => {})
|
||||
}, [entries, activeThemeId, clearTheme, vaultPath, setActiveThemeId])
|
||||
|
||||
Reference in New Issue
Block a user