Skip to content

Commit ef85134

Browse files
mmalerbajelbourn
authored andcommitted
docs(harnesses): ensure all harnesses have complete and correct docs (#17723)
1 parent 74dde10 commit ef85134

31 files changed

+258
-195
lines changed

src/cdk/testing/component-harness.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,11 @@ export interface ComponentHarnessConstructor<T extends ComponentHarness> {
384384
hostSelector: string;
385385
}
386386

387+
/** A set of criteria that can be used to filter a list of `ComponentHarness` instances. */
387388
export interface BaseHarnessFilters {
388-
/** Only find component instances whose host element matches the given selector. */
389+
/** Only find instances whose host element matches the given selector. */
389390
selector?: string;
390-
/** Only find component instances that are nested under an element with the given selector. */
391+
/** Only find instances that are nested under an element with the given selector. */
391392
ancestor?: string;
392393
}
393394

src/material/autocomplete/testing/autocomplete-harness-filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11+
/** A set of criteria that can be used to filter a list of `MatAutocompleteHarness` instances. */
1112
export interface AutocompleteHarnessFilters extends BaseHarnessFilters {
13+
/** Only find instances whose associated input element matches the given value. */
1214
value?: string | RegExp;
1315
}

src/material/autocomplete/testing/autocomplete-harness.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export class MatAutocompleteHarness extends ComponentHarness {
2424
private _documentRootLocator = this.documentRootLocatorFactory();
2525
private _optionalPanel = this._documentRootLocator.locatorForOptional(PANEL_SELECTOR);
2626

27+
/** The selector for the host element of a `MatAutocomplete` instance. */
2728
static hostSelector = '.mat-autocomplete-trigger';
2829

2930
/**
30-
* Gets a `HarnessPredicate` that can be used to search for an autocomplete with
31-
* specific attributes.
32-
* @param options Options for narrowing the search:
33-
* - `name` finds an autocomplete with a specific name.
31+
* Gets a `HarnessPredicate` that can be used to search for a `MatAutocompleteHarness` that meets
32+
* certain criteria.
33+
* @param options Options for filtering which autocomplete instances are considered a match.
3434
* @return a `HarnessPredicate` configured with the given options.
3535
*/
3636
static with(options: AutocompleteHarnessFilters = {}): HarnessPredicate<MatAutocompleteHarness> {
@@ -44,18 +44,18 @@ export class MatAutocompleteHarness extends ComponentHarness {
4444
return (await this.host()).getProperty('value');
4545
}
4646

47-
/** Gets a boolean promise indicating if the autocomplete input is disabled. */
47+
/** Whether the autocomplete input is disabled. */
4848
async isDisabled(): Promise<boolean> {
4949
const disabled = (await this.host()).getAttribute('disabled');
5050
return coerceBooleanProperty(await disabled);
5151
}
5252

53-
/** Focuses the input and returns a void promise that indicates when the action is complete. */
53+
/** Focuses the autocomplete input. */
5454
async focus(): Promise<void> {
5555
return (await this.host()).focus();
5656
}
5757

58-
/** Blurs the input and returns a void promise that indicates when the action is complete. */
58+
/** Blurs the autocomplete input. */
5959
async blur(): Promise<void> {
6060
return (await this.host()).blur();
6161
}
@@ -70,7 +70,7 @@ export class MatAutocompleteHarness extends ComponentHarness {
7070
return this._documentRootLocator.locatorForAll(MatAutocompleteOptionHarness.with(filters))();
7171
}
7272

73-
/** Gets the groups of options inside the panel. */
73+
/** Gets the option groups inside the autocomplete panel. */
7474
async getOptionGroups(filters: OptionGroupHarnessFilters = {}):
7575
Promise<MatAutocompleteOptionGroupHarness[]> {
7676
return this._documentRootLocator.locatorForAll(
@@ -87,7 +87,7 @@ export class MatAutocompleteHarness extends ComponentHarness {
8787
await options[0].select();
8888
}
8989

90-
/** Gets whether the autocomplete is open. */
90+
/** Whether the autocomplete is open. */
9191
async isOpen(): Promise<boolean> {
9292
const panel = await this._optionalPanel();
9393
return !!panel && await panel.hasClass('mat-autocomplete-visible');

src/material/autocomplete/testing/option-harness.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,34 @@ import {ComponentHarness, HarnessPredicate, BaseHarnessFilters} from '@angular/c
1111
// TODO(crisbeto): combine these with the ones in `mat-select`
1212
// and expand to cover all states once we have experimental/core.
1313

14+
/**
15+
* A set of criteria that can be used to filter a list of `MatAutocompleteOptionHarness` instances
16+
*/
1417
export interface OptionHarnessFilters extends BaseHarnessFilters {
18+
/** Only find instances whose text matches the given value. */
1519
text?: string | RegExp;
1620
}
1721

22+
/**
23+
* A set of criteria that can be used to filter a list of `MatAutocompleteOptionGroupHarness`
24+
* instances.
25+
*/
1826
export interface OptionGroupHarnessFilters extends BaseHarnessFilters {
27+
/** Only find instances whose label text matches the given value. */
1928
labelText?: string | RegExp;
2029
}
2130

2231
/** Harness for interacting with a the `mat-option` for a `mat-autocomplete` in tests. */
2332
export class MatAutocompleteOptionHarness extends ComponentHarness {
33+
/** The selector for the host element of an autocomplete `MatOption` instance. */
2434
static hostSelector = '.mat-autocomplete-panel .mat-option';
2535

36+
/**
37+
* Gets a `HarnessPredicate` that can be used to search for a `MatAutocompleteOptionHarness` that
38+
* meets certain criteria.
39+
* @param options Options for filtering which option instances are considered a match.
40+
* @return a `HarnessPredicate` configured with the given options.
41+
*/
2642
static with(options: OptionHarnessFilters = {}) {
2743
return new HarnessPredicate(MatAutocompleteOptionHarness, options)
2844
.addOption('text', options.text,
@@ -34,7 +50,7 @@ export class MatAutocompleteOptionHarness extends ComponentHarness {
3450
return (await this.host()).click();
3551
}
3652

37-
/** Gets a promise for the option's label text. */
53+
/** Gets the option's label text. */
3854
async getText(): Promise<string> {
3955
return (await this.host()).text();
4056
}
@@ -43,15 +59,23 @@ export class MatAutocompleteOptionHarness extends ComponentHarness {
4359
/** Harness for interacting with a the `mat-optgroup` for a `mat-autocomplete` in tests. */
4460
export class MatAutocompleteOptionGroupHarness extends ComponentHarness {
4561
private _label = this.locatorFor('.mat-optgroup-label');
62+
63+
/** The selector for the host element of an autocomplete `MatOptionGroup` instance. */
4664
static hostSelector = '.mat-autocomplete-panel .mat-optgroup';
4765

66+
/**
67+
* Gets a `HarnessPredicate` that can be used to search for a `MatAutocompleteOptionGroupHarness`
68+
* that meets certain criteria.
69+
* @param options Options for filtering which option group instances are considered a match.
70+
* @return a `HarnessPredicate` configured with the given options.
71+
*/
4872
static with(options: OptionGroupHarnessFilters = {}) {
4973
return new HarnessPredicate(MatAutocompleteOptionGroupHarness, options)
5074
.addOption('labelText', options.labelText,
5175
(harness, label) => HarnessPredicate.stringMatches(harness.getLabelText(), label));
5276
}
5377

54-
/** Gets a promise for the option group's label text. */
78+
/** Gets the option group's label text. */
5579
async getLabelText(): Promise<string> {
5680
return (await this._label()).text();
5781
}

src/material/button/testing/button-harness-filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11+
/** A set of criteria that can be used to filter a list of `MatButtonHarness` instances. */
1112
export interface ButtonHarnessFilters extends BaseHarnessFilters {
13+
/** Only find instances whose text matches the given value. */
1214
text?: string | RegExp;
1315
}

src/material/button/testing/button-harness.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {ButtonHarnessFilters} from './button-harness-filters';
1414
/** Harness for interacting with a standard mat-button in tests. */
1515
export class MatButtonHarness extends ComponentHarness {
1616
// TODO(jelbourn) use a single class, like `.mat-button-base`
17+
/** The selector for the host element of a `MatButton` instance. */
1718
static hostSelector = [
1819
'[mat-button]',
1920
'[mat-raised-button]',
@@ -25,10 +26,9 @@ export class MatButtonHarness extends ComponentHarness {
2526
].join(',');
2627

2728
/**
28-
* Gets a `HarnessPredicate` that can be used to search for a button with specific attributes.
29-
* @param options Options for narrowing the search:
30-
* - `selector` finds a button whose host element matches the given selector.
31-
* - `text` finds a button with specific text content.
29+
* Gets a `HarnessPredicate` that can be used to search for a `MatButtonHarness` that meets
30+
* certain criteria.
31+
* @param options Options for filtering which button instances are considered a match.
3232
* @return a `HarnessPredicate` configured with the given options.
3333
*/
3434
static with(options: ButtonHarnessFilters = {}): HarnessPredicate<MatButtonHarness> {
@@ -42,23 +42,23 @@ export class MatButtonHarness extends ComponentHarness {
4242
return (await this.host()).click();
4343
}
4444

45-
/** Gets a boolean promise indicating if the button is disabled. */
45+
/** Whether the button is disabled. */
4646
async isDisabled(): Promise<boolean> {
4747
const disabled = (await this.host()).getAttribute('disabled');
4848
return coerceBooleanProperty(await disabled);
4949
}
5050

51-
/** Gets a promise for the button's label text. */
51+
/** Gets the button's label text. */
5252
async getText(): Promise<string> {
5353
return (await this.host()).text();
5454
}
5555

56-
/** Focuses the button and returns a void promise that indicates when the action is complete. */
56+
/** Focuses the button. */
5757
async focus(): Promise<void> {
5858
return (await this.host()).focus();
5959
}
6060

61-
/** Blurs the button and returns a void promise that indicates when the action is complete. */
61+
/** Blurs the button. */
6262
async blur(): Promise<void> {
6363
return (await this.host()).blur();
6464
}

src/material/checkbox/testing/checkbox-harness-filters.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11+
/** A set of criteria that can be used to filter a list of `MatCheckboxHarness` instances. */
1112
export interface CheckboxHarnessFilters extends BaseHarnessFilters {
13+
/** Only find instances whose label matches the given value. */
1214
label?: string | RegExp;
15+
/** Only find instances whose name attribute is the given value. */
1316
name?: string;
1417
}

src/material/checkbox/testing/checkbox-harness.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import {CheckboxHarnessFilters} from './checkbox-harness-filters';
1212

1313
/** Harness for interacting with a standard mat-checkbox in tests. */
1414
export class MatCheckboxHarness extends ComponentHarness {
15+
/** The selector for the host element of a `MatCheckbox` instance. */
1516
static hostSelector = 'mat-checkbox';
1617

1718
/**
18-
* Gets a `HarnessPredicate` that can be used to search for a checkbox with specific attributes.
19-
* @param options Options for narrowing the search:
20-
* - `selector` finds a checkbox whose host element matches the given selector.
21-
* - `label` finds a checkbox with specific label text.
22-
* - `name` finds a checkbox with specific name.
19+
* Gets a `HarnessPredicate` that can be used to search for a `MatCheckboxHarness` that meets
20+
* certain criteria.
21+
* @param options Options for filtering which checkbox instances are considered a match.
2322
* @return a `HarnessPredicate` configured with the given options.
2423
*/
2524
static with(options: CheckboxHarnessFilters = {}): HarnessPredicate<MatCheckboxHarness> {
@@ -37,74 +36,73 @@ export class MatCheckboxHarness extends ComponentHarness {
3736
private _input = this.locatorFor('input');
3837
private _inputContainer = this.locatorFor('.mat-checkbox-inner-container');
3938

40-
/** Gets a boolean promise indicating if the checkbox is checked. */
39+
/** Whether the checkbox is checked. */
4140
async isChecked(): Promise<boolean> {
4241
const checked = (await this._input()).getProperty('checked');
4342
return coerceBooleanProperty(await checked);
4443
}
4544

46-
/** Gets a boolean promise indicating if the checkbox is in an indeterminate state. */
45+
/** Whether the checkbox is in an indeterminate state. */
4746
async isIndeterminate(): Promise<boolean> {
4847
const indeterminate = (await this._input()).getProperty('indeterminate');
4948
return coerceBooleanProperty(await indeterminate);
5049
}
5150

52-
/** Gets a boolean promise indicating if the checkbox is disabled. */
51+
/** Whether the checkbox is disabled. */
5352
async isDisabled(): Promise<boolean> {
5453
const disabled = (await this._input()).getAttribute('disabled');
5554
return coerceBooleanProperty(await disabled);
5655
}
5756

58-
/** Gets a boolean promise indicating if the checkbox is required. */
57+
/** Whether the checkbox is required. */
5958
async isRequired(): Promise<boolean> {
6059
const required = (await this._input()).getProperty('required');
6160
return coerceBooleanProperty(await required);
6261
}
6362

64-
/** Gets a boolean promise indicating if the checkbox is valid. */
63+
/** Whether the checkbox is valid. */
6564
async isValid(): Promise<boolean> {
6665
const invalid = (await this.host()).hasClass('ng-invalid');
6766
return !(await invalid);
6867
}
6968

70-
/** Gets a promise for the checkbox's name. */
69+
/** Gets the checkbox's name. */
7170
async getName(): Promise<string|null> {
7271
return (await this._input()).getAttribute('name');
7372
}
7473

75-
/** Gets a promise for the checkbox's value. */
74+
/** Gets the checkbox's value. */
7675
async getValue(): Promise<string|null> {
7776
return (await this._input()).getProperty('value');
7877
}
7978

80-
/** Gets a promise for the checkbox's aria-label. */
79+
/** Gets the checkbox's aria-label. */
8180
async getAriaLabel(): Promise<string|null> {
8281
return (await this._input()).getAttribute('aria-label');
8382
}
8483

85-
/** Gets a promise for the checkbox's aria-labelledby. */
84+
/** Gets the checkbox's aria-labelledby. */
8685
async getAriaLabelledby(): Promise<string|null> {
8786
return (await this._input()).getAttribute('aria-labelledby');
8887
}
8988

90-
/** Gets a promise for the checkbox's label text. */
89+
/** Gets the checkbox's label text. */
9190
async getLabelText(): Promise<string> {
9291
return (await this._label()).text();
9392
}
9493

95-
/** Focuses the checkbox and returns a void promise that indicates when the action is complete. */
94+
/** Focuses the checkbox. */
9695
async focus(): Promise<void> {
9796
return (await this._input()).focus();
9897
}
9998

100-
/** Blurs the checkbox and returns a void promise that indicates when the action is complete. */
99+
/** Blurs the checkbox. */
101100
async blur(): Promise<void> {
102101
return (await this._input()).blur();
103102
}
104103

105104
/**
106-
* Toggle the checked state of the checkbox and returns a void promise that indicates when the
107-
* action is complete.
105+
* Toggles the checked state of the checkbox.
108106
*
109107
* Note: This attempts to toggle the checkbox as a user would, by clicking it. Therefore if you
110108
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method
@@ -116,8 +114,7 @@ export class MatCheckboxHarness extends ComponentHarness {
116114

117115
/**
118116
* Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing
119-
* nothing if it is already checked. Returns a void promise that indicates when the action is
120-
* complete.
117+
* nothing if it is already checked.
121118
*
122119
* Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you
123120
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method
@@ -131,8 +128,7 @@ export class MatCheckboxHarness extends ComponentHarness {
131128

132129
/**
133130
* Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing
134-
* nothing if it is already unchecked. Returns a void promise that indicates when the action is
135-
* complete.
131+
* nothing if it is already unchecked.
136132
*
137133
* Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you
138134
* are using `MAT_CHECKBOX_CLICK_ACTION` to change the behavior on click, calling this method

src/material/dialog/testing/dialog-harness-filters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
import {BaseHarnessFilters} from '@angular/cdk/testing';
1010

11+
/** A set of criteria that can be used to filter a list of `MatDialogHarness` instances. */
1112
export interface DialogHarnessFilters extends BaseHarnessFilters {}

src/material/dialog/testing/dialog-harness.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import {ComponentHarness, HarnessPredicate, TestKey} from '@angular/cdk/testing'
1010
import {DialogRole} from '@angular/material/dialog';
1111
import {DialogHarnessFilters} from './dialog-harness-filters';
1212

13-
/** Harness for interacting with a standard MatDialog in tests. */
13+
/** Harness for interacting with a standard `MatDialog` in tests. */
1414
export class MatDialogHarness extends ComponentHarness {
1515
// Developers can provide a custom component or template for the
1616
// dialog. The canonical dialog parent is the "MatDialogContainer".
17+
/** The selector for the host element of a `MatDialog` instance. */
1718
static hostSelector = '.mat-dialog-container';
1819

1920
/**
20-
* Gets a `HarnessPredicate` that can be used to search for a dialog with
21-
* specific attributes.
22-
* @param options Options for narrowing the search:
23-
* - `id` finds a dialog with specific id.
21+
* Gets a `HarnessPredicate` that can be used to search for a `MatDialogHarness` that meets
22+
* certain criteria.
23+
* @param options Options for filtering which dialog instances are considered a match.
2424
* @return a `HarnessPredicate` configured with the given options.
2525
*/
2626
static with(options: DialogHarnessFilters = {}): HarnessPredicate<MatDialogHarness> {
@@ -56,8 +56,9 @@ export class MatDialogHarness extends ComponentHarness {
5656
}
5757

5858
/**
59-
* Closes the dialog by pressing escape. Note that this method cannot
60-
* be used if "disableClose" has been set to true for the dialog.
59+
* Closes the dialog by pressing escape.
60+
*
61+
* Note: this method does nothing if `disableClose` has been set to `true` for the dialog.
6162
*/
6263
async close(): Promise<void> {
6364
await (await this.host()).sendKeys(TestKey.ESCAPE);

0 commit comments

Comments
 (0)