fix: use camelCase arg keys for Tauri theme commands (#160)
* fix: use camelCase arg keys for Tauri theme commands Tauri v2 auto-converts Rust snake_case params to camelCase for the JS interface. useThemeManager was sending snake_case keys (vault_path, theme_id, source_id) which caused "missing required key vaultPath" errors in the native app, making New Theme silently fail. All other hooks already use camelCase — this aligns the theme manager. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: exclude search.rs and lib.rs from coverage --------- Co-authored-by: Test <test@test.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -105,7 +105,7 @@ describe('useThemeManager', () => {
|
||||
await result.current.switchTheme('dark')
|
||||
})
|
||||
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('set_active_theme', { vault_path: '/vault', theme_id: 'dark' })
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('set_active_theme', { vaultPath: '/vault', themeId: 'dark' })
|
||||
expect(result.current.activeThemeId).toBe('dark')
|
||||
})
|
||||
|
||||
@@ -140,7 +140,7 @@ describe('useThemeManager', () => {
|
||||
})
|
||||
|
||||
expect(newId).toBe('new-theme-id')
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('create_theme', { vault_path: '/vault', source_id: 'default' })
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('create_theme', { vaultPath: '/vault', sourceId: 'default' })
|
||||
// Should reload after creation
|
||||
const listCalls = mockInvokeFn.mock.calls.filter(c => c[0] === 'list_themes')
|
||||
expect(listCalls.length).toBeGreaterThanOrEqual(2)
|
||||
@@ -156,7 +156,7 @@ describe('useThemeManager', () => {
|
||||
await result.current.createTheme()
|
||||
})
|
||||
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('create_theme', { vault_path: '/vault', source_id: null })
|
||||
expect(mockInvokeFn).toHaveBeenCalledWith('create_theme', { vaultPath: '/vault', sourceId: null })
|
||||
})
|
||||
|
||||
it('handles load failure gracefully', async () => {
|
||||
|
||||
@@ -74,8 +74,8 @@ export function useThemeManager(vaultPath: string | null): ThemeManager {
|
||||
if (!vaultPath) return
|
||||
try {
|
||||
const [themeList, settings] = await Promise.all([
|
||||
tauriCall<ThemeFile[]>('list_themes', { vault_path: vaultPath }),
|
||||
tauriCall<VaultSettings>('get_vault_settings', { vault_path: vaultPath }),
|
||||
tauriCall<ThemeFile[]>('list_themes', { vaultPath }),
|
||||
tauriCall<VaultSettings>('get_vault_settings', { vaultPath }),
|
||||
])
|
||||
setThemes(themeList)
|
||||
setActiveThemeId(settings.theme)
|
||||
@@ -97,7 +97,7 @@ export function useThemeManager(vaultPath: string | null): ThemeManager {
|
||||
const switchTheme = useCallback(async (themeId: string) => {
|
||||
if (!vaultPath) return
|
||||
try {
|
||||
await tauriCall<null>('set_active_theme', { vault_path: vaultPath, theme_id: themeId })
|
||||
await tauriCall<null>('set_active_theme', { vaultPath, themeId })
|
||||
setActiveThemeId(themeId)
|
||||
} catch (err) {
|
||||
console.error('Failed to switch theme:', err)
|
||||
@@ -108,8 +108,8 @@ export function useThemeManager(vaultPath: string | null): ThemeManager {
|
||||
if (!vaultPath) return ''
|
||||
try {
|
||||
const newId = await tauriCall<string>('create_theme', {
|
||||
vault_path: vaultPath,
|
||||
source_id: sourceId ?? null,
|
||||
vaultPath,
|
||||
sourceId: sourceId ?? null,
|
||||
})
|
||||
await loadThemes()
|
||||
await switchTheme(newId)
|
||||
|
||||
@@ -252,16 +252,16 @@ export const mockHandlers: Record<string, (args: any) => any> = {
|
||||
create_getting_started_vault: () => '/Users/mock/Documents/Laputa',
|
||||
register_mcp_tools: () => 'registered',
|
||||
list_themes: (): ThemeFile[] => [...mockThemes],
|
||||
get_theme: (args: { theme_id: string }): ThemeFile => {
|
||||
const t = mockThemes.find(t => t.id === args.theme_id)
|
||||
if (!t) throw new Error(`Theme not found: ${args.theme_id}`)
|
||||
get_theme: (args: { themeId: string }): ThemeFile => {
|
||||
const t = mockThemes.find(t => t.id === args.themeId)
|
||||
if (!t) throw new Error(`Theme not found: ${args.themeId}`)
|
||||
return { ...t }
|
||||
},
|
||||
get_vault_settings: (): VaultSettings => ({ ...mockVaultSettings }),
|
||||
save_vault_settings: (args: { settings: VaultSettings }) => { mockVaultSettings = { ...args.settings }; return null },
|
||||
set_active_theme: (args: { theme_id: string }) => { mockVaultSettings.theme = args.theme_id; return null },
|
||||
create_theme: (args: { source_id?: string }): string => {
|
||||
const sourceId = args.source_id ?? 'default'
|
||||
set_active_theme: (args: { themeId: string }) => { mockVaultSettings.theme = args.themeId; return null },
|
||||
create_theme: (args: { sourceId?: string }): string => {
|
||||
const sourceId = args.sourceId ?? 'default'
|
||||
const source = mockThemes.find(t => t.id === sourceId) ?? mockThemes[0]
|
||||
const newId = `untitled-${mockThemes.length}`
|
||||
mockThemes.push({ ...source, id: newId, name: 'Untitled Theme' })
|
||||
|
||||
Reference in New Issue
Block a user