UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

197 lines • 9.06 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 const dom_1 = require("@awsui/test-utils-core/dom"); const collection_preferences_1 = require("../collection-preferences"); const container_1 = require("../container"); const pagination_1 = require("../pagination"); const property_filter_1 = require("../property-filter"); const text_filter_1 = require("../text-filter"); const styles_selectors_js_1 = require("../../../internal/components/expand-toggle-button/styles.selectors.js"); const styles_selectors_js_2 = require("../../../table/body-cell/styles.selectors.js"); const styles_selectors_js_3 = require("../../../table/header-cell/styles.selectors.js"); const styles_selectors_js_4 = require("../../../table/progressive-loading/styles.selectors.js"); const styles_selectors_js_5 = require("../../../table/resizer/styles.selectors.js"); const styles_selectors_js_6 = require("../../../table/selection/styles.selectors.js"); const styles_selectors_js_7 = require("../../../table/styles.selectors.js"); class TableWrapper extends dom_1.ComponentWrapper { constructor() { super(...arguments); this.containerWrapper = new container_1.default(this.getElement()); } findNativeTable() { return this.find(`.${styles_selectors_js_7.default.wrapper} > .${styles_selectors_js_7.default.table}`); } findActiveTHead() { return this.findByClassName(styles_selectors_js_7.default['thead-active']); } findHeaderSlot() { return this.findByClassName(styles_selectors_js_7.default['header-controls']); } /** * Alias for findHeaderSlot method for compatibility with previous versions * @deprecated */ findHeaderRegion() { return this.findHeaderSlot(); } findFooterSlot() { return this.containerWrapper.findFooter(); } findColumnHeaders() { return this.findActiveTHead().findAll('tr > *'); } /** * Returns the element the user clicks when resizing a column. * * @param columnIndex 1-based index of the column containing the resizer. */ findColumnResizer(columnIndex) { return this.findActiveTHead().find(`th:nth-child(${columnIndex}) .${styles_selectors_js_5.default.resizer}`); } /** * Returns a table cell based on given row and column indices. * * @param rowIndex 1-based index of the row of the cell to select. * @param columnIndex 1-based index of the column of the cell to select. */ findBodyCell(rowIndex, columnIndex) { return this.findNativeTable().find(`tbody tr:nth-child(${rowIndex}) .${styles_selectors_js_2.default['body-cell']}:nth-child(${columnIndex})`); } findRows() { return this.findNativeTable().findAllByClassName(styles_selectors_js_7.default.row); } findSelectedRows() { return this.findAllByClassName(styles_selectors_js_7.default['row-selected']); } /** * Alias for findEmptySlot method for compatibility with previous versions * @deprecated */ findEmptyRegion() { return this.findEmptySlot(); } findEmptySlot() { return this.findByClassName(styles_selectors_js_7.default.empty); } findLoadingText() { return this.findByClassName(styles_selectors_js_7.default.loading); } findColumnSortingArea(colIndex) { return this.findActiveTHead().find(`tr > *:nth-child(${colIndex}) [role=button]`); } /** * Returns the column that is used for ascending sorting. */ findAscSortedColumn() { return this.findNativeTable().findByClassName(styles_selectors_js_3.default['header-cell-ascending']); } /** * Returns the column that is used for descending sorting. */ findDescSortedColumn() { return this.findNativeTable().findByClassName(styles_selectors_js_3.default['header-cell-descending']); } /** * Returns a row selection area for a given index. * * @param rowIndex 1-based index of the row selection area to return. */ findRowSelectionArea(rowIndex) { return this.findNativeTable().find(`tbody tr:nth-child(${rowIndex}) .${styles_selectors_js_6.default.root}`); } findSelectAllTrigger() { return this.findActiveTHead().find(`.${styles_selectors_js_6.default.root}`); } findTextFilter() { return this.findComponent(`.${styles_selectors_js_7.default['tools-filtering']}`, text_filter_1.default); } findPropertyFilter() { return this.findComponent(`.${styles_selectors_js_7.default['tools-filtering']}`, property_filter_1.default); } findFilterSlot() { return this.findComponent(`.${styles_selectors_js_7.default['tools-filtering']}`, dom_1.ElementWrapper); } findCollectionPreferences() { return this.findComponent(`.${styles_selectors_js_7.default['tools-preferences']}`, collection_preferences_1.default); } findPagination() { return this.findComponent(`.${styles_selectors_js_7.default['tools-pagination']}`, pagination_1.default); } /** * Returns the button that activates inline editing for a table cell based on given row and column indices. * * @param rowIndex 1-based index of the row of the cell to select. * @param columnIndex 1-based index of the column of the cell to select. */ findEditCellButton(rowIndex, columnIndex) { var _a, _b; return (_b = (_a = this.findBodyCell(rowIndex, columnIndex)) === null || _a === void 0 ? void 0 : _a.findByClassName(styles_selectors_js_2.default['body-cell-editor'])) !== null && _b !== void 0 ? _b : null; } findEditingCell() { return this.findNativeTable().findByClassName(styles_selectors_js_2.default['body-cell-edit-active']); } _findEditingCellControls() { var _a, _b; return (_b = (_a = this.findEditingCell()) === null || _a === void 0 ? void 0 : _a.findByClassName(styles_selectors_js_2.default['body-cell-editor-controls'])) !== null && _b !== void 0 ? _b : null; } findEditingCellSaveButton() { var _a, _b; return (_b = (_a = this._findEditingCellControls()) === null || _a === void 0 ? void 0 : _a.find('button[type="submit"]')) !== null && _b !== void 0 ? _b : null; } findEditingCellCancelButton() { var _a, _b; return (_b = (_a = this._findEditingCellControls()) === null || _a === void 0 ? void 0 : _a.find('button:first-child')) !== null && _b !== void 0 ? _b : null; } /** * Returns the expandable row toggle button. * * @param rowIndex 1-based index of the row. */ findExpandToggle(rowIndex) { // the file was moved, which changed the hash, so we cannot use old test class anymore. const oldSelector = `tbody tr:nth-child(${rowIndex}) .awsui_expand-toggle_1ss49_1w02f_153`; const newSelector = `tbody tr:nth-child(${rowIndex}) .${styles_selectors_js_1.default['expand-toggle']}`; return this.findNativeTable().findAny(oldSelector, newSelector); } /** * Returns `true` if the row expand toggle is present and expanded. Returns `false` otherwise. * * @param rowIndex 1-based index of the row. */ isRowToggled(rowIndex) { var _a; return ((_a = this.findExpandToggle(rowIndex)) === null || _a === void 0 ? void 0 : _a.getElement().getAttribute('aria-expanded')) === 'true'; } /** * Returns items loader of the root table level. */ findRootItemsLoader() { const selector = `.${styles_selectors_js_4.default['items-loader']}[data-root="true"]`; return this.find(selector); } /** * Returns items loader of the specific item (matched by item's track ID). * * @param itemId the (expandable) item ID provided with `trackBy` property. * * Note: when used with collection-hooks the `trackBy` is set automatically from `expandableRows.getId`. */ findItemsLoaderByItemId(itemId) { const selector = `.${styles_selectors_js_4.default['items-loader']}[data-parentrow="${itemId}"]`; return this.find(selector); } } TableWrapper.rootSelector = styles_selectors_js_7.default.root; exports.default = TableWrapper; __decorate([ dom_1.usesDom ], TableWrapper.prototype, "isRowToggled", null); //# sourceMappingURL=index.js.map