|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing'; |
| 9 | +import {HarnessPredicate} from '@angular/cdk/testing'; |
10 | 10 | import {MatSelectHarness} from '@angular/material-experimental/mdc-select/testing';
|
11 |
| -import {coerceNumberProperty} from '@angular/cdk/coercion'; |
12 |
| -import {PaginatorHarnessFilters} from './paginator-harness-filters'; |
| 11 | +import { |
| 12 | + PaginatorHarnessFilters, |
| 13 | + MatPaginatorHarness as NonMdcMatPaginatorHarness, |
| 14 | +} from '@angular/material/paginator/testing'; |
13 | 15 |
|
14 | 16 |
|
15 | 17 | /** Harness for interacting with an MDC-based mat-paginator in tests. */
|
16 |
| -export class MatPaginatorHarness extends ComponentHarness { |
| 18 | +export class MatPaginatorHarness extends NonMdcMatPaginatorHarness { |
17 | 19 | /** Selector used to find paginator instances. */
|
18 | 20 | static hostSelector = '.mat-mdc-paginator';
|
19 |
| - private _nextButton = this.locatorFor('.mat-mdc-paginator-navigation-next'); |
20 |
| - private _previousButton = this.locatorFor('.mat-mdc-paginator-navigation-previous'); |
21 |
| - private _firstPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-first'); |
22 |
| - private _lastPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-last'); |
23 |
| - private _select = this.locatorForOptional(MatSelectHarness.with({ |
| 21 | + protected _nextButton = this.locatorFor('.mat-mdc-paginator-navigation-next'); |
| 22 | + protected _previousButton = this.locatorFor('.mat-mdc-paginator-navigation-previous'); |
| 23 | + protected _firstPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-first'); |
| 24 | + protected _lastPageButton = this.locatorForOptional('.mat-mdc-paginator-navigation-last'); |
| 25 | + protected _select = this.locatorForOptional(MatSelectHarness.with({ |
24 | 26 | ancestor: '.mat-mdc-paginator-page-size'
|
25 |
| - })); |
26 |
| - private _pageSizeFallback = this.locatorFor('.mat-mdc-paginator-page-size-value'); |
27 |
| - private _rangeLabel = this.locatorFor('.mat-mdc-paginator-range-label'); |
| 27 | + })) as any; // TODO(crisbeto): should be able to remove the `as any` after #21460 is merged in. |
| 28 | + protected _pageSizeFallback = this.locatorFor('.mat-mdc-paginator-page-size-value'); |
| 29 | + protected _rangeLabel = this.locatorFor('.mat-mdc-paginator-range-label'); |
28 | 30 |
|
29 | 31 | /**
|
30 | 32 | * Gets a `HarnessPredicate` that can be used to search for a `MatPaginatorHarness` that meets
|
31 | 33 | * certain criteria.
|
32 | 34 | * @param options Options for filtering which paginator instances are considered a match.
|
33 | 35 | * @return a `HarnessPredicate` configured with the given options.
|
34 | 36 | */
|
35 |
| - static with(options: PaginatorHarnessFilters = {}): HarnessPredicate<MatPaginatorHarness> { |
36 |
| - return new HarnessPredicate(MatPaginatorHarness, options); |
37 |
| - } |
38 |
| - |
39 |
| - /** Goes to the next page in the paginator. */ |
40 |
| - async goToNextPage(): Promise<void> { |
41 |
| - return (await this._nextButton()).click(); |
42 |
| - } |
43 |
| - |
44 |
| - /** Goes to the previous page in the paginator. */ |
45 |
| - async goToPreviousPage(): Promise<void> { |
46 |
| - return (await this._previousButton()).click(); |
47 |
| - } |
48 |
| - |
49 |
| - /** Goes to the first page in the paginator. */ |
50 |
| - async goToFirstPage(): Promise<void> { |
51 |
| - const button = await this._firstPageButton(); |
52 |
| - |
53 |
| - // The first page button isn't enabled by default so we need to check for it. |
54 |
| - if (!button) { |
55 |
| - throw Error('Could not find first page button inside paginator. ' + |
56 |
| - 'Make sure that `showFirstLastButtons` is enabled.'); |
57 |
| - } |
58 |
| - |
59 |
| - return button.click(); |
60 |
| - } |
61 |
| - |
62 |
| - /** Goes to the last page in the paginator. */ |
63 |
| - async goToLastPage(): Promise<void> { |
64 |
| - const button = await this._lastPageButton(); |
65 |
| - |
66 |
| - // The last page button isn't enabled by default so we need to check for it. |
67 |
| - if (!button) { |
68 |
| - throw Error('Could not find last page button inside paginator. ' + |
69 |
| - 'Make sure that `showFirstLastButtons` is enabled.'); |
70 |
| - } |
71 |
| - |
72 |
| - return button.click(); |
73 |
| - } |
74 |
| - |
75 |
| - /** |
76 |
| - * Sets the page size of the paginator. |
77 |
| - * @param size Page size that should be select. |
78 |
| - */ |
79 |
| - async setPageSize(size: number): Promise<void> { |
80 |
| - const select = await this._select(); |
81 |
| - |
82 |
| - // The select is only available if the `pageSizeOptions` are |
83 |
| - // set to an array with more than one item. |
84 |
| - if (!select) { |
85 |
| - throw Error('Cannot find page size selector in paginator. ' + |
86 |
| - 'Make sure that the `pageSizeOptions` have been configured.'); |
87 |
| - } |
88 |
| - |
89 |
| - return select.clickOptions({text: `${size}`}); |
90 |
| - } |
91 |
| - |
92 |
| - /** Gets the page size of the paginator. */ |
93 |
| - async getPageSize(): Promise<number> { |
94 |
| - const select = await this._select(); |
95 |
| - const value = select ? select.getValueText() : (await this._pageSizeFallback()).text(); |
96 |
| - return coerceNumberProperty(await value); |
97 |
| - } |
98 |
| - |
99 |
| - /** Gets the text of the range labe of the paginator. */ |
100 |
| - async getRangeLabel(): Promise<string> { |
101 |
| - return (await this._rangeLabel()).text(); |
| 37 | + static with(options: PaginatorHarnessFilters = {}): HarnessPredicate<NonMdcMatPaginatorHarness> { |
| 38 | + return new HarnessPredicate<NonMdcMatPaginatorHarness>(MatPaginatorHarness, options); |
102 | 39 | }
|
103 | 40 | }
|
0 commit comments