/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing'; /** Harness for interacting with a standard Angular Material sort header in tests. */ export class MatSortHeaderHarness extends ComponentHarness { constructor() { super(...arguments); this._container = this.locatorFor('.mat-sort-header-container'); } static { this.hostSelector = '.mat-sort-header'; } /** * Gets a `HarnessPredicate` that can be used to * search for a sort header with specific attributes. */ static with(options = {}) { return new HarnessPredicate(MatSortHeaderHarness, options) .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label)) .addOption('sortDirection', options.sortDirection, (harness, sortDirection) => { return HarnessPredicate.stringMatches(harness.getSortDirection(), sortDirection); }); } /** Gets the label of the sort header. */ async getLabel() { return (await this._container()).text(); } /** Gets the sorting direction of the header. */ async getSortDirection() { const host = await this.host(); const ariaSort = await host.getAttribute('aria-sort'); if (ariaSort === 'ascending') { return 'asc'; } else if (ariaSort === 'descending') { return 'desc'; } return ''; } /** Gets whether the sort header is currently being sorted by. */ async isActive() { return !!(await this.getSortDirection()); } /** Whether the sort header is disabled. */ async isDisabled() { return (await this.host()).hasClass('mat-sort-header-disabled'); } /** Clicks the header to change its sorting direction. Only works if the header is enabled. */ async click() { return (await this.host()).click(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic29ydC1oZWFkZXItaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9zb3J0L3Rlc3Rpbmcvc29ydC1oZWFkZXItaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQztBQUl4RSxxRk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