UNPKG

wix-style-react

Version:
81 lines (67 loc) 2.69 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import ReactTestUtils from 'react-dom/test-utils'; import inputWithOptionsDriverFactory from '../InputWithOptions/InputWithOptions.driver'; import tagDriverFactory from '../Tag/Tag.driver'; var multiSelectDriverFactory = function multiSelectDriverFactory(_ref) { var element = _ref.element, wrapper = _ref.wrapper, eventTrigger = _ref.eventTrigger; var _inputWithOptionsDriv = inputWithOptionsDriverFactory({ element: element, wrapper: wrapper, eventTrigger: eventTrigger }), driver = _inputWithOptionsDriv.driver, inputDriver = _inputWithOptionsDriv.inputDriver, dropdownLayoutDriver = _inputWithOptionsDriv.dropdownLayoutDriver; var inputWrapper = driver.inputWrapper(); var tags = _toConsumableArray(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 ReactTestUtils.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 tagDriverFactory({ element: tags.find(function (tag) { return tag.id === tagId; }) }); } }); return { driver: multiSelectDriver, inputDriver: inputDriver, dropdownLayoutDriver: dropdownLayoutDriver }; }; export default multiSelectDriverFactory;