import { describe, expect, test } from 'vitest'
import { renderHook } from '@testing-library/react'
import { useTypewriter } from './use-typewriter'

describe('useTypewriter', () => {
  test('starts with empty text and isTyping=true when fullText is non-empty', () => {
    const { result } = renderHook(() => useTypewriter('hello'))
    expect(result.current.displayedText).toBe('')
    expect(result.current.isTyping).toBe(true)
  })

  test('returns the full text immediately when skipAnimation is true', () => {
    const { result } = renderHook(() =>
      useTypewriter('hello', { skipAnimation: true }),
    )
    expect(result.current.displayedText).toBe('hello')
    expect(result.current.isTyping).toBe(false)
  })

  test('isTyping=false for empty fullText', () => {
    const { result } = renderHook(() => useTypewriter(''))
    expect(result.current.displayedText).toBe('')
    expect(result.current.isTyping).toBe(false)
  })

  test('skipAnimation captured at mount — toggling later does not retrigger reveal', () => {
    const { result, rerender } = renderHook(
      ({ skip }: { skip: boolean }) =>
        useTypewriter('hello', { skipAnimation: skip }),
      { initialProps: { skip: true } },
    )
    expect(result.current.displayedText).toBe('hello')

    rerender({ skip: false })
    expect(result.current.displayedText).toBe('hello')
    expect(result.current.isTyping).toBe(false)
  })
})
