"use strict";

/*
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 */

/* global after */
var scenarios = require('./examples-list');

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

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('The select component', function () {
  after(function (browser, done) {
    browser.end(function () {
      return done();
    });
  }); // TODO(#424)

  it('opens dropdown menu when click on select input', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.SELECT,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).waitForElementPresent(selectors.selectDropDown);
  });
  it('opened dropdown can be closed with ESC', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.SELECT,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).waitForElementPresent(selectors.selectDropDown).keys("\uE00C").waitForElementNotPresent(selectors.selectDropDown);
  });
  it('selects option when clicked in dropdown', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.SINGLE_SELECT_SEARCH,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).waitForElementPresent(selectors.selectDropDown).click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child")).waitForElementNotPresent(selectors.selectDropDown).getText("".concat(selectors.selectedList), function (result) {
      this.assert.equal(result.value, 'AliceBlue');
    });
  });
  it('does not close dropdown after multiple selections were made', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.MULTI_SELECT,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).waitForElementPresent(selectors.selectDropDown).click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child")).click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(3)")).waitForElementPresent(selectors.selectDropDown);
  });
  it('doesnt allow to click and select disabled options', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.SINGLE_SELECT_SEARCH,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).waitForElementPresent(selectors.selectDropDown).click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(2)")).waitForElementPresent(selectors.selectDropDown).getText(selectors.selectedList, function (result) {
      // Placeholder is displayed
      this.assert.equal(result.value, 'Start searching');
    });
  });
  it('selects options when search input successful with results', function (browser) {
    goToUrl({
      suite: suite,
      test: scenarios.MULTI_SELECT_SEARCH,
      browser: browser
    }).waitForElementVisible(selectors.selectInput).click(selectors.selectInput).setValue(selectors.selectInput, 'dark', function () {
      browser.waitForElementPresent(selectors.selectDropDown).waitForElementPresent("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":nth-child(2)")).click("".concat(selectors.selectDropDown, " ").concat(selectors.dropDownOption, ":first-child")).getText("".concat(selectors.selectedList), function (result) {
        this.assert.equal(result.value, 'DarkBlue');
      });
    });
  });
});