import { _ as _asyncToGenerator, r as regenerator } from '../index-qSfOyGhk.js';
import React__default from 'react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import AutosuggestInput from './index.js';
import '../typeof-CgC7Bq6K.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 '../_commonjsHelpers-_1FafXWI.js';
import '../use-forwardedref/index.js';
import '../use-localstorage/index.js';

describe("AutosuggestInput", function () {
  it("suggests values that have been previously entered", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
    var input, suggestion;
    return regenerator.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput"
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            suggestion = screen.getByTestId("suggestion");
            _context.next = 5;
            return act(function () {
              return userEvent.type(input, "Spaghetti");
            });

          case 5:
            _context.next = 7;
            return act(function () {
              return userEvent.tab();
            });

          case 7:
            _context.next = 9;
            return act(function () {
              return userEvent.clear(input);
            });

          case 9:
            expect(input).toHaveValue("");
            _context.next = 12;
            return act(function () {
              return userEvent.type(input, "Spag");
            });

          case 12:
            expect(suggestion).toHaveTextContent("Spaghetti");

          case 13:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it("shows no suggestion when input matches no stored suggestions", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
    var input, suggestion;
    return regenerator.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput"
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            suggestion = screen.getByTestId("suggestion");
            _context2.next = 5;
            return act(function () {
              return userEvent.type(input, "Lasagna");
            });

          case 5:
            expect(suggestion).toHaveTextContent("");

          case 6:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  it("uses case sensitive suggestions", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
    var input, suggestion;
    return regenerator.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput"
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            suggestion = screen.getByTestId("suggestion");
            _context3.next = 5;
            return act(function () {
              return userEvent.type(input, "FETTUCCINE");
            });

          case 5:
            _context3.next = 7;
            return act(function () {
              return userEvent.tab();
            });

          case 7:
            _context3.next = 9;
            return act(function () {
              return userEvent.clear(input);
            });

          case 9:
            expect(input).toHaveValue("");
            _context3.next = 12;
            return act(function () {
              return userEvent.type(input, "fett");
            });

          case 12:
            expect(suggestion).toHaveTextContent("");

          case 13:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  })));
  it("uses right arrow key to complete input with matching suggestion", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
    var input;
    return regenerator.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput"
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            _context4.next = 4;
            return act(function () {
              return userEvent.type(input, "Linguine");
            });

          case 4:
            _context4.next = 6;
            return act(function () {
              return userEvent.tab();
            });

          case 6:
            _context4.next = 8;
            return act(function () {
              return userEvent.clear(input);
            });

          case 8:
            expect(input).toHaveValue("");
            _context4.next = 11;
            return act(function () {
              return userEvent.type(input, "Ling{arrowright}");
            });

          case 11:
            expect(input).toHaveValue("Linguine");

          case 12:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  })));
  it("updates onChange callback when right arrow key changes input", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
    var onChangeCallback, input;
    return regenerator.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            onChangeCallback = jest.fn();
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput",
              onChange: onChangeCallback
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            _context5.next = 5;
            return act(function () {
              return userEvent.type(input, "Gnocchi");
            });

          case 5:
            _context5.next = 7;
            return act(function () {
              return userEvent.tab();
            });

          case 7:
            _context5.next = 9;
            return act(function () {
              return userEvent.clear(input);
            });

          case 9:
            _context5.next = 11;
            return act(function () {
              return userEvent.type(input, "G{arrowright}");
            });

          case 11:
            // calls onchange 2x -> G and arrow right key -> 2 + 8 = 10
            expect(onChangeCallback).toHaveBeenCalledTimes(10);

          case 12:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
  it("does not fill empty suggestion to input", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
    var input, suggestion;
    return regenerator.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutosuggestInput, {
              "aria-label": "myInput"
            }));
            input = screen.getByRole("textbox", {
              name: "myInput"
            });
            suggestion = screen.getByTestId("suggestion");
            _context6.next = 5;
            return act(function () {
              return userEvent.type(input, "Orzo{arrowright}");
            });

          case 5:
            expect(input).toHaveValue("Orzo");
            expect(suggestion).toHaveTextContent("");

          case 7:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  })));
});
