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

Class MatStepHarness

src/material/stepper/testing/step-harness.ts:17–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16/** Harness for interacting with a standard Angular Material step in tests. */
17export class MatStepHarness extends ContentContainerComponentHarness<string> {
18 /** The selector for the host element of a `MatStep` instance. */
19 static hostSelector = '.mat-step-header';
20
21 /**
22 * Gets a `HarnessPredicate` that can be used to search for a `MatStepHarness` that meets
23 * certain criteria.
24 * @param options Options for filtering which steps are considered a match.
25 * @return a `HarnessPredicate` configured with the given options.
26 */
27 static with(options: StepHarnessFilters = {}): HarnessPredicate<MatStepHarness> {
28 return new HarnessPredicate(MatStepHarness, options)
29 .addOption('label', options.label, (harness, label) =>
30 HarnessPredicate.stringMatches(harness.getLabel(), label),
31 )
32 .addOption(
33 'selected',
34 options.selected,
35 async (harness, selected) => (await harness.isSelected()) === selected,
36 )
37 .addOption(
38 'completed',
39 options.completed,
40 async (harness, completed) => (await harness.isCompleted()) === completed,
41 )
42 .addOption(
43 'invalid',
44 options.invalid,
45 async (harness, invalid) => (await harness.hasErrors()) === invalid,
46 );
47 }
48
49 /** Gets the label of the step. */
50 async getLabel(): Promise<string> {
51 return (await this.locatorFor('.mat-step-text-label')()).text();
52 }
53
54 /** Gets the `aria-label` of the step. */
55 async getAriaLabel(): Promise<string | null> {
56 return (await this.host()).getAttribute('aria-label');
57 }
58
59 /** Gets the value of the `aria-labelledby` attribute. */
60 async getAriaLabelledby(): Promise<string | null> {
61 return (await this.host()).getAttribute('aria-labelledby');
62 }
63
64 /** Whether the step is selected. */
65 async isSelected(): Promise<boolean> {
66 const host = await this.host();
67 return (
68 (await host.getAttribute('aria-selected')) === 'true' ||
69 (await host.getAttribute('aria-current')) === 'step'
70 );
71 }
72
73 /** Whether the step has been filled out. */
74 async isCompleted(): Promise<boolean> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…