import {QueryClient} from '@tanstack/react-query'
import {renderHook} from '@testing-library/react'
import {describe, expect, it} from 'vitest'

import {MinisQueryProvider} from './MinisQueryProvider'
import {useShopMinisQueryClient} from './queryClient'

describe('MinisQueryProvider', () => {
  it('provides QueryClient to children', () => {
    const {result} = renderHook(() => useShopMinisQueryClient(), {
      wrapper: MinisQueryProvider,
    })

    expect(result.current).toBeInstanceOf(QueryClient)
  })

  it('allows hooks to work within provider', () => {
    const {result} = renderHook(() => useShopMinisQueryClient(), {
      wrapper: MinisQueryProvider,
    })

    // Should not throw
    expect(() => result.current).not.toThrow()
  })

  it('provides consistent QueryClient across renders', () => {
    const {result, rerender} = renderHook(() => useShopMinisQueryClient(), {
      wrapper: MinisQueryProvider,
    })

    const firstClient = result.current
    rerender()
    const secondClient = result.current

    // Same instance across re-renders
    expect(firstClient).toBe(secondClient)
  })
})
