@@ -91,7 +91,7 @@ describe('NgxSmartModalService', () => {
9191
9292 it ( 'should add events ( _private and no browser )' , inject ( [ NgxSmartModalService ] , ( service : NgxSmartModalService ) => {
9393 spyOnProperty ( service as any , 'isBrowser' , 'get' ) . and . returnValue ( false ) ;
94-
94+
9595 expect ( ( service as any ) . _addEvents ( ) ) . toBeFalsy ( ) ;
9696 } ) ) ;
9797
@@ -413,4 +413,48 @@ describe('NgxSmartModalService', () => {
413413 tick ( 500 ) ;
414414 expect ( ( service as any ) . _trapFocusModal ( event ) ) . toBeFalsy ( ) ;
415415 } ) ) ) ;
416+
417+ it ( 'should closeAll' , fakeAsync ( inject ( [ NgxSmartModalService ] , ( service : NgxSmartModalService ) => {
418+ const firstFixture = TestBed . createComponent ( NgxSmartModalComponent ) ;
419+ const secFixture = TestBed . createComponent ( NgxSmartModalComponent ) ;
420+ const thirdFixture = TestBed . createComponent ( NgxSmartModalComponent ) ;
421+ const firstApp = firstFixture . debugElement . componentInstance ;
422+ const secApp = secFixture . debugElement . componentInstance ;
423+ const thirdApp = thirdFixture . debugElement . componentInstance ;
424+
425+ firstApp . identifier = 'myFirstModal' ;
426+ secApp . identifier = 'mySecModal' ;
427+ thirdApp . identifier = 'myThirdModal' ;
428+
429+ service . addModal ( { id : 'myFirstModal' , modal : firstApp } ) ;
430+ service . addModal ( { id : 'mySecModal' , modal : secApp } ) ;
431+ service . addModal ( { id : 'myThirdModal' , modal : thirdApp } ) ;
432+
433+ spyOn ( service , 'closeAll' ) . and . callThrough ( ) ;
434+ spyOn ( service , 'getOpenedModals' ) . and . callThrough ( ) ;
435+ spyOn ( service as any , '_closeModal' ) . and . callThrough ( ) ;
436+
437+ service . open ( firstApp . identifier ) ;
438+ service . open ( secApp . identifier ) ;
439+ service . open ( thirdApp . identifier ) ;
440+
441+ expect ( firstApp . visible ) . toBeTruthy ( ) ;
442+ expect ( secApp . visible ) . toBeTruthy ( ) ;
443+ expect ( thirdApp . visible ) . toBeTruthy ( ) ;
444+
445+ tick ( 501 ) ;
446+
447+ service . closeAll ( ) ;
448+
449+ tick ( 501 ) ;
450+
451+ expect ( service . closeAll ) . toHaveBeenCalled ( ) ;
452+ expect ( service . getOpenedModals ) . toHaveBeenCalled ( ) ;
453+ expect ( service [ '_closeModal' ] ) . toHaveBeenCalledWith ( firstApp ) ;
454+ expect ( service [ '_closeModal' ] ) . toHaveBeenCalledWith ( secApp ) ;
455+ expect ( service [ '_closeModal' ] ) . toHaveBeenCalledWith ( thirdApp ) ;
456+ expect ( firstApp . visible ) . toBeFalsy ( ) ;
457+ expect ( secApp . visible ) . toBeFalsy ( ) ;
458+ expect ( thirdApp . visible ) . toBeFalsy ( ) ;
459+ } ) ) ) ;
416460} ) ;
0 commit comments