import React from 'react'
import {
  testContext,
  testHook,
  testRenderProp,
} from '../../__tests__/helpers/state'
import {
  initTrigger,
  Trigger,
  TriggerProvider,
  useTrigger,
  useTriggerContext,
} from '../Trigger'

const mockEnable = () => {}
const mockDisable = () => {}

const validateAPI = (api) => {
  expect(api.isVisible).toBe(false)
  expect(api.enable).toBeInstanceOf(Function)
  expect(api.disable).toBeInstanceOf(Function)
  expect(api.toggle).toBeInstanceOf(Function)
}

const apiTest = {
  test: 'api',
  config: {
    scope: React.createRef(),
    enable: mockEnable,
    disable: mockDisable,
  },
  callback: validateAPI,
}

describe('Trigger', () => {
  testHook(useTrigger, [apiTest])

  testRenderProp(Trigger, 'trigger', [apiTest])

  testContext(TriggerProvider, useTriggerContext, [
    apiTest,
    ,
    {
      test: 'missing provider',
      config: {},
      injectProvider: false,
      callback: (context) => {
        expect(context).toEqual(initTrigger)
      },
    },
  ])
})
