UNPKG

wix-style-react

Version:
66 lines 3.55 kB
import { getElement, baseUniDriverFactory, } from '../test-utils/utils/unidriver'; import { dataTablePrivateUniDriverFactory } from './DataTable/DataTable.private.uni.driver'; import { checkboxUniDriverFactory } from '../Checkbox/Checkbox.uni.driver'; export const tableUniDriverFactory = (base, body) => { const dataTableDriver = dataTablePrivateUniDriverFactory(base); const getRowCheckbox = async (index) => { const row = await dataTableDriver.getRow(index); const cell = await row.$('[data-hook="bulk-selection-cell"]'); return cell.$('[data-hook="row-select"]'); }; const getRowCheckboxDriver = async (index) => checkboxUniDriverFactory(await getRowCheckbox(index), body); const getBulkSelectionCheckboxDriver = async () => { const cell = await dataTableDriver.getHeaderCellByDataHook('bulk-selection-cell'); return checkboxUniDriverFactory(await cell.$('[data-hook="table-select"]')); }; const isBulkSelectionChecked = async () => { const checkboxDriver = await getBulkSelectionCheckboxDriver(); return ((await checkboxDriver.isChecked()) && !(await checkboxDriver.isIndeterminate())); }; const isBulkSelectionIndeterminate = async () => { const checkboxDriver = await getBulkSelectionCheckboxDriver(); return (!(await checkboxDriver.isChecked()) && (await checkboxDriver.isIndeterminate())); }; const isBulkSelectionUnchecked = async () => { const checkboxDriver = await getBulkSelectionCheckboxDriver(); return (!(await checkboxDriver.isChecked()) && !(await checkboxDriver.isIndeterminate())); }; return { ...baseUniDriverFactory(base), ...dataTableDriver, /** Get driver of row selection checkbox by row index */ getRowCheckboxDriver, /** Get driver of row bulk-selection checkbox */ getBulkSelectionCheckboxDriver, /** Whether bulk selection checkbox is disabled */ isBulkSelectionDisabled: async () => (await getBulkSelectionCheckboxDriver()).isDisabled(), /** Whether specific row selection checkbox is disabled */ isRowSelectionDisabled: async (index) => (await getRowCheckboxDriver(index)).isDisabled(), /** Click the row selection checkbox */ clickRowCheckbox: async (index) => (await getRowCheckbox(index)).click(), /** Click the bulk-selection checkbox */ clickBulkSelectionCheckbox: async () => (await getBulkSelectionCheckboxDriver()).click(), /** Is row selected by index */ isRowSelected: async (index) => (await getRowCheckboxDriver(index)).isChecked(), getBulkSelectionState: async () => { if (await isBulkSelectionChecked()) { return 'ALL'; } if (await isBulkSelectionIndeterminate()) { return 'SOME'; } if (await isBulkSelectionUnchecked()) { return 'NONE'; } }, /** Get title-bar (column titles) */ getTitlebar: () => getElement(base.$('[data-hook="table-title-bar"]')), getCellTextValue: async (row = 0, column = 0) => (await dataTableDriver.getCell(row, column))._prop('textContent'), isSelectionTooltipEnabled: async (index) => (await getRowCheckboxDriver(index)).isTooltipEnabled(), getSelectionTooltipContent: async (index) => (await getRowCheckboxDriver(index)).getTooltipContent(), }; }; //# sourceMappingURL=Table.uni.driver.js.map