@@ -16,7 +16,13 @@ import {coerceBooleanProperty} from '@angular/cdk/coercion';
16
16
export class MatCheckboxHarness extends ComponentHarness {
17
17
static hostSelector = 'mat-checkbox' ;
18
18
19
- static with ( options : { label : string | RegExp } ) : HarnessPredicate < MatCheckboxHarness > {
19
+ /**
20
+ * Gets a `HarnessPredicate` that can be used to search for a checkbox with specific attributes.
21
+ * @param options Options for narrowing the search:
22
+ * - `label` finds a checkbox with specific label text.
23
+ * @return a `HarnessPredicate` configured with the given options.
24
+ */
25
+ static with ( options : { label ?: string | RegExp } = { } ) : HarnessPredicate < MatCheckboxHarness > {
20
26
return new HarnessPredicate ( MatCheckboxHarness )
21
27
. addOption ( 'label' , options . label ,
22
28
( harness , label ) => HarnessPredicate . stringMatches ( harness . getLabelText ( ) , label ) ) ;
@@ -25,69 +31,95 @@ export class MatCheckboxHarness extends ComponentHarness {
25
31
private _label = this . locatorFor ( '.mat-checkbox-label' ) ;
26
32
private _input = this . locatorFor ( 'input' ) ;
27
33
34
+ /** Gets a boolean promise indicating if the checkbox is checked. */
28
35
async isChecked ( ) : Promise < boolean > {
29
36
const checked = ( await this . _input ( ) ) . getAttribute ( 'checked' ) ;
30
37
return coerceBooleanProperty ( await checked ) ;
31
38
}
32
39
40
+ /** Gets a boolean promise indicating if the checkbox is in an indeterminate state. */
33
41
async isIndeterminate ( ) : Promise < boolean > {
34
42
const indeterminate = ( await this . _input ( ) ) . getAttribute ( 'indeterminate' ) ;
35
43
return coerceBooleanProperty ( await indeterminate ) ;
36
44
}
37
45
46
+ /** Gets a boolean promise indicating if the checkbox is disabled. */
38
47
async isDisabled ( ) : Promise < boolean > {
39
48
const disabled = ( await this . _input ( ) ) . getAttribute ( 'disabled' ) ;
40
49
return coerceBooleanProperty ( await disabled ) ;
41
50
}
42
51
52
+ /** Gets a boolean promise indicating if the checkbox is required. */
43
53
async isRequired ( ) : Promise < boolean > {
44
54
const required = ( await this . _input ( ) ) . getAttribute ( 'required' ) ;
45
55
return coerceBooleanProperty ( await required ) ;
46
56
}
47
57
58
+ /** Gets a boolean promise indicating if the checkbox is valid. */
48
59
async isValid ( ) : Promise < boolean > {
49
60
const invalid = ( await this . host ( ) ) . hasClass ( 'ng-invalid' ) ;
50
61
return ! ( await invalid ) ;
51
62
}
52
63
64
+ /** Gets a promise for the checkbox's name. */
53
65
async getName ( ) : Promise < string | null > {
54
66
return ( await this . _input ( ) ) . getAttribute ( 'name' ) ;
55
67
}
56
68
69
+ /** Gets a promise for the checkbox's value. */
57
70
async getValue ( ) : Promise < string | null > {
58
71
return ( await this . _input ( ) ) . getAttribute ( 'value' ) ;
59
72
}
60
73
74
+ /** Gets a promise for the checkbox's aria-label. */
61
75
async getAriaLabel ( ) : Promise < string | null > {
62
76
return ( await this . _input ( ) ) . getAttribute ( 'aria-label' ) ;
63
77
}
64
78
79
+ /** Gets a promise for the checkbox's aria-labelledby. */
65
80
async getAriaLabelledby ( ) : Promise < string | null > {
66
81
return ( await this . _input ( ) ) . getAttribute ( 'aria-labelledby' ) ;
67
82
}
68
83
84
+ /** Gets a promise for the checkbox's label text. */
69
85
async getLabelText ( ) : Promise < string > {
70
86
return ( await this . _label ( ) ) . text ( ) ;
71
87
}
72
88
89
+ /** Focuses the checkbox and returns a void promise that indicates when the action is complete. */
73
90
async foucs ( ) : Promise < void > {
74
91
return ( await this . _input ( ) ) . focus ( ) ;
75
92
}
76
93
94
+ /** Blurs the checkbox and returns a void promise that indicates when the action is complete. */
77
95
async blur ( ) : Promise < void > {
78
96
return ( await this . _input ( ) ) . blur ( ) ;
79
97
}
80
98
99
+ /**
100
+ * Toggle the checked state of the checkbox and returns a void promise that indicates when the
101
+ * action is complete.
102
+ */
81
103
async toggle ( ) : Promise < void > {
82
104
return ( await this . _input ( ) ) . click ( ) ;
83
105
}
84
106
107
+ /**
108
+ * Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing
109
+ * nothing if it is already checked. Returns a void promise that indicates when the action is
110
+ * complete.
111
+ */
85
112
async check ( ) : Promise < void > {
86
113
if ( ! ( await this . isChecked ( ) ) ) {
87
114
await this . toggle ( ) ;
88
115
}
89
116
}
90
117
118
+ /**
119
+ * Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing
120
+ * nothing if it is already unchecked. Returns a void promise that indicates when the action is
121
+ * complete.
122
+ */
91
123
async uncheck ( ) : Promise < void > {
92
124
if ( await this . isChecked ( ) ) {
93
125
await this . toggle ( ) ;
0 commit comments