@@ -108,45 +108,83 @@ describe('PoCheckboxGroupComponent:', () => {
108
108
109
109
describe ( 'Methods:' , ( ) => {
110
110
111
- it ( 'focus : should call `focus` of checkbox ' , ( ) => {
112
- component . options = [ { label : 'teste1' , value : 'teste1' } , { label : 'teste2' , value : 'teste2' } ] ;
111
+ it ( 'ngAfterViewInit : should call `focus` if `autoFocus` is true. ' , ( ) => {
112
+ component . autoFocus = true ;
113
113
114
- changeDetector . detectChanges ( ) ;
114
+ const spyFocus = spyOn ( component , < any > 'focus' ) ;
115
115
116
- spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
116
+ component . ngAfterViewInit ( ) ;
117
117
118
- component . focus ( ) ;
118
+ expect ( spyFocus ) . toHaveBeenCalled ( ) ;
119
+ } ) ;
120
+
121
+ it ( 'ngAfterViewInit: shouldn´t call `focus` if `autoFocus` is false.' , ( ) => {
122
+ component . autoFocus = false ;
123
+
124
+ const spyFocus = spyOn ( component , < any > 'focus' ) ;
125
+
126
+ component . ngAfterViewInit ( ) ;
119
127
120
- expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . toHaveBeenCalled ( ) ;
128
+ expect ( spyFocus ) . not . toHaveBeenCalled ( ) ;
121
129
} ) ;
122
130
123
- it ( 'focus: should`t call `focus` of checkbox if option is `disabled`' , ( ) => {
124
- component . options = [ { label : 'teste1' , value : 'teste1' , disabled : true } , { label : 'teste2' , value : 'teste2' } ] ;
131
+ describe ( 'focus:' , ( ) => {
125
132
126
- changeDetector . detectChanges ( ) ;
133
+ it ( 'should call `focus` of checkbox.' , ( ) => {
134
+ component . options = [ { label : 'teste1' , value : 'teste1' } , { label : 'teste2' , value : 'teste2' } ] ;
127
135
128
- spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
129
- spyOn ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement , 'focus' ) ;
136
+ changeDetector . detectChanges ( ) ;
130
137
131
- component . focus ( ) ;
138
+ spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
132
139
133
- expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
134
- expect ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement . focus ) . toHaveBeenCalled ( ) ;
135
- } ) ;
140
+ component . focus ( ) ;
141
+
142
+ expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . toHaveBeenCalled ( ) ;
143
+ } ) ;
144
+
145
+ it ( 'shouldn`t call `focus` of checkbox if option is `disabled`.' , ( ) => {
146
+ component . options = [ { label : 'teste1' , value : 'teste1' , disabled : true } , { label : 'teste2' , value : 'teste2' } ] ;
147
+
148
+ changeDetector . detectChanges ( ) ;
149
+
150
+ spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
151
+ spyOn ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement , 'focus' ) ;
152
+
153
+ component . focus ( ) ;
136
154
137
- it ( 'focus: should`t call `focus` of checkbox if `disabled`' , ( ) => {
138
- component . options = [ { label : 'teste1' , value : 'teste1' , disabled : true } , { label : 'teste2' , value : 'teste2' } ] ;
139
- component . disabled = true ;
155
+ expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
156
+ expect ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement . focus ) . toHaveBeenCalled ( ) ;
157
+ } ) ;
158
+
159
+ it ( 'shouldn`t call `focus` if component is `disabled`.' , ( ) => {
160
+ component . options = [ { label : 'teste1' , value : 'teste1' } , { label : 'teste2' , value : 'teste2' } ] ;
161
+ component . disabled = true ;
140
162
141
- changeDetector . detectChanges ( ) ;
163
+ changeDetector . detectChanges ( ) ;
142
164
143
- spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
144
- spyOn ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement , 'focus' ) ;
165
+ spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
166
+ spyOn ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement , 'focus' ) ;
167
+
168
+ component . focus ( ) ;
169
+
170
+ expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
171
+ expect ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
172
+ } ) ;
145
173
146
- component . focus ( ) ;
174
+ it ( 'shouldn`t call `focus` if all checkboxes are `disabled`.' , ( ) => {
175
+ component . options = [ { label : 'teste1' , value : 'teste1' , disabled : true } , { label : 'teste2' , value : 'teste2' , disabled : true } ] ;
176
+
177
+ changeDetector . detectChanges ( ) ;
178
+
179
+ spyOn ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement , 'focus' ) ;
180
+ spyOn ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement , 'focus' ) ;
181
+
182
+ component . focus ( ) ;
183
+
184
+ expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
185
+ expect ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
186
+ } ) ;
147
187
148
- expect ( component . checkboxLabels . toArray ( ) [ 0 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
149
- expect ( component . checkboxLabels . toArray ( ) [ 1 ] . nativeElement . focus ) . not . toHaveBeenCalled ( ) ;
150
188
} ) ;
151
189
152
190
it ( 'trackByFn: should return index' , ( ) => {
0 commit comments