wix-style-react
Version:
wix-style-react
132 lines (105 loc) • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.dropdownLayoutDriverFactory = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
// TODO: remove when implementation with UniDriver becomes possible
var _baseDriver = require('wix-ui-test-utils/base-driver');
var _testUtils = require('react-dom/test-utils');
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var dropdownLayoutDriverFactory = exports.dropdownLayoutDriverFactory = function dropdownLayoutDriverFactory(base) {
var byDataHook = function byDataHook(dataHook) {
return base.$('[data-hook="' + dataHook + '"]');
};
var getOptions = function getOptions() {
return byDataHook('dropdown-layout-options').$$('div');
};
var getOptionAt = function getOptionAt(index) {
return getOptions().get(index);
};
return _extends({}, (0, _baseDriver.baseUniDriverFactory)(base), {
optionsLength: function optionsLength() {
return getOptions().count();
},
isOptionHovered: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(index) {
var option;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return getOptionAt(index);
case 2:
option = _context.sent;
_context.next = 5;
return option.hasClass('hovered');
case 5:
return _context.abrupt('return', _context.sent);
case 6:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function isOptionHovered(_x) {
return _ref.apply(this, arguments);
};
}(),
isOptionSelected: function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(index) {
var option;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return getOptionAt(index);
case 2:
option = _context2.sent;
_context2.next = 5;
return option.hasClass('selected');
case 5:
return _context2.abrupt('return', _context2.sent);
case 6:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function isOptionSelected(_x2) {
return _ref2.apply(this, arguments);
};
}(),
clickAtOption: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(index) {
var option;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
if (!(base.type === 'react')) {
_context3.next = 5;
break;
}
_context3.next = 3;
return getOptionAt(index).getNative();
case 3:
option = _context3.sent;
_testUtils.Simulate.mouseDown(option);
case 5:
case 'end':
return _context3.stop();
}
}
}, _callee3, undefined);
}));
return function clickAtOption(_x3) {
return _ref3.apply(this, arguments);
};
}()
});
};