@@ -28,9 +28,9 @@ describe('PoMultiselectBaseComponent:', () => {
28
28
expectSettersMethod ( component , 'required' , 'undefined' , 'required' , false ) ;
29
29
expectSettersMethod ( component , 'required' , undefined , 'required' , false ) ;
30
30
31
- spyOn ( component , 'updateModelToValidate ') ;
31
+ spyOn ( component , < any > 'validateModel ') ;
32
32
component . disabled = true ;
33
- expect ( component . updateModelToValidate ) . toHaveBeenCalled ( ) ;
33
+ expect ( component [ 'validateModel' ] ) . toHaveBeenCalled ( ) ;
34
34
} ) ;
35
35
36
36
it ( 'should set disabled' , ( ) => {
@@ -42,10 +42,10 @@ describe('PoMultiselectBaseComponent:', () => {
42
42
expectSettersMethod ( component , 'disabled' , 'undefined' , 'disabled' , false ) ;
43
43
expectSettersMethod ( component , 'disabled' , undefined , 'disabled' , false ) ;
44
44
45
- spyOn ( component , 'updateModelToValidate ') ;
45
+ spyOn ( component , < any > 'validateModel ') ;
46
46
spyOn ( component , 'updateVisibleItems' ) ;
47
47
component . disabled = true ;
48
- expect ( component . updateModelToValidate ) . toHaveBeenCalled ( ) ;
48
+ expect ( component [ 'validateModel' ] ) . toHaveBeenCalled ( ) ;
49
49
expect ( component . updateVisibleItems ) . toHaveBeenCalled ( ) ;
50
50
} ) ;
51
51
@@ -107,12 +107,6 @@ describe('PoMultiselectBaseComponent:', () => {
107
107
expect ( component . updateList ) . toHaveBeenCalledWith ( [ ] ) ;
108
108
} ) ;
109
109
110
- it ( 'should set variable readyToValidation to true' , ( ) => {
111
- component [ 'readyToValidation' ] = false ;
112
- component . ngAfterContentChecked ( ) ;
113
- expect ( component [ 'readyToValidation' ] ) . toBeTruthy ( ) ;
114
- } ) ;
115
-
116
110
it ( 'should call validation functions and sort function' , ( ) => {
117
111
component . options = [ { label : '1' , value : 1 } ] ;
118
112
component . sort = true ;
@@ -177,25 +171,6 @@ describe('PoMultiselectBaseComponent:', () => {
177
171
expect ( component . visibleOptionsDropdown . length ) . toBe ( 1 ) ;
178
172
} ) ;
179
173
180
- it ( 'should call method callOnChange with selectedOptions' , fakeAsync ( ( ) => {
181
- component [ 'readyToValidation' ] = true ;
182
- component [ 'selectedOptions' ] = [ ] ;
183
- spyOn ( component , 'callOnChange' ) ;
184
- component . updateModelToValidate ( ) ;
185
-
186
- tick ( 100 ) ;
187
- expect ( component . callOnChange ) . toHaveBeenCalledWith ( [ ] ) ;
188
- } ) ) ;
189
-
190
- it ( 'shouldn`t call method callOnChange' , fakeAsync ( ( ) => {
191
- component [ 'readyToValidation' ] = false ;
192
- spyOn ( component , 'callOnChange' ) ;
193
- component . updateModelToValidate ( ) ;
194
-
195
- tick ( 100 ) ;
196
- expect ( component . callOnChange ) . not . toHaveBeenCalled ( ) ;
197
- } ) ) ;
198
-
199
174
it ( 'should call onModelChange and eventChange' , ( ) => {
200
175
const fakeThis = {
201
176
onModelChange : v => { } ,
@@ -343,16 +318,6 @@ describe('PoMultiselectBaseComponent:', () => {
343
318
expect ( component . selectedOptions . length ) . toBe ( 1 ) ;
344
319
} ) ;
345
320
346
- it ( 'should call `callOnChange` and `updateSelectedOptions` with `[]` if model value is `invalid`.' , ( ) => {
347
- spyOn ( component , 'updateSelectedOptions' ) ;
348
- spyOn ( component , 'callOnChange' ) ;
349
-
350
- component . writeValue ( null ) ;
351
-
352
- expect ( component . updateSelectedOptions ) . toHaveBeenCalledWith ( [ ] ) ;
353
- expect ( component . callOnChange ) . toHaveBeenCalledWith ( [ ] ) ;
354
- } ) ;
355
-
356
321
it ( 'should update model if the values is different of the selectedOptions.' , ( ) => {
357
322
component . selectedOptions = [ ] ;
358
323
component . options = [ { value : 1 , label : '1' } , { value : 2 , label : '2' } ] ;
@@ -401,6 +366,39 @@ describe('PoMultiselectBaseComponent:', () => {
401
366
component . eventChange ( [ { value : 1 , label : '1' } ] ) ;
402
367
expect ( component . change . emit ) . not . toHaveBeenCalled ( ) ;
403
368
} ) ;
369
+
370
+ it ( 'registerOnValidatorChange: should register validatorChange function' , ( ) => {
371
+ const registerOnValidatorChangeFn = ( ) => { } ;
372
+
373
+ component . registerOnValidatorChange ( registerOnValidatorChangeFn ) ;
374
+ expect ( component [ 'validatorChange' ] ) . toBe ( registerOnValidatorChangeFn ) ;
375
+ } ) ;
376
+
377
+ it ( 'validateModel: shouldn`t call `validatorChange` when it is falsy' , ( ) => {
378
+ component [ 'validatorChange' ] = undefined ;
379
+
380
+ component [ 'validateModel' ] ( ) ;
381
+
382
+ expect ( component [ 'validatorChange' ] ) . toBeUndefined ( ) ;
383
+ } ) ;
384
+
385
+ it ( 'validateModel: should call `validatorChange` to validateModel when `validatorChange` is a function' , ( ) => {
386
+ component [ 'validatorChange' ] = ( ) => { } ;
387
+
388
+ spyOn ( component , < any > 'validatorChange' ) ;
389
+
390
+ component [ 'validateModel' ] ( ) ;
391
+
392
+ expect ( component [ 'validatorChange' ] ) . toHaveBeenCalledWith ( ) ;
393
+ } ) ;
394
+
395
+ it ( 'writeValue: should call `updateSelectedOptions` with `[]` if model value is `invalid`.' , ( ) => {
396
+ spyOn ( component , 'updateSelectedOptions' ) ;
397
+
398
+ component . writeValue ( null ) ;
399
+
400
+ expect ( component . updateSelectedOptions ) . toHaveBeenCalledWith ( [ ] ) ;
401
+ } ) ;
404
402
} ) ;
405
403
406
404
describe ( 'Properties:' , ( ) => {
0 commit comments