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

describe('useSkeleton', () => {
  test('should return true if loading', () => {
    const { result } = renderHook(() => useSkeleton(true))

    expect(result.current).toBe(true)
  })

  test('should return false if not loading', () => {
    const { result } = renderHook(() => useSkeleton(false))

    expect(result.current).toBe(false)
  })

  test('should return false if skeleton was already rendered', () => {
    const { result, rerender } = renderHook(
      ({ showSkeleton }) => useSkeleton(showSkeleton),
      { initialProps: { showSkeleton: true } },
    )

    expect(result.current).toBe(true)

    rerender({ showSkeleton: false })
    expect(result.current).toBe(false)

    rerender({ showSkeleton: true })
    expect(result.current).toBe(false)
  })
})
