55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { act, renderHook } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it } from 'vitest'
|
|
import { useClaudeCodeOnboarding } from './useClaudeCodeOnboarding'
|
|
|
|
const localStorageMock = (() => {
|
|
let store: Record<string, string> = {}
|
|
return {
|
|
getItem: (key: string) => store[key] ?? null,
|
|
setItem: (key: string, value: string) => { store[key] = value },
|
|
removeItem: (key: string) => { delete store[key] },
|
|
clear: () => { store = {} },
|
|
}
|
|
})()
|
|
|
|
Object.defineProperty(globalThis, 'localStorage', { value: localStorageMock, writable: true })
|
|
|
|
const DISMISSED_KEY = 'tolaria:claude-code-onboarding-dismissed'
|
|
|
|
describe('useClaudeCodeOnboarding', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
})
|
|
|
|
it('shows the prompt when enabled and not dismissed', () => {
|
|
const { result } = renderHook(() => useClaudeCodeOnboarding(true))
|
|
|
|
expect(result.current.showPrompt).toBe(true)
|
|
})
|
|
|
|
it('hides the prompt when onboarding is disabled', () => {
|
|
const { result } = renderHook(() => useClaudeCodeOnboarding(false))
|
|
|
|
expect(result.current.showPrompt).toBe(false)
|
|
})
|
|
|
|
it('starts hidden when the prompt was already dismissed', () => {
|
|
localStorage.setItem(DISMISSED_KEY, '1')
|
|
|
|
const { result } = renderHook(() => useClaudeCodeOnboarding(true))
|
|
|
|
expect(result.current.showPrompt).toBe(false)
|
|
})
|
|
|
|
it('persists dismissal and hides the prompt', () => {
|
|
const { result } = renderHook(() => useClaudeCodeOnboarding(true))
|
|
|
|
act(() => {
|
|
result.current.dismissPrompt()
|
|
})
|
|
|
|
expect(result.current.showPrompt).toBe(false)
|
|
expect(localStorage.getItem(DISMISSED_KEY)).toBe('1')
|
|
})
|
|
})
|