import {
  testContext,
  testHook,
  testRenderProp,
} from '../../__tests__/helpers/state'
import { Event, EventProvider, useEvent, useEventContext } from '../Event'

const validateAPI = (api) => {
  expect(api.value).toEqual(null)
}

const apiTest = {
  test: 'api',
  config: {},
  callback: validateAPI,
}

jest.spyOn(global.console, 'warn').mockImplementation(() => {})

afterAll(() => {
  jest.clearAllMocks()
})

describe('Event', () => {
  testHook(useEvent, [
    apiTest,
    {
      test: 'mutations',
      config: { initialValue: 'foo' },
    },
  ])

  testRenderProp(Event, 'event', [apiTest])

  testContext(EventProvider, useEventContext, [
    apiTest,
    {
      test: 'missing provider',
      config: {},
      injectProvider: false,
      callback: (context, { spy }) => {
        expect(context.value).toBe(null)
      },
    },
  ])
})
