UNPKG

wix-style-react

Version:
92 lines (74 loc) 3.03 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _testUtils = _interopRequireDefault(require("react-dom/test-utils")); var _InputWithOptions = _interopRequireDefault(require("../InputWithOptions/InputWithOptions.driver")); var _Tag = _interopRequireDefault(require("../Tag/Tag.driver")); var multiSelectDriverFactory = function multiSelectDriverFactory(_ref) { var element = _ref.element, wrapper = _ref.wrapper, eventTrigger = _ref.eventTrigger; var _inputWithOptionsDriv = (0, _InputWithOptions["default"])({ element: element, wrapper: wrapper, eventTrigger: eventTrigger }), driver = _inputWithOptionsDriv.driver, inputDriver = _inputWithOptionsDriv.inputDriver, dropdownLayoutDriver = _inputWithOptionsDriv.dropdownLayoutDriver; var inputWrapper = driver.inputWrapper(); var tags = (0, _toConsumableArray2["default"])(inputWrapper.querySelectorAll('[data-hook="tag"]')); var multiSelectDriver = Object.assign(driver, { /** returns the max height of the component */ getMaxHeight: function getMaxHeight() { return inputWrapper.style.maxHeight; }, /** click on the input element wrapper */ clickOnInputWrapper: function clickOnInputWrapper() { return _testUtils["default"].Simulate.click(inputWrapper); }, /** returns true if the input is focused */ inputWrapperHasFocus: function inputWrapperHasFocus() { return inputDriver.isFocusedStyle(); }, /** returns true if the input is disabled */ inputWrapperIsDisabled: function inputWrapperIsDisabled() { return inputWrapper.querySelector('[data-hook="wsr-custom-input"]').hasAttribute('disabled'); }, /** returns the number of tags selected in the input */ numberOfTags: function numberOfTags() { return tags.length; }, /** returns true if a custom suffix exists */ customSuffixExists: function customSuffixExists() { return !!inputWrapper.querySelector('[data-hook="custom-suffix"]'); }, /** returns the label of the tag given it's index */ getTagLabelAt: function getTagLabelAt(index) { return tags[index].textContent; }, /** press the comma key in the input field */ pressCommaKey: function pressCommaKey() { return inputDriver.keyDown(','); }, /** returns the `tagDriver` for the specified tag id */ getTagDriverByTagId: function getTagDriverByTagId(tagId) { return (0, _Tag["default"])({ element: tags.find(function (tag) { return tag.id === tagId; }) }); } }); return { driver: multiSelectDriver, inputDriver: inputDriver, dropdownLayoutDriver: dropdownLayoutDriver }; }; var _default = multiSelectDriverFactory; exports["default"] = _default;