import { act, renderHook } from '@testing-library/react-hooks';
import { useInputValue } from '../useInputValue';
describe('useInputValue', function () {
  var rerender;
  var result;
  beforeEach(function () {
    var render = renderHook(function (value) {
      return useInputValue(value);
    }, {
      initialProps: undefined
    });
    rerender = render.rerender;
    result = render.result;
  });
  it('should set `committedValue` as an empty string', function () {
    expect(result.current.committedValue).toEqual('');
  });
  it('should set `hasValue` to `false`', function () {
    expect(result.current.hasValue).toBeFalsy();
  });
  describe('when the user types', function () {
    beforeEach(function () {
      act(function () {
        var event = {
          target: {
            value: 'a'
          }
        };

        // @ts-ignore
        result.current.onValueChange(event);
      });
    });
    it('should set `committedValue`', function () {
      expect(result.current.committedValue).toEqual('a');
    });
    it('should set `hasValue` to `true`', function () {
      expect(result.current.hasValue).toBeTruthy();
    });
  });
  describe('when the user deletes', function () {
    beforeEach(function () {
      act(function () {
        var event = {
          target: {}
        };

        // @ts-ignore
        result.current.onValueChange(event);
      });
    });
    it('should set `committedValue` as an empty string', function () {
      expect(result.current.committedValue).toEqual('');
    });
  });
  describe('when `value` is updated by a side effect', function () {
    describe('and the value is a string', function () {
      beforeEach(function () {
        rerender('new');
      });
      it('should set `committedValue`', function () {
        expect(result.current.committedValue).toEqual('new');
      });
    });
    describe('and the value is undefined', function () {
      beforeEach(function () {
        rerender(undefined);
      });
      it('should set `committedValue` as an empty string', function () {
        expect(result.current.committedValue).toEqual('');
      });
    });
  });
});