@angular/material
Version:
Angular Material
1 lines • 7.05 kB
Source Map (JSON)
{"version":3,"file":"testing.mjs","sources":["../../../../../../darwin_arm64-fastbuild-ST-46c76129e412/bin/src/material/paginator/testing/paginator-harness.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n ComponentHarness,\n ComponentHarnessConstructor,\n HarnessPredicate,\n} from '@angular/cdk/testing';\nimport {MatSelectHarness} from '../../select/testing';\nimport {coerceNumberProperty} from '@angular/cdk/coercion';\nimport {PaginatorHarnessFilters} from './paginator-harness-filters';\n\n/** Harness for interacting with a mat-paginator in tests. */\nexport class MatPaginatorHarness extends ComponentHarness {\n /** Selector used to find paginator instances. */\n static hostSelector = '.mat-mdc-paginator';\n private _nextButton = this.locatorFor('.mat-mdc-paginator-navigation-next');\n private _previousButton = this.locatorFor('.mat-mdc-paginator-navigation-previous');\n private _firstPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-first');\n private _lastPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-last');\n _select = this.locatorForOptional(\n MatSelectHarness.with({\n ancestor: '.mat-mdc-paginator-page-size',\n }),\n );\n private _pageSizeFallback = this.locatorFor('.mat-mdc-paginator-page-size-value');\n _rangeLabel = this.locatorFor('.mat-mdc-paginator-range-label');\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a paginator with specific attributes.\n * @param options Options for filtering which paginator instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with<T extends MatPaginatorHarness>(\n this: ComponentHarnessConstructor<T>,\n options: PaginatorHarnessFilters = {},\n ): HarnessPredicate<T> {\n return new HarnessPredicate(this, options);\n }\n\n /** Goes to the next page in the paginator. */\n async goToNextPage(): Promise<void> {\n return (await this._nextButton()).click();\n }\n\n /** Returns whether or not the next page button is disabled. */\n async isNextPageDisabled(): Promise<boolean> {\n const disabledValue = await (await this._nextButton()).getAttribute('aria-disabled');\n return disabledValue == 'true';\n }\n\n /* Returns whether or not the previous page button is disabled. */\n async isPreviousPageDisabled(): Promise<boolean> {\n const disabledValue = await (await this._previousButton()).getAttribute('aria-disabled');\n return disabledValue == 'true';\n }\n\n /** Goes to the previous page in the paginator. */\n async goToPreviousPage(): Promise<void> {\n return (await this._previousButton()).click();\n }\n\n /** Goes to the first page in the paginator. */\n async goToFirstPage(): Promise<void> {\n const button = await this._firstPageButton();\n\n // The first page button isn't enabled by default so we need to check for it.\n if (!button) {\n throw Error(\n 'Could not find first page button inside paginator. ' +\n 'Make sure that `showFirstLastButtons` is enabled.',\n );\n }\n\n return button.click();\n }\n\n /** Goes to the last page in the paginator. */\n async goToLastPage(): Promise<void> {\n const button = await this._lastPageButton();\n\n // The last page button isn't enabled by default so we need to check for it.\n if (!button) {\n throw Error(\n 'Could not find last page button inside paginator. ' +\n 'Make sure that `showFirstLastButtons` is enabled.',\n );\n }\n\n return button.click();\n }\n\n /**\n * Sets the page size of the paginator.\n * @param size Page size that should be select.\n */\n async setPageSize(size: number): Promise<void> {\n const select = await this._select();\n\n // The select is only available if the `pageSizeOptions` are\n // set to an array with more than one item.\n if (!select) {\n throw Error(\n 'Cannot find page size selector in paginator. ' +\n 'Make sure that the `pageSizeOptions` have been configured.',\n );\n }\n\n return select.clickOptions({text: `${size}`});\n }\n\n /** Gets the page size of the paginator. */\n async getPageSize(): Promise<number> {\n const select = await this._select();\n const value = select ? select.getValueText() : (await this._pageSizeFallback()).text();\n return coerceNumberProperty(await value);\n }\n\n /** Gets the text of the range label of the paginator. */\n async getRangeLabel(): Promise<string> {\n return (await this._rangeLabel()).text();\n }\n}\n"],"names":[],"mappings":";;;;;;;AAiBA;AACM,MAAO,mBAAoB,SAAQ,gBAAgB,CAAA;;AAEvD,IAAA,OAAO,YAAY,GAAG,oBAAoB,CAAA;AAClC,IAAA,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,oCAAoC,CAAC,CAAA;AACnE,IAAA,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