6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { ComponentHarness , HarnessPredicate } from '@angular/cdk/testing' ;
10
- import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
- import { CheckboxHarnessFilters } from '@angular/material/checkbox/testing' ;
9
+ import { HarnessPredicate } from '@angular/cdk/testing' ;
10
+ import { CheckboxHarnessFilters , _MatCheckboxHarnessBase } from '@angular/material/checkbox/testing' ;
12
11
13
12
/** Harness for interacting with a MDC-based mat-checkbox in tests. */
14
- export class MatCheckboxHarness extends ComponentHarness {
13
+ export class MatCheckboxHarness extends _MatCheckboxHarnessBase {
15
14
static hostSelector = '.mat-mdc-checkbox' ;
16
15
17
16
/**
@@ -33,120 +32,12 @@ export class MatCheckboxHarness extends ComponentHarness {
33
32
. addOption ( 'name' , options . name , async ( harness , name ) => await harness . getName ( ) === name ) ;
34
33
}
35
34
36
- private _label = this . locatorFor ( 'label ' ) ;
37
- private _input = this . locatorFor ( 'input ' ) ;
35
+ protected _input = this . locatorFor ( 'input ' ) ;
36
+ protected _label = this . locatorFor ( 'label ' ) ;
38
37
private _inputContainer = this . locatorFor ( '.mdc-checkbox' ) ;
39
38
40
- /** Gets a boolean promise indicating if the checkbox is checked. */
41
- async isChecked ( ) : Promise < boolean > {
42
- const checked = ( await this . _input ( ) ) . getProperty ( 'checked' ) ;
43
- return coerceBooleanProperty ( await checked ) ;
44
- }
45
-
46
- /** Gets a boolean promise indicating if the checkbox is in an indeterminate state. */
47
- async isIndeterminate ( ) : Promise < boolean > {
48
- const indeterminate = ( await this . _input ( ) ) . getProperty ( 'indeterminate' ) ;
49
- return coerceBooleanProperty ( await indeterminate ) ;
50
- }
51
-
52
- /** Gets a boolean promise indicating if the checkbox is disabled. */
53
- async isDisabled ( ) : Promise < boolean > {
54
- const disabled = ( await this . _input ( ) ) . getAttribute ( 'disabled' ) ;
55
- return coerceBooleanProperty ( await disabled ) ;
56
- }
57
-
58
- /** Gets a boolean promise indicating if the checkbox is required. */
59
- async isRequired ( ) : Promise < boolean > {
60
- const required = ( await this . _input ( ) ) . getAttribute ( 'required' ) ;
61
- return coerceBooleanProperty ( await required ) ;
62
- }
63
-
64
- /** Gets a boolean promise indicating if the checkbox is valid. */
65
- async isValid ( ) : Promise < boolean > {
66
- const invalid = ( await this . host ( ) ) . hasClass ( 'ng-invalid' ) ;
67
- return ! ( await invalid ) ;
68
- }
69
-
70
- /** Gets a promise for the checkbox's name. */
71
- async getName ( ) : Promise < string | null > {
72
- return ( await this . _input ( ) ) . getAttribute ( 'name' ) ;
73
- }
74
-
75
- /** Gets a promise for the checkbox's value. */
76
- async getValue ( ) : Promise < string | null > {
77
- return ( await this . _input ( ) ) . getProperty ( 'value' ) ;
78
- }
79
-
80
- /** Gets a promise for the checkbox's aria-label. */
81
- async getAriaLabel ( ) : Promise < string | null > {
82
- return ( await this . _input ( ) ) . getAttribute ( 'aria-label' ) ;
83
- }
84
-
85
- /** Gets a promise for the checkbox's aria-labelledby. */
86
- async getAriaLabelledby ( ) : Promise < string | null > {
87
- return ( await this . _input ( ) ) . getAttribute ( 'aria-labelledby' ) ;
88
- }
89
-
90
- /** Gets a promise for the checkbox's label text. */
91
- async getLabelText ( ) : Promise < string > {
92
- return ( await this . _label ( ) ) . text ( ) ;
93
- }
94
-
95
- /** Focuses the checkbox and returns a void promise that indicates when the action is complete. */
96
- async focus ( ) : Promise < void > {
97
- return ( await this . _input ( ) ) . focus ( ) ;
98
- }
99
-
100
- /** Blurs the checkbox and returns a void promise that indicates when the action is complete. */
101
- async blur ( ) : Promise < void > {
102
- return ( await this . _input ( ) ) . blur ( ) ;
103
- }
104
-
105
- /** Whether the checkbox is focused. */
106
- async isFocused ( ) : Promise < boolean > {
107
- return ( await this . _input ( ) ) . isFocused ( ) ;
108
- }
109
-
110
- /**
111
- * Toggle the checked state of the checkbox and returns a void promise that indicates when the
112
- * action is complete.
113
- *
114
- * Note: This attempts to toggle the checkbox as a user would, by clicking it. Therefore if you
115
- * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method
116
- * might not have the expected result.
117
- */
118
39
async toggle ( ) : Promise < void > {
119
40
const elToClick = await this . isDisabled ( ) ? this . _inputContainer ( ) : this . _input ( ) ;
120
41
return ( await elToClick ) . click ( ) ;
121
42
}
122
-
123
- /**
124
- * Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing
125
- * nothing if it is already checked. Returns a void promise that indicates when the action is
126
- * complete.
127
- *
128
- * Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you
129
- * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method
130
- * might not have the expected result.
131
- */
132
- async check ( ) : Promise < void > {
133
- if ( ! ( await this . isChecked ( ) ) ) {
134
- await this . toggle ( ) ;
135
- }
136
- }
137
-
138
- /**
139
- * Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing
140
- * nothing if it is already unchecked. Returns a void promise that indicates when the action is
141
- * complete.
142
- *
143
- * Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you
144
- * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method
145
- * might not have the expected result.
146
- */
147
- async uncheck ( ) : Promise < void > {
148
- if ( await this . isChecked ( ) ) {
149
- await this . toggle ( ) ;
150
- }
151
- }
152
43
}
0 commit comments