wix-style-react
Version:
wix-style-react
246 lines (201 loc) • 8.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.thumbnailDriverFactory = 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; };
var _baseDriver = require('wix-ui-test-utils/base-driver');
var _stylableUniTestkit = require('../../test/utils/stylable-uni-testkit');
var _ThumbnailSt = require('./Thumbnail.st.css');
var _ThumbnailSt2 = _interopRequireDefault(_ThumbnailSt);
var _Text = require('../Text/Text.driver');
var _Text2 = _interopRequireDefault(_Text);
var _vanilla = require('wix-ui-test-utils/vanilla');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 textTestkitFactory = (0, _vanilla.testkitFactoryCreator)(_Text2.default);
var thumbnailDriverFactory = exports.thumbnailDriverFactory = function thumbnailDriverFactory(base) {
var byHook = function byHook(hook) {
return base.$('[data-hook*="' + hook + '"]');
};
var getStyle = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(rule) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return base.attr('style');
case 2:
_context.t0 = new RegExp(rule + ': (.*?);');
return _context.abrupt('return', _context.sent.match(_context.t0)[1]);
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function getStyle(_x) {
return _ref.apply(this, arguments);
};
}();
var titleDriver = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.t0 = textTestkitFactory;
_context2.next = 3;
return byHook('thumbnail-title').getNative();
case 3:
_context2.t1 = _context2.sent;
_context2.t2 = {
wrapper: _context2.t1,
dataHook: 'thumbnail-title'
};
return _context2.abrupt('return', (0, _context2.t0)(_context2.t2));
case 6:
case 'end':
return _context2.stop();
}
}
}, _callee2, undefined);
}));
return function titleDriver() {
return _ref2.apply(this, arguments);
};
}();
return _extends({}, (0, _baseDriver.baseUniDriverFactory)(base), {
/** Get thumbnail title */
getTitle: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return titleDriver();
case 2:
return _context3.abrupt('return', _context3.sent.getText());
case 3:
case 'end':
return _context3.stop();
}
}
}, _callee3, undefined);
}));
return function getTitle() {
return _ref3.apply(this, arguments);
};
}(),
/** Get thumbnail description */
getDescription: function getDescription() {
return byHook('thumbnail-description').text();
},
/** Get selected icon */
getSelectedIcon: function getSelectedIcon() {
return byHook('thumbnail-selected-icon');
},
getBackgroundImage: function getBackgroundImage() {
return byHook('thumbnail-background-image');
},
/** Is Thumbnail selected */
isSelected: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
var stylableState;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _stylableUniTestkit.getStylableState)(base, _ThumbnailSt2.default, 'selected');
case 2:
stylableState = _context4.sent;
return _context4.abrupt('return', stylableState === 'true');
case 4:
case 'end':
return _context4.stop();
}
}
}, _callee4, undefined);
}));
return function isSelected() {
return _ref4.apply(this, arguments);
};
}(),
/** Is Thumbnail disabled */
isDisabled: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
var stylableState;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return (0, _stylableUniTestkit.getStylableState)(base, _ThumbnailSt2.default, 'disabled');
case 2:
stylableState = _context5.sent;
return _context5.abrupt('return', stylableState === 'true');
case 4:
case 'end':
return _context5.stop();
}
}
}, _callee5, undefined);
}));
return function isDisabled() {
return _ref5.apply(this, arguments);
};
}(),
/** Get thumbnail image */
getImage: function getImage() {
return byHook('thumbnail-image');
},
/** Get thumbnail width, if it's set through `width` prop */
getWidth: function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return getStyle('width');
case 2:
return _context6.abrupt('return', _context6.sent);
case 3:
case 'end':
return _context6.stop();
}
}
}, _callee6, undefined);
}));
return function getWidth() {
return _ref6.apply(this, arguments);
};
}(),
/** Get thumbnail height, if it's set through `height` prop */
getHeight: function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return getStyle('height');
case 2:
return _context7.abrupt('return', _context7.sent);
case 3:
case 'end':
return _context7.stop();
}
}
}, _callee7, undefined);
}));
return function getHeight() {
return _ref7.apply(this, arguments);
};
}()
});
};