import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing'; import { MatSelectHarness } from '@angular/material/select/testing'; import { coerceNumberProperty } from '@angular/cdk/coercion'; class _MatPaginatorHarnessBase extends ComponentHarness { /** Goes to the next page in the paginator. */ async goToNextPage() { return (await this._nextButton()).click(); } /** Returns whether or not the next page button is disabled. */ async isNextPageDisabled() { const disabledValue = await (await this._nextButton()).getAttribute('disabled'); return disabledValue == 'true'; } /* Returns whether or not the previous page button is disabled. */ async isPreviousPageDisabled() { const disabledValue = await (await this._previousButton()).getAttribute('disabled'); return disabledValue == 'true'; } /** Goes to the previous page in the paginator. */ async goToPreviousPage() { return (await this._previousButton()).click(); } /** Goes to the first page in the paginator. */ async goToFirstPage() { const button = await this._firstPageButton(); // The first page button isn't enabled by default so we need to check for it. if (!button) { throw Error('Could not find first page button inside paginator. ' + 'Make sure that `showFirstLastButtons` is enabled.'); } return button.click(); } /** Goes to the last page in the paginator. */ async goToLastPage() { const button = await this._lastPageButton(); // The last page button isn't enabled by default so we need to check for it. if (!button) { throw Error('Could not find last page button inside paginator. ' + 'Make sure that `showFirstLastButtons` is enabled.'); } return button.click(); } /** * Sets the page size of the paginator. * @param size Page size that should be select. */ async setPageSize(size) { const select = await this._select(); // The select is only available if the `pageSizeOptions` are // set to an array with more than one item. if (!select) { throw Error('Cannot find page size selector in paginator. ' + 'Make sure that the `pageSizeOptions` have been configured.'); } return select.clickOptions({ text: `${size}` }); } /** Gets the page size of the paginator. */ async getPageSize() { const select = await this._select(); const value = select ? select.getValueText() : (await this._pageSizeFallback()).text(); return coerceNumberProperty(await value); } /** Gets the text of the range label of the paginator. */ async getRangeLabel() { return (await this._rangeLabel()).text(); } } /** Harness for interacting with an MDC-based mat-paginator in tests. */ class MatPaginatorHarness extends _MatPaginatorHarnessBase { constructor() { super(...arguments); this._nextButton = this.locatorFor('.mat-mdc-paginator-navigation-next'); this._previousButton = this.locatorFor('.mat-mdc-paginator-navigation-previous'); this._firstPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-first'); this._lastPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-last'); this._select = this.locatorForOptional(MatSelectHarness.with({ ancestor: '.mat-mdc-paginator-page-size', })); this._pageSizeFallback = this.locatorFor('.mat-mdc-paginator-page-size-value'); this._rangeLabel = this.locatorFor('.mat-mdc-paginator-range-label'); } /** Selector used to find paginator instances. */ static { this.hostSelector = '.mat-mdc-paginator'; } /** * Gets a `HarnessPredicate` that can be used to search for a paginator with specific attributes. * @param options Options for filtering which paginator instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options); } } export { MatPaginatorHarness, _MatPaginatorHarnessBase }; //# sourceMappingURL=testing.mjs.map