import React__default from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import userEvent from '@testing-library/user-event';
import AutosuggestInput from './index.js';
import '../extends-C4cduGrv.js';
import '../defineProperty-CEd-kZQW.js';
import '../toConsumableArray-dKQYsfpV.js';
import '../slicedToArray-BB-AwwkK.js';
import '../objectWithoutProperties-TXwlfNxG.js';
import 'prop-types';
import '../_baseIteratee-D8btQgSF.js';
import '../typeof-CgC7Bq6K.js';
import '../_commonjsHelpers-_1FafXWI.js';
import '../use-forwardedref/index.js';
import '../use-localstorage/index.js';

describe('AutosuggestInput', function () {
  it('suggests values that have been previously entered', function () {
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput"
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    var suggestion = screen.getByTestId('suggestion');
    userEvent.type(input, 'Spaghetti');
    userEvent.tab();
    userEvent.clear(input);
    expect(input).toHaveValue('');
    userEvent.type(input, 'Spag');
    expect(suggestion).toHaveTextContent('Spaghetti');
  });
  it('shows no suggestion when input matches no stored suggestions', function () {
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput"
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    var suggestion = screen.getByTestId('suggestion');
    userEvent.type(input, 'Lasagna');
    expect(suggestion).toHaveTextContent('');
  });
  it('uses case sensitive suggestions', function () {
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput"
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    var suggestion = screen.getByTestId('suggestion');
    userEvent.type(input, 'FETTUCCINE');
    userEvent.tab();
    userEvent.clear(input);
    expect(input).toHaveValue('');
    userEvent.type(input, 'fett');
    expect(suggestion).toHaveTextContent('');
  });
  it('uses right arrow key to complete input with matching suggestion', function () {
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput"
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    userEvent.type(input, 'Linguine');
    userEvent.tab();
    userEvent.clear(input);
    expect(input).toHaveValue('');
    userEvent.type(input, 'Ling{arrowright}');
    expect(input).toHaveValue('Linguine');
  });
  it('updates onChange callback when right arrow key changes input', function () {
    var onChangeCallback = jest.fn();
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput",
      onChange: onChangeCallback
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    userEvent.type(input, 'Gnocchi'); // calls onchange 7x -> length of string

    userEvent.tab();
    userEvent.clear(input); // calls onchange once -> 1 + 7  = 8

    userEvent.type(input, 'G{arrowright}'); // calls onchange 2x -> G and arrow right key -> 2 + 8 = 10

    expect(onChangeCallback).toHaveBeenCalledTimes(10);
  });
  it('does not fill empty suggestion to input', function () {
    render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
      "aria-label": "myInput"
    }));
    var input = screen.getByRole('textbox', {
      name: 'myInput'
    });
    var suggestion = screen.getByTestId('suggestion');
    userEvent.type(input, 'Orzo{arrowright}');
    expect(input).toHaveValue('Orzo');
    expect(suggestion).toHaveTextContent('');
  });
});
