function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/

/* eslint-env node */

/* eslint-disable flowtype/require-valid-file-annotation */
var scenarios = require('./examples-list');

var _require = require('../../e2e/helpers'),
    getPuppeteerUrl = _require.getPuppeteerUrl;

var suite = 'Select Test Suite';
var selectors = {
  selectInput: '[role="combobox"]',
  selectDropDown: '[role="listbox"]',
  dropDownOption: '[role="option"]',
  selectedList: '[role="list"]',
  searchType: '[aria-autocomplete="list"]',
  expandedDropDown: '[aria-expanded="true"]'
};
describe(suite, function () {
  it('opens dropdown menu when click on select input',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee() {
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.SELECT
            }));

          case 2:
            _context.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context.next = 8;
            return page.waitFor(selectors.selectDropDown);

          case 8:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  })));
  it('opened dropdown can be closed with ESC',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee2() {
    return regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _context2.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.SELECT
            }));

          case 2:
            _context2.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context2.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context2.next = 8;
            return page.waitFor(selectors.selectDropDown);

          case 8:
            _context2.next = 10;
            return page.keyboard.press('Escape');

          case 10:
            _context2.next = 12;
            return page.waitFor(selectors.selectDropDown, {
              hidden: true
            });

          case 12:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, this);
  })));
  it('selects option when clicked in dropdown',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee3() {
    var selectedValue;
    return regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _context3.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.SINGLE_SELECT_SEARCH
            }));

          case 2:
            _context3.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context3.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context3.next = 8;
            return page.waitFor(selectors.selectDropDown);

          case 8:
            _context3.next = 10;
            return page.click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child"));

          case 10:
            _context3.next = 12;
            return page.waitFor(selectors.selectDropDown, {
              hidden: true
            });

          case 12:
            _context3.next = 14;
            return page.$eval(selectors.selectedList, function (select) {
              return select.textContent;
            });

          case 14:
            selectedValue = _context3.sent;
            expect(selectedValue).toBe('AliceBlue');

          case 16:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3, this);
  })));
  it('does not close dropdown after multiple selections were made',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee4() {
    return regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            _context4.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.MULTI_SELECT
            }));

          case 2:
            _context4.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context4.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context4.next = 8;
            return page.waitFor(selectors.selectDropDown);

          case 8:
            _context4.next = 10;
            return page.click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child"));

          case 10:
            _context4.next = 12;
            return page.click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(3)"));

          case 12:
            _context4.next = 14;
            return page.waitFor(selectors.selectDropDown);

          case 14:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4, this);
  })));
  it('doesnt allow to click and select disabled options',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee5() {
    var selectedValue;
    return regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            _context5.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.SINGLE_SELECT_SEARCH
            }));

          case 2:
            _context5.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context5.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context5.next = 8;
            return page.waitFor(selectors.selectDropDown);

          case 8:
            _context5.next = 10;
            return page.click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(2)"));

          case 10:
            _context5.next = 12;
            return page.waitFor(selectors.selectDropDown);

          case 12:
            _context5.next = 14;
            return page.$eval(selectors.selectedList, function (select) {
              return select.textContent;
            });

          case 14:
            selectedValue = _context5.sent;
            expect(selectedValue).toBe('Start searching');

          case 16:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5, this);
  })));
  it('selects options when search input successful with results',
  /*#__PURE__*/
  _asyncToGenerator(
  /*#__PURE__*/
  regeneratorRuntime.mark(function _callee6() {
    var selectedValue;
    return regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            _context6.next = 2;
            return page.goto(getPuppeteerUrl({
              suite: suite,
              test: scenarios.MULTI_SELECT_SEARCH
            }));

          case 2:
            _context6.next = 4;
            return page.waitFor(selectors.selectInput);

          case 4:
            _context6.next = 6;
            return page.click(selectors.selectInput);

          case 6:
            _context6.next = 8;
            return page.type(selectors.selectInput, 'dark');

          case 8:
            _context6.next = 10;
            return page.waitFor(selectors.selectDropDown);

          case 10:
            _context6.next = 12;
            return page.waitFor("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(2)"));

          case 12:
            _context6.next = 14;
            return page.click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child"));

          case 14:
            _context6.next = 16;
            return page.$eval(selectors.selectedList, function (select) {
              return select.textContent;
            });

          case 16:
            selectedValue = _context6.sent;
            expect(selectedValue).toBe('DarkBlue');

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