MCPcopy
hub / github.com/angular/components / MatSortHeaderHarness

Class MatSortHeaderHarness

src/material/sort/testing/sort-header-harness.ts:14–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13/** Harness for interacting with a standard Angular Material sort header in tests. */
14export class MatSortHeaderHarness extends ComponentHarness {
15 static hostSelector = '.mat-sort-header';
16 private _container = this.locatorFor('.mat-sort-header-container');
17
18 /**
19 * Gets a `HarnessPredicate` that can be used to
20 * search for a sort header with specific attributes.
21 */
22 static with(options: SortHeaderHarnessFilters = {}): HarnessPredicate<MatSortHeaderHarness> {
23 return new HarnessPredicate(MatSortHeaderHarness, options)
24 .addOption('label', options.label, (harness, label) =>
25 HarnessPredicate.stringMatches(harness.getLabel(), label),
26 )
27 .addOption('sortDirection', options.sortDirection, (harness, sortDirection) => {
28 return HarnessPredicate.stringMatches(harness.getSortDirection(), sortDirection);
29 });
30 }
31
32 /** Gets the label of the sort header. */
33 async getLabel(): Promise<string> {
34 return (await this._container()).text();
35 }
36
37 /** Gets the sorting direction of the header. */
38 async getSortDirection(): Promise<SortDirection> {
39 const host = await this.host();
40 const ariaSort = await host.getAttribute('aria-sort');
41
42 if (ariaSort === 'ascending') {
43 return 'asc';
44 } else if (ariaSort === 'descending') {
45 return 'desc';
46 }
47
48 return '';
49 }
50
51 /** Gets whether the sort header is currently being sorted by. */
52 async isActive(): Promise<boolean> {
53 return !!(await this.getSortDirection());
54 }
55
56 /** Whether the sort header is disabled. */
57 async isDisabled(): Promise<boolean> {
58 return (await this.host()).hasClass('mat-sort-header-disabled');
59 }
60
61 /** Clicks the header to change its sorting direction. Only works if the header is enabled. */
62 async click(): Promise<void> {
63 return (await this.host()).click();
64 }
65}

Callers

nothing calls this directly

Calls 1

locatorForMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…