feat: add first-launch Claude Code onboarding
This commit is contained in:
54
src/hooks/useClaudeCodeOnboarding.test.ts
Normal file
54
src/hooks/useClaudeCodeOnboarding.test.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user