import { act, renderHook } from '@testing-library/react-hooks';
import { useBooleanState } from '../use-boolean-state';

describe('useBooleanState hook', () => {
  test('defaultValue works correctly', async () => {
    const defaultValue = false;
    const { result } = renderHook(() => useBooleanState(defaultValue));
    expect(result.current.value).toBe(defaultValue);
  });

  test('setValue works correctly', async () => {
    const { result } = renderHook(() => useBooleanState(false));
    act(() => result.current.setValue(true));
    expect(result.current.value).toBeTruthy();
    act(() => result.current.setValue(false));
    expect(result.current.value).toBeFalsy();
  });

  test('toggle works correctly', async () => {
    const defaultValue = false;
    const { result } = renderHook(() => useBooleanState(defaultValue));
    act(() => result.current.toggle());
    expect(result.current.value).toBe(!defaultValue);
  });

  test('setTrue works correctly', async () => {
    const { result } = renderHook(() => useBooleanState(false));
    act(() => result.current.setTrue());
    expect(result.current.value).toBeTruthy();
  });

  test('setFalse works correctly', async () => {
    const { result } = renderHook(() => useBooleanState(true));
    act(() => result.current.setFalse());
    expect(result.current.value).toBeFalsy();
  });
});
