import {
  testContext,
  testHook,
  testRenderProp,
} from '../../__tests__/helpers/state'

import {
  DelayedToggle,
  DelayedToggleProvider,
  initDelayedToggle,
  useDelayedToggle,
  useDelayedToggleContext,
} from '../DelayedToggle'

const mockOnEnable = () => {}
const mockOnDisable = () => {}

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

const apiTest = {
  test: 'api',
  config: {
    onEnable: mockOnEnable,
    onDisable: mockOnDisable,
  },
  callback: validateAPI,
}

describe('DelayedToggle', () => {
  testHook(useDelayedToggle, [apiTest])

  testRenderProp(DelayedToggle, 'delayedToggle', [apiTest])

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