import type { MutableRefObject } from 'react'
import React, { useImperativeHandle } from 'react'
import { useGrid } from './use-grid'
import { render } from '@testing-library/react'

type UseGrid = ReturnType<typeof useGrid>
const Test = ({ gridRef }: { gridRef: MutableRefObject<UseGrid> }) => {
    const grid = useGrid()
    useImperativeHandle(gridRef, () => grid)
    return <div></div>
}

describe('useGrid hook', () => {
    it('should create store', () => {
        const gridRef = React.createRef<UseGrid>()
        render(<Test gridRef={gridRef as MutableRefObject<UseGrid>} />)

        expect(gridRef.current).toHaveProperty('subscribe')
        expect(gridRef.current).toHaveProperty('dispatch')
        expect(gridRef.current).toHaveProperty('getState')
    })

    it('should create events', () => {
        const gridRef = React.createRef<UseGrid>()
        render(<Test gridRef={gridRef as MutableRefObject<UseGrid>} />)

        expect(gridRef.current).toHaveProperty('events')
    })

    it('should create api', () => {
        const gridRef = React.createRef<UseGrid>()
        render(<Test gridRef={gridRef as MutableRefObject<UseGrid>} />)

        expect(gridRef.current).toHaveProperty('api')
    })
})
