Skip to content

Commit 30f4b35

Browse files
committed
docs(harnesses): ensure all harnesses have complete and correct docs
1 parent 74dde10 commit 30f4b35

30 files changed

+296
-168
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: 8 additions & 8 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> {
@@ -39,7 +39,7 @@ export class MatAutocompleteHarness extends ComponentHarness {
3939
(harness, value) => HarnessPredicate.stringMatches(harness.getValue(), value));
4040
}
4141

42-
/** Gets the value of the autocomplete input. */
42+
/** Gets a promise for the value of the autocomplete input. */
4343
async getValue(): Promise<string> {
4444
return (await this.host()).getProperty('value');
4545
}
@@ -65,12 +65,12 @@ export class MatAutocompleteHarness extends ComponentHarness {
6565
return (await this.host()).sendKeys(value);
6666
}
6767

68-
/** Gets the options inside the autocomplete panel. */
68+
/** Gets a promise for the options inside the autocomplete panel. */
6969
async getOptions(filters: OptionHarnessFilters = {}): Promise<MatAutocompleteOptionHarness[]> {
7070
return this._documentRootLocator.locatorForAll(MatAutocompleteOptionHarness.with(filters))();
7171
}
7272

73-
/** Gets the groups of options inside the panel. */
73+
/** Gets a promise for the option groups inside the 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+
/** Gets a boolean promise indicating 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: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,44 @@ 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,
2945
(harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
3046
}
3147

32-
/** Clicks the option. */
48+
/**
49+
* Clicks the option.
50+
* @return A promise that resolves when the action is complete.
51+
*/
3352
async select(): Promise<void> {
3453
return (await this.host()).click();
3554
}
@@ -43,8 +62,16 @@ export class MatAutocompleteOptionHarness extends ComponentHarness {
4362
/** Harness for interacting with a the `mat-optgroup` for a `mat-autocomplete` in tests. */
4463
export class MatAutocompleteOptionGroupHarness extends ComponentHarness {
4564
private _label = this.locatorFor('.mat-optgroup-label');
65+
66+
/** The selector for the host element of an autocomplete `MatOptionGroup` instance. */
4667
static hostSelector = '.mat-autocomplete-panel .mat-optgroup';
4768

69+
/**
70+
* Gets a `HarnessPredicate` that can be used to search for a `MatAutocompleteOptionGroupHarness`
71+
* that meets certain criteria.
72+
* @param options Options for filtering which option group instances are considered a match.
73+
* @return a `HarnessPredicate` configured with the given options.
74+
*/
4875
static with(options: OptionGroupHarnessFilters = {}) {
4976
return new HarnessPredicate(MatAutocompleteOptionGroupHarness, options)
5077
.addOption('labelText', options.labelText,

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: 4 additions & 4 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> {

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: 4 additions & 5 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> {

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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,55 @@ 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> {
2727
return new HarnessPredicate(MatDialogHarness, options);
2828
}
2929

30-
/** Gets the id of the dialog. */
30+
/** Gets a promise for the id of the dialog. */
3131
async getId(): Promise<string|null> {
3232
const id = await (await this.host()).getAttribute('id');
3333
// In case no id has been specified, the "id" property always returns
3434
// an empty string. To make this method more explicit, we return null.
3535
return id !== '' ? id : null;
3636
}
3737

38-
/** Gets the role of the dialog. */
38+
/** Gets a promise for the role of the dialog. */
3939
async getRole(): Promise<DialogRole|null> {
4040
return (await this.host()).getAttribute('role') as Promise<DialogRole|null>;
4141
}
4242

43-
/** Gets the value of the dialog's "aria-label" attribute. */
43+
/** Gets a promise for the value of the dialog's "aria-label" attribute. */
4444
async getAriaLabel(): Promise<string|null> {
4545
return (await this.host()).getAttribute('aria-label');
4646
}
4747

48-
/** Gets the value of the dialog's "aria-labelledby" attribute. */
48+
/** Gets a promise for the value of the dialog's "aria-labelledby" attribute. */
4949
async getAriaLabelledby(): Promise<string|null> {
5050
return (await this.host()).getAttribute('aria-labelledby');
5151
}
5252

53-
/** Gets the value of the dialog's "aria-describedby" attribute. */
53+
/** Gets a promise for the value of the dialog's "aria-describedby" attribute. */
5454
async getAriaDescribedby(): Promise<string|null> {
5555
return (await this.host()).getAttribute('aria-describedby');
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 cannot be used if `disableClose` has been set to `true` for the dialog.
6162
*/
6263
async close(): Promise<void> {
6364
await (await this.host()).sendKeys(TestKey.ESCAPE);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

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

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

17+
/** A set of criteria that can be used to filter a list of `MatMenuItemHarness` instances. */
1518
export interface MenuItemHarnessFilters extends BaseHarnessFilters {
19+
/** Only find instances whose text matches the given value. */
1620
text?: string | RegExp;
21+
/** Only find instances that have a sub-menu. */
1722
hasSubmenu?: boolean;
1823
}

0 commit comments

Comments
 (0)