import { _ as _asyncToGenerator, r as regenerator } from '../../index-qSfOyGhk.js';
import React__default from 'react';
import { render, screen, act, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import AutoComplete from '../autocomplete.js';
import SelectMenu 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 '../../index-CMfVNfTW.js';
import 'react-dom';
import 'prop-types';
import 'classnames';
import '../../icon/assets/icon-map/index.js';
import '../../social-icon/index.js';
import '@fortawesome/react-fontawesome';
import '../../social-icon/icons.js';
import '../../social-icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/free-solid-svg-icons';
import '@fortawesome/free-brands-svg-icons';
import '../../tooltip/index.js';
import '../../auto-id.esm-CjaDlg7r.js';
import '../../utils.esm-BKUEBdyY.js';
import '../../warning-s9zGJbnw.js';
import '../../portal.esm-D9LQ40g_.js';
import '@reach/visually-hidden';
import '../../portal/index.js';
import '../../use-rerender-once/index.js';
import '../../use-force-update/index.js';
import '../../button/button-group.js';
import '../../inject-css-BqVV5N0s.js';
import '../../select-menu-CMlOgi2H.js';
import '../../_commonjsHelpers-_1FafXWI.js';
import '../../label/index.js';

describe("SelectMenu Wrapper", function () {
  it("renders a SelectMenu with a default placeholder 'Select'", function () {
    render( /*#__PURE__*/React__default.createElement(SelectMenu, {
      options: [{
        label: "Option 1",
        value: "option1"
      }, {
        label: "Option 2",
        value: "option2"
      }, {
        label: "Option 3",
        value: "option3"
      }]
    }));
    var trigger = screen.getByRole("combobox");
    expect(trigger).toBeInTheDocument();
    expect(trigger.tagName).toEqual("DIV");
    expect(trigger.getAttribute("role")).toEqual("combobox");
  });
  it("uses type 'autocomplete' when async prop is set", function () {
    render( /*#__PURE__*/React__default.createElement(SelectMenu, {
      async: true,
      options: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
        return regenerator.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                return _context.abrupt("return", [{
                  label: "Option 1",
                  value: "option1"
                }, {
                  label: "Option 2",
                  value: "option2"
                }, {
                  label: "Option 3",
                  value: "option3"
                }]);

              case 1:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }))
    }));
    var trigger = screen.getByRole("combobox");
    expect(trigger).toBeInTheDocument();
    expect(trigger.tagName).toEqual("INPUT");
    expect(trigger.getAttribute("role")).toEqual("combobox");
  });
  it("uses type 'autocomplete' when create prop is set", function () {
    render( /*#__PURE__*/React__default.createElement(SelectMenu, {
      create: true,
      options: [{
        label: "Option 1",
        value: "option1"
      }, {
        label: "Option 2",
        value: "option2"
      }, {
        label: "Option 3",
        value: "option3"
      }]
    }));
    var trigger = screen.getByRole("combobox");
    expect(trigger).toBeInTheDocument();
    expect(trigger.tagName).toEqual("INPUT");
  });
  it("applies aria-label to the reference when passed", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
    var trigger, listbox;
    return regenerator.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(SelectMenu, {
              "aria-label": "Select an option",
              options: [{
                label: "Option 1",
                value: "option1"
              }, {
                label: "Option 2",
                value: "option2"
              }, {
                label: "Option 3",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context2.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            listbox = screen.getByRole("listbox");
            expect(trigger).toHaveAttribute("aria-label", "Select an option");
            expect(listbox).not.toHaveAttribute("aria-label", "Select an option");

          case 7:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  it("applies aria-labelledby to the reference when passed", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
    var trigger, listbox;
    return regenerator.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(SelectMenu, {
              "aria-labelledby": "my-external-id",
              options: [{
                label: "Option 1",
                value: "option1"
              }, {
                label: "Option 2",
                value: "option2"
              }, {
                label: "Option 3",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context3.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            listbox = screen.getByRole("listbox");
            expect(trigger).toHaveAttribute("aria-labelledby", "my-external-id");
            expect(listbox).not.toHaveAttribute("aria-labelledby", "my-external-id");

          case 7:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  })));
});
describe("Autocomplete", function () {
  it("renders a trigger with a default placeholder 'Select'", function () {
    render( /*#__PURE__*/React__default.createElement(AutoComplete, {
      options: [{
        label: "Option 1",
        value: "option1"
      }, {
        label: "Option 2",
        value: "option2"
      }, {
        label: "Option 3",
        value: "option3"
      }]
    }));
    var trigger = screen.getByRole("combobox");
    expect(trigger).toBeInTheDocument();
    expect(trigger.placeholder).toEqual("Select");
  });
  it("allows to set a custom placeholder", function () {
    render( /*#__PURE__*/React__default.createElement(AutoComplete, {
      options: [{
        label: "Option 1",
        value: "option1"
      }, {
        label: "Option 2",
        value: "option2"
      }, {
        label: "Option 3",
        value: "option3"
      }],
      placeholder: "Custom placeholder"
    }));
    var trigger = screen.getByRole("combobox");
    expect(trigger).toBeInTheDocument();
    expect(trigger.placeholder).toEqual("Custom placeholder");
  });
  it("renders a list of options", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
    var trigger, options;
    return regenerator.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "Option 1",
                value: "option1"
              }, {
                label: "Option 2",
                value: "option2"
              }, {
                label: "Option 3",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context4.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(trigger).toBeInTheDocument();
            expect(options).toHaveLength(3);

          case 7:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  })));
  it("throws an error when 'async' is true and options is not a function", function () {
    jest.spyOn(console, "error");
    console.error.mockImplementation(function () {});
    expect(function () {
      render( /*#__PURE__*/React__default.createElement(AutoComplete, {
        async: true,
        type: "autocomplete",
        options: [{
          label: "Option 1",
          value: "option1"
        }, {
          label: "Option 2",
          value: "option2"
        }, {
          label: "Option 3",
          value: "option3"
        }]
      }));
    }).toThrow("Async autocomplete requires options to be a function");
    console.error.mockRestore();
  });
  it("selects the option that matches all the input characters", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
    var trigger, option, selectedOption;
    return regenerator.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "Option 1",
                value: "option1"
              }, {
                label: "Option 2",
                value: "option2"
              }, {
                label: "Option 3",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context5.next = 4;
            return act(function () {
              return userEvent.type(trigger, "Option 1");
            });

          case 4:
            option = screen.getByRole("option", {
              name: "Option 2"
            });
            selectedOption = screen.getByRole("option", {
              name: "Option 1"
            });
            expect(option.getAttribute("aria-selected")).toEqual("false");
            expect(selectedOption.getAttribute("aria-selected")).toEqual("true");

          case 8:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
  it("filters the options based on the input value", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
    var trigger, options;
    return regenerator.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context6.next = 4;
            return act(function () {
              return userEvent.type(trigger, "subscriber");
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(2);
            expect(options[0].textContent).toEqual("All subscribers");
            expect(options[1].textContent).toEqual("Cold subscribers");

          case 8:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  })));
  it("shows all options when the input value is empty", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
    var trigger, options;
    return regenerator.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context7.next = 4;
            return act(function () {
              return userEvent.type(trigger, "subscriber");
            });

          case 4:
            _context7.next = 6;
            return act(function () {
              return userEvent.clear(trigger);
            });

          case 6:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(3);

          case 8:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  })));
  it("shows all options when the input value matches all characters of an option", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
    var trigger, options;
    return regenerator.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context8.next = 4;
            return act(function () {
              return userEvent.type(trigger, "All subscribers");
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(3);
            expect(options[0].getAttribute("aria-selected")).toEqual("true");

          case 7:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  })));
  it("shows 'No result found' when there are no results", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9() {
    var trigger, options;
    return regenerator.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context9.next = 4;
            return act(function () {
              return userEvent.type(trigger, "subscriberz");
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(1);
            expect(options[0].textContent).toEqual("No result found");

          case 7:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  })));
  it("selects match when 'Enter' key is pressed", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10() {
    var trigger, options;
    return regenerator.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context10.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(3);
            _context10.next = 8;
            return act(function () {
              return userEvent.type(trigger, "Cold");
            });

          case 8:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(1);
            _context10.next = 12;
            return act(function () {
              return userEvent.keyboard("{Enter}");
            });

          case 12:
            options = screen.queryAllByRole("option");
            expect(options).toHaveLength(0);
            expect(trigger).toHaveValue("Cold subscribers");

          case 15:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  })));
  it("does not load async options when the input value is less than 2 characters", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11() {
    var options, trigger;
    return regenerator.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            options = jest.fn(function () {
              return new Promise(function (resolve) {
                resolve([{
                  label: "All subscribers",
                  value: "option1"
                }, {
                  label: "Subscribed for a year",
                  value: "option2"
                }, {
                  label: "Cold subscribers",
                  value: "option3"
                }]);
              });
            });
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              async: true,
              options: options
            }));
            trigger = screen.getByRole("combobox");
            _context11.next = 5;
            return act(function () {
              return userEvent.type(trigger, "C", {
                delay: 2
              });
            });

          case 5:
            _context11.next = 7;
            return waitFor(function () {
              expect(options).toHaveBeenCalledTimes(0);
            });

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

          case 9:
            _context11.next = 11;
            return act(function () {
              return userEvent.type(trigger, "Co", {
                delay: 2
              });
            });

          case 11:
            _context11.next = 13;
            return waitFor(function () {
              expect(options).toHaveBeenCalledTimes(1);
            });

          case 13:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  })));
  it("calls onChange callback when an option is selected", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee12() {
    var onChange, trigger, options;
    return regenerator.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            onChange = jest.fn();
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              name: "subscribers",
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }],
              onChange: onChange
            }));
            trigger = screen.getByRole("combobox");
            _context12.next = 5;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 5:
            options = screen.getAllByRole("option");
            _context12.next = 8;
            return act(function () {
              return userEvent.click(options[1]);
            });

          case 8:
            expect(onChange).toHaveBeenCalledTimes(1);
            expect(onChange).toHaveBeenCalledWith({
              target: {
                label: "Subscribed for a year",
                value: "option2",
                name: "subscribers"
              }
            });

          case 10:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  })));
  it("calls onChange callback when an option is selected with keyboard", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee13() {
    var onChange, trigger;
    return regenerator.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            onChange = jest.fn();
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              name: "subscribers",
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }],
              onChange: onChange
            }));
            trigger = screen.getByRole("combobox");
            _context13.next = 5;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 5:
            _context13.next = 7;
            return act(function () {
              return userEvent.keyboard("{ArrowDown}{ArrowDown}");
            });

          case 7:
            _context13.next = 9;
            return act(function () {
              return userEvent.keyboard("{Enter}");
            });

          case 9:
            expect(onChange).toHaveBeenCalledTimes(1);
            expect(onChange).toHaveBeenCalledWith({
              target: {
                label: "Subscribed for a year",
                value: "option2",
                name: "subscribers"
              }
            });

          case 11:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  })));
  it("accepts a prefilled value", function () {
    render( /*#__PURE__*/React__default.createElement(AutoComplete, {
      name: "testAutoComplete",
      options: [],
      onChange: function onChange() {},
      value: {
        value: "internalValue",
        label: "User-friendly label"
      }
    }));
    var element = screen.getByRole("combobox");
    expect(element.value).toEqual("User-friendly label");
  });
  it("renders an option's component over label when provided", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee14() {
    var trigger, options;
    return regenerator.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "Blowfish",
                value: "blowfish",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC21 Blowfish")
              }, {
                label: "Fried Shrimp",
                value: "fried-shrimp",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83C\uDF64 Fried Shrimp")
              }, {
                label: "Octopus",
                value: "octopus",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC19 Octopus")
              }, {
                label: "Squid",
                value: "squid",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83E\uDD91 Squid")
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context14.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(4);
            expect(options[0].textContent).toEqual("🐡 Blowfish");

          case 7:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  })));
  it("uses the option label over component in the input value", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee15() {
    var trigger, options;
    return regenerator.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                label: "Blowfish",
                value: "blowfish",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC21 Blowfish")
              }, {
                label: "Fried Shrimp",
                value: "fried-shrimp",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83C\uDF64 Fried Shrimp")
              }, {
                label: "Octopus",
                value: "octopus",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC19 Octopus")
              }, {
                label: "Squid",
                value: "squid",
                component: /*#__PURE__*/React__default.createElement("div", null, "\uD83E\uDD91 Squid")
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context15.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(4);
            _context15.next = 8;
            return act(function () {
              return userEvent.click(options[0]);
            });

          case 8:
            expect(trigger).toHaveValue("Blowfish");

          case 9:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  })));
  it("uses text content of an option's JSX label in the input value", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee16() {
    var trigger, options;
    return regenerator.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              options: [{
                value: "blowfish",
                label: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC21 Blowfish")
              }, {
                value: "fried-shrimp",
                label: /*#__PURE__*/React__default.createElement("div", null, "\uD83C\uDF64 Fried Shrimp")
              }, {
                value: "octopus",
                label: /*#__PURE__*/React__default.createElement("div", null, "\uD83D\uDC19 Octopus")
              }, {
                value: "squid",
                label: /*#__PURE__*/React__default.createElement("div", null, "\uD83E\uDD91 Squid")
              }]
            }));
            trigger = screen.getByRole("combobox");
            _context16.next = 4;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 4:
            options = screen.getAllByRole("option");
            expect(options).toHaveLength(4);
            _context16.next = 8;
            return act(function () {
              return userEvent.click(options[0]);
            });

          case 8:
            expect(trigger).toHaveValue("🐡 Blowfish");

          case 9:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  })));
  it("does not allow interaction when disabled", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee17() {
    var onChange, trigger, options;
    return regenerator.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            onChange = jest.fn();
            render( /*#__PURE__*/React__default.createElement(AutoComplete, {
              disabled: true,
              options: [{
                label: "All subscribers",
                value: "option1"
              }, {
                label: "Subscribed for a year",
                value: "option2"
              }, {
                label: "Cold subscribers",
                value: "option3"
              }],
              onChange: onChange
            }));
            trigger = screen.getByRole("combobox");
            expect(trigger).toBeDisabled();
            _context17.next = 6;
            return act(function () {
              return userEvent.click(trigger);
            });

          case 6:
            options = screen.queryAllByRole("option");
            expect(options).toHaveLength(0);
            _context17.next = 10;
            return act(function () {
              return userEvent.type(trigger, "subscriber");
            });

          case 10:
            expect(trigger).toHaveValue("");
            expect(onChange).not.toHaveBeenCalled();

          case 12:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  })));
  describe("create option", function () {
    it("adds a new option when the input value does not match any option", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee18() {
      var onChange, trigger, options, lastOption;
      return regenerator.wrap(function _callee18$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              onChange = jest.fn();
              render( /*#__PURE__*/React__default.createElement(AutoComplete, {
                create: true,
                options: [{
                  label: "All subscribers",
                  value: "option1"
                }, {
                  label: "Subscribed for a year",
                  value: "option2"
                }, {
                  label: "Cold subscribers",
                  value: "option3"
                }],
                onChange: onChange
              }));
              trigger = screen.getByRole("combobox");
              _context18.next = 5;
              return act(function () {
                return userEvent.type(trigger, "New subscriber");
              });

            case 5:
              options = screen.getAllByRole("option");
              expect(options).toHaveLength(1);
              expect(options[0].textContent).toEqual("Create “New subscriber”");
              _context18.next = 10;
              return act(function () {
                return userEvent.click(options[0]);
              });

            case 10:
              expect(onChange).toHaveBeenCalledTimes(1);
              expect(onChange).toHaveBeenCalledWith({
                target: {
                  label: "New subscriber",
                  value: "New subscriber1",
                  created: true,
                  name: undefined
                }
              });
              _context18.next = 14;
              return act(function () {
                return userEvent.click(trigger);
              });

            case 14:
              options = screen.queryAllByRole("option");
              expect(options).toHaveLength(4);
              lastOption = screen.getByRole("option", {
                name: "New subscriber"
              });
              expect(lastOption.getAttribute("aria-selected")).toEqual("true");

            case 18:
            case "end":
              return _context18.stop();
          }
        }
      }, _callee18);
    })));
    it("allows the use of Enter key to create a new option", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee19() {
      var onChange, trigger, options, lastOption;
      return regenerator.wrap(function _callee19$(_context19) {
        while (1) {
          switch (_context19.prev = _context19.next) {
            case 0:
              onChange = jest.fn();
              render( /*#__PURE__*/React__default.createElement(AutoComplete, {
                create: true,
                options: [{
                  label: "All subscribers",
                  value: "option1"
                }, {
                  label: "Subscribed for a year",
                  value: "option2"
                }, {
                  label: "Cold subscribers",
                  value: "option3"
                }],
                onChange: onChange
              }));
              trigger = screen.getByRole("combobox");
              _context19.next = 5;
              return act(function () {
                return userEvent.type(trigger, "New subscriber");
              });

            case 5:
              _context19.next = 7;
              return act(function () {
                return userEvent.keyboard("{Enter}");
              });

            case 7:
              expect(onChange).toHaveBeenCalledTimes(1);
              expect(onChange).toHaveBeenCalledWith({
                target: {
                  label: "New subscriber",
                  value: "New subscriber1",
                  created: true,
                  name: undefined
                }
              });
              _context19.next = 11;
              return act(function () {
                return userEvent.click(trigger);
              });

            case 11:
              options = screen.getAllByRole("option");
              expect(options).toHaveLength(4);
              lastOption = screen.getByRole("option", {
                name: "New subscriber"
              });
              expect(lastOption.getAttribute("aria-selected")).toEqual("true");

            case 15:
            case "end":
              return _context19.stop();
          }
        }
      }, _callee19);
    })));
  });
});
