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 { SlideToggleHarnessFilters } from '@angular/material/slide-toggle/testing' ;
9
+ import { HarnessPredicate } from '@angular/cdk/testing' ;
10
+ import {
11
+ _MatSlideToggleHarnessBase ,
12
+ SlideToggleHarnessFilters
13
+ } from '@angular/material/slide-toggle/testing' ;
12
14
13
15
14
16
/** Harness for interacting with a MDC-based mat-slide-toggle in tests. */
15
- export class MatSlideToggleHarness extends ComponentHarness {
17
+ export class MatSlideToggleHarness extends _MatSlideToggleHarnessBase {
16
18
static hostSelector = '.mat-mdc-slide-toggle' ;
17
19
18
20
/**
@@ -32,103 +34,10 @@ export class MatSlideToggleHarness extends ComponentHarness {
32
34
. addOption ( 'name' , options . name , async ( harness , name ) => await harness . getName ( ) === name ) ;
33
35
}
34
36
35
- private _label = this . locatorFor ( 'label' ) ;
36
- private _input = this . locatorFor ( 'input' ) ;
37
37
private _inputContainer = this . locatorFor ( '.mdc-switch' ) ;
38
38
39
- /** Gets a boolean promise indicating if the slide-toggle is checked. */
40
- async isChecked ( ) : Promise < boolean > {
41
- const checked = ( await this . _input ( ) ) . getProperty ( 'checked' ) ;
42
- return coerceBooleanProperty ( await checked ) ;
43
- }
44
-
45
- /** Gets a boolean promise indicating if the slide-toggle is disabled. */
46
- async isDisabled ( ) : Promise < boolean > {
47
- const disabled = ( await this . _input ( ) ) . getAttribute ( 'disabled' ) ;
48
- return coerceBooleanProperty ( await disabled ) ;
49
- }
50
-
51
- /** Gets a boolean promise indicating if the slide-toggle is required. */
52
- async isRequired ( ) : Promise < boolean > {
53
- const required = ( await this . _input ( ) ) . getAttribute ( 'required' ) ;
54
- return coerceBooleanProperty ( await required ) ;
55
- }
56
-
57
- /** Gets a boolean promise indicating if the slide-toggle is valid. */
58
- async isValid ( ) : Promise < boolean > {
59
- const invalid = ( await this . host ( ) ) . hasClass ( 'ng-invalid' ) ;
60
- return ! ( await invalid ) ;
61
- }
62
-
63
- /** Gets a promise for the slide-toggle's name. */
64
- async getName ( ) : Promise < string | null > {
65
- return ( await this . _input ( ) ) . getAttribute ( 'name' ) ;
66
- }
67
-
68
- /** Gets a promise for the slide-toggle's aria-label. */
69
- async getAriaLabel ( ) : Promise < string | null > {
70
- return ( await this . _input ( ) ) . getAttribute ( 'aria-label' ) ;
71
- }
72
-
73
- /** Gets a promise for the slide-toggle's aria-labelledby. */
74
- async getAriaLabelledby ( ) : Promise < string | null > {
75
- return ( await this . _input ( ) ) . getAttribute ( 'aria-labelledby' ) ;
76
- }
77
-
78
- /** Gets a promise for the slide-toggle's label text. */
79
- async getLabelText ( ) : Promise < string > {
80
- return ( await this . _label ( ) ) . text ( ) ;
81
- }
82
-
83
- /** Focuses the slide-toggle and returns a void promise that indicates action completion. */
84
- async focus ( ) : Promise < void > {
85
- return ( await this . _input ( ) ) . focus ( ) ;
86
- }
87
-
88
- /** Blurs the slide-toggle and returns a void promise that indicates action completion. */
89
- async blur ( ) : Promise < void > {
90
- return ( await this . _input ( ) ) . blur ( ) ;
91
- }
92
-
93
- /** Whether the slide-toggle is focused. */
94
- async isFocused ( ) : Promise < boolean > {
95
- return ( await this . _input ( ) ) . isFocused ( ) ;
96
- }
97
-
98
- /**
99
- * Toggle the checked state of the slide-toggle and returns a void promise that indicates when the
100
- * action is complete.
101
- *
102
- * Note: This attempts to toggle the slide-toggle as a user would, by clicking it.
103
- */
104
39
async toggle ( ) : Promise < void > {
105
40
const elToClick = await this . isDisabled ( ) ? this . _inputContainer ( ) : this . _input ( ) ;
106
41
return ( await elToClick ) . click ( ) ;
107
42
}
108
-
109
- /**
110
- * Puts the slide-toggle in a checked state by toggling it if it is currently unchecked, or doing
111
- * nothing if it is already checked. Returns a void promise that indicates when the action is
112
- * complete.
113
- *
114
- * Note: This attempts to check the slide-toggle as a user would, by clicking it.
115
- */
116
- async check ( ) : Promise < void > {
117
- if ( ! ( await this . isChecked ( ) ) ) {
118
- await this . toggle ( ) ;
119
- }
120
- }
121
-
122
- /**
123
- * Puts the slide-toggle in an unchecked state by toggling it if it is currently checked, or doing
124
- * nothing if it is already unchecked. Returns a void promise that indicates when the action is
125
- * complete.
126
- *
127
- * Note: This attempts to uncheck the slide-toggle as a user would, by clicking it.
128
- */
129
- async uncheck ( ) : Promise < void > {
130
- if ( await this . isChecked ( ) ) {
131
- await this . toggle ( ) ;
132
- }
133
- }
134
43
}
0 commit comments