UNPKG

wix-style-react

Version:
527 lines (433 loc) • 17.2 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } import _regeneratorRuntime from "@babel/runtime/regenerator"; import { baseUniDriverFactory } from 'wix-ui-test-utils/base-driver'; import { getElement } from '../../test/utils/unidriver'; import { dataTablePrivateUniDriverFactory } from './DataTable/DataTable.private.uni.driver'; import { checkboxUniDriverFactory } from '../Checkbox/Checkbox.uni.driver'; export var tableUniDriverFactory = function tableUniDriverFactory(base, body) { var dataTableDriver = dataTablePrivateUniDriverFactory(base); var getRowCheckbox = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(index) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return dataTableDriver.getCell(index, 0); case 2: return _context.abrupt("return", _context.sent.$('[data-hook="row-select"]')); case 3: case "end": return _context.stop(); } } }, _callee); })); return function getRowCheckbox(_x) { return _ref.apply(this, arguments); }; }(); var getRowCheckboxDriver = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index) { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.t0 = checkboxUniDriverFactory; _context2.next = 3; return getRowCheckbox(index); case 3: _context2.t1 = _context2.sent; _context2.t2 = body; return _context2.abrupt("return", (0, _context2.t0)(_context2.t1, _context2.t2)); case 6: case "end": return _context2.stop(); } } }, _callee2); })); return function getRowCheckboxDriver(_x2) { return _ref2.apply(this, arguments); }; }(); var getBulkSelectionCheckboxDriver = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var cell; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return dataTableDriver.getHeaderCell(0); case 2: cell = _context3.sent; _context3.t0 = checkboxUniDriverFactory; _context3.next = 6; return cell.$('[data-hook="table-select"]'); case 6: _context3.t1 = _context3.sent; return _context3.abrupt("return", (0, _context3.t0)(_context3.t1)); case 8: case "end": return _context3.stop(); } } }, _callee3); })); return function getBulkSelectionCheckboxDriver() { return _ref3.apply(this, arguments); }; }(); var isBulkSelectionChecked = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var checkboxDriver; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return getBulkSelectionCheckboxDriver(); case 2: checkboxDriver = _context4.sent; _context4.next = 5; return checkboxDriver.isChecked(); case 5: _context4.t0 = _context4.sent; if (!_context4.t0) { _context4.next = 10; break; } _context4.next = 9; return checkboxDriver.isIndeterminate(); case 9: _context4.t0 = !_context4.sent; case 10: return _context4.abrupt("return", _context4.t0); case 11: case "end": return _context4.stop(); } } }, _callee4); })); return function isBulkSelectionChecked() { return _ref4.apply(this, arguments); }; }(); var isBulkSelectionIndeterminate = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var checkboxDriver; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return getBulkSelectionCheckboxDriver(); case 2: checkboxDriver = _context5.sent; _context5.next = 5; return checkboxDriver.isChecked(); case 5: _context5.t0 = !_context5.sent; if (!_context5.t0) { _context5.next = 10; break; } _context5.next = 9; return checkboxDriver.isIndeterminate(); case 9: _context5.t0 = _context5.sent; case 10: return _context5.abrupt("return", _context5.t0); case 11: case "end": return _context5.stop(); } } }, _callee5); })); return function isBulkSelectionIndeterminate() { return _ref5.apply(this, arguments); }; }(); var isBulkSelectionUnchecked = /*#__PURE__*/function () { var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { var checkboxDriver; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return getBulkSelectionCheckboxDriver(); case 2: checkboxDriver = _context6.sent; _context6.next = 5; return checkboxDriver.isChecked(); case 5: _context6.t0 = !_context6.sent; if (!_context6.t0) { _context6.next = 10; break; } _context6.next = 9; return checkboxDriver.isIndeterminate(); case 9: _context6.t0 = !_context6.sent; case 10: return _context6.abrupt("return", _context6.t0); case 11: case "end": return _context6.stop(); } } }, _callee6); })); return function isBulkSelectionUnchecked() { return _ref6.apply(this, arguments); }; }(); return _objectSpread(_objectSpread(_objectSpread({}, baseUniDriverFactory(base)), dataTableDriver), {}, { /** Get driver of row selection checkbox by row index */ getRowCheckboxDriver: getRowCheckboxDriver, /** Get driver of row bulk-selection checkbox */ getBulkSelectionCheckboxDriver: getBulkSelectionCheckboxDriver, /** Whether bulk selection checkbox is disabled */ isBulkSelectionDisabled: function () { var _isBulkSelectionDisabled = _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 getBulkSelectionCheckboxDriver(); case 2: return _context7.abrupt("return", _context7.sent.isDisabled()); case 3: case "end": return _context7.stop(); } } }, _callee7); })); function isBulkSelectionDisabled() { return _isBulkSelectionDisabled.apply(this, arguments); } return isBulkSelectionDisabled; }(), /** Whether specific row selection checkbox is disabled */ isRowSelectionDisabled: function () { var _isRowSelectionDisabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(index) { return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return getRowCheckboxDriver(index); case 2: return _context8.abrupt("return", _context8.sent.isDisabled()); case 3: case "end": return _context8.stop(); } } }, _callee8); })); function isRowSelectionDisabled(_x3) { return _isRowSelectionDisabled.apply(this, arguments); } return isRowSelectionDisabled; }(), /** Click the row selection checkbox */ clickRowCheckbox: function () { var _clickRowCheckbox = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(index) { return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return getRowCheckbox(index); case 2: return _context9.abrupt("return", _context9.sent.click()); case 3: case "end": return _context9.stop(); } } }, _callee9); })); function clickRowCheckbox(_x4) { return _clickRowCheckbox.apply(this, arguments); } return clickRowCheckbox; }(), /** Click the bulk-selection checkbox */ clickBulkSelectionCheckbox: function () { var _clickBulkSelectionCheckbox = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() { return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return getBulkSelectionCheckboxDriver(); case 2: return _context10.abrupt("return", _context10.sent.click()); case 3: case "end": return _context10.stop(); } } }, _callee10); })); function clickBulkSelectionCheckbox() { return _clickBulkSelectionCheckbox.apply(this, arguments); } return clickBulkSelectionCheckbox; }(), /** Is row selected by index */ isRowSelected: function () { var _isRowSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(index) { return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return getRowCheckboxDriver(index); case 2: return _context11.abrupt("return", _context11.sent.isChecked()); case 3: case "end": return _context11.stop(); } } }, _callee11); })); function isRowSelected(_x5) { return _isRowSelected.apply(this, arguments); } return isRowSelected; }(), getBulkSelectionState: function () { var _getBulkSelectionState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() { return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: _context12.next = 2; return isBulkSelectionChecked(); case 2: if (!_context12.sent) { _context12.next = 4; break; } return _context12.abrupt("return", 'ALL'); case 4: _context12.next = 6; return isBulkSelectionIndeterminate(); case 6: if (!_context12.sent) { _context12.next = 8; break; } return _context12.abrupt("return", 'SOME'); case 8: _context12.next = 10; return isBulkSelectionUnchecked(); case 10: if (!_context12.sent) { _context12.next = 12; break; } return _context12.abrupt("return", 'NONE'); case 12: case "end": return _context12.stop(); } } }, _callee12); })); function getBulkSelectionState() { return _getBulkSelectionState.apply(this, arguments); } return getBulkSelectionState; }(), /** Get title-bar (column titles) */ getTitlebar: function getTitlebar() { return getElement(base.$('[data-hook="table-title-bar"]')); }, getCellTextValue: function () { var _getCellTextValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() { var row, column, _args13 = arguments; return _regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: row = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : 0; column = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : 0; _context13.next = 4; return dataTableDriver.getCell(row, column); case 4: return _context13.abrupt("return", _context13.sent._prop('textContent')); case 5: case "end": return _context13.stop(); } } }, _callee13); })); function getCellTextValue() { return _getCellTextValue.apply(this, arguments); } return getCellTextValue; }(), isSelectionTooltipEnabled: function () { var _isSelectionTooltipEnabled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(index) { return _regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _context14.next = 2; return getRowCheckboxDriver(index); case 2: return _context14.abrupt("return", _context14.sent.isTooltipEnabled()); case 3: case "end": return _context14.stop(); } } }, _callee14); })); function isSelectionTooltipEnabled(_x6) { return _isSelectionTooltipEnabled.apply(this, arguments); } return isSelectionTooltipEnabled; }(), getSelectionTooltipContent: function () { var _getSelectionTooltipContent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(index) { return _regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: _context15.next = 2; return getRowCheckboxDriver(index); case 2: return _context15.abrupt("return", _context15.sent.getTooltipContent()); case 3: case "end": return _context15.stop(); } } }, _callee15); })); function getSelectionTooltipContent(_x7) { return _getSelectionTooltipContent.apply(this, arguments); } return getSelectionTooltipContent; }() }); };