UNPKG

wix-style-react

Version:
53 lines (45 loc) 2.05 kB
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } 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; var _inputWithOptionsDriv = inputWithOptionsDriverFactory({ element: element }), driver = _inputWithOptionsDriv.driver, inputDriver = _inputWithOptionsDriv.inputDriver, dropdownLayoutDriver = _inputWithOptionsDriv.dropdownLayoutDriver; var inputWrapper = driver.inputWrapper().childNodes[0]; var tags = [].concat(_toConsumableArray(inputWrapper.querySelectorAll('[data-hook="tag"]'))); var multiSelectDriver = Object.assign(driver, { getMaxHeight: function getMaxHeight() { return inputWrapper.style.maxHeight; }, clickOnInputWrapper: function clickOnInputWrapper() { return ReactTestUtils.Simulate.click(inputWrapper); }, inputWrapperHasFocus: function inputWrapperHasFocus() { return inputWrapper.classList.contains('hasFocus'); }, inputWrapperHasError: function inputWrapperHasError() { return inputWrapper.classList.contains('error'); }, numberOfTags: function numberOfTags() { return tags.length; }, getTagLabelAt: function getTagLabelAt(index) { return tags[index].textContent; }, pressCommaKey: function pressCommaKey() { return inputDriver.keyDown(','); }, 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;