[6a3a178] | 1 | import { __awaiter } from 'tslib';
|
---|
| 2 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * @license
|
---|
| 6 | * Copyright Google LLC All Rights Reserved.
|
---|
| 7 | *
|
---|
| 8 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 9 | * found in the LICENSE file at https://angular.io/license
|
---|
| 10 | */
|
---|
| 11 | /** Harness for interacting with a standard Angular Material sort header in tests. */
|
---|
| 12 | class MatSortHeaderHarness extends ComponentHarness {
|
---|
| 13 | constructor() {
|
---|
| 14 | super(...arguments);
|
---|
| 15 | this._container = this.locatorFor('.mat-sort-header-container');
|
---|
| 16 | }
|
---|
| 17 | /**
|
---|
| 18 | * Gets a `HarnessPredicate` that can be used to
|
---|
| 19 | * search for a sort header with specific attributes.
|
---|
| 20 | */
|
---|
| 21 | static with(options = {}) {
|
---|
| 22 | return new HarnessPredicate(MatSortHeaderHarness, options)
|
---|
| 23 | .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label))
|
---|
| 24 | .addOption('sortDirection', options.sortDirection, (harness, sortDirection) => {
|
---|
| 25 | return HarnessPredicate.stringMatches(harness.getSortDirection(), sortDirection);
|
---|
| 26 | });
|
---|
| 27 | }
|
---|
| 28 | /** Gets the label of the sort header. */
|
---|
| 29 | getLabel() {
|
---|
| 30 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 31 | return (yield this._container()).text();
|
---|
| 32 | });
|
---|
| 33 | }
|
---|
| 34 | /** Gets the sorting direction of the header. */
|
---|
| 35 | getSortDirection() {
|
---|
| 36 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 37 | const host = yield this.host();
|
---|
| 38 | const ariaSort = yield host.getAttribute('aria-sort');
|
---|
| 39 | if (ariaSort === 'ascending') {
|
---|
| 40 | return 'asc';
|
---|
| 41 | }
|
---|
| 42 | else if (ariaSort === 'descending') {
|
---|
| 43 | return 'desc';
|
---|
| 44 | }
|
---|
| 45 | return '';
|
---|
| 46 | });
|
---|
| 47 | }
|
---|
| 48 | /** Gets whether the sort header is currently being sorted by. */
|
---|
| 49 | isActive() {
|
---|
| 50 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 51 | return !!(yield this.getSortDirection());
|
---|
| 52 | });
|
---|
| 53 | }
|
---|
| 54 | /** Whether the sort header is disabled. */
|
---|
| 55 | isDisabled() {
|
---|
| 56 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 57 | return (yield this.host()).hasClass('mat-sort-header-disabled');
|
---|
| 58 | });
|
---|
| 59 | }
|
---|
| 60 | /** Clicks the header to change its sorting direction. Only works if the header is enabled. */
|
---|
| 61 | click() {
|
---|
| 62 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 63 | return (yield this.host()).click();
|
---|
| 64 | });
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | MatSortHeaderHarness.hostSelector = '.mat-sort-header';
|
---|
| 68 |
|
---|
| 69 | /**
|
---|
| 70 | * @license
|
---|
| 71 | * Copyright Google LLC All Rights Reserved.
|
---|
| 72 | *
|
---|
| 73 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 74 | * found in the LICENSE file at https://angular.io/license
|
---|
| 75 | */
|
---|
| 76 | /** Harness for interacting with a standard `mat-sort` in tests. */
|
---|
| 77 | class MatSortHarness extends ComponentHarness {
|
---|
| 78 | /**
|
---|
| 79 | * Gets a `HarnessPredicate` that can be used to search for a `mat-sort` with specific attributes.
|
---|
| 80 | * @param options Options for narrowing the search.
|
---|
| 81 | * @return a `HarnessPredicate` configured with the given options.
|
---|
| 82 | */
|
---|
| 83 | static with(options = {}) {
|
---|
| 84 | return new HarnessPredicate(MatSortHarness, options);
|
---|
| 85 | }
|
---|
| 86 | /** Gets all of the sort headers in the `mat-sort`. */
|
---|
| 87 | getSortHeaders(filter = {}) {
|
---|
| 88 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 89 | return this.locatorForAll(MatSortHeaderHarness.with(filter))();
|
---|
| 90 | });
|
---|
| 91 | }
|
---|
| 92 | /** Gets the selected header in the `mat-sort`. */
|
---|
| 93 | getActiveHeader() {
|
---|
| 94 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 95 | const headers = yield this.getSortHeaders();
|
---|
| 96 | for (let i = 0; i < headers.length; i++) {
|
---|
| 97 | if (yield headers[i].isActive()) {
|
---|
| 98 | return headers[i];
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | return null;
|
---|
| 102 | });
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | MatSortHarness.hostSelector = '.mat-sort';
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * @license
|
---|
| 109 | * Copyright Google LLC All Rights Reserved.
|
---|
| 110 | *
|
---|
| 111 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 112 | * found in the LICENSE file at https://angular.io/license
|
---|
| 113 | */
|
---|
| 114 |
|
---|
| 115 | /**
|
---|
| 116 | * @license
|
---|
| 117 | * Copyright Google LLC All Rights Reserved.
|
---|
| 118 | *
|
---|
| 119 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 120 | * found in the LICENSE file at https://angular.io/license
|
---|
| 121 | */
|
---|
| 122 |
|
---|
| 123 | export { MatSortHarness, MatSortHeaderHarness };
|
---|
| 124 | //# sourceMappingURL=testing.js.map
|
---|