@@ -3,7 +3,7 @@ import { NgModule, Component, ViewContainerRef, NO_ERRORS_SCHEMA } from '@angula
33import { Page , Frame , isIOS } from '@nativescript/core' ;
44import { ModalDialogParams , ModalDialogService } from '@nativescript/angular' ;
55
6- import { ComponentFixture , TestBed , async , waitForAsync } from '@angular/core/testing' ;
6+ import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
77import { nsTestBedRender , nsTestBedAfterEach , nsTestBedBeforeEach , NATIVESCRIPT_TESTING_PROVIDERS , NativeScriptTestingModule } from '@nativescript/angular/testing' ;
88import { NSLocationStrategy , Outlet } from '@nativescript/angular' ;
99import { FrameService } from '@nativescript/angular' ;
@@ -45,7 +45,12 @@ export class FailComponent {
4545 </GridLayout>` ,
4646} )
4747export class SuccessComponent {
48- constructor ( public service : ModalDialogService , public vcRef : ViewContainerRef , public locationStrategy : NSLocationStrategy , public fakeFrameService : FrameService ) { }
48+ constructor (
49+ public service : ModalDialogService ,
50+ public vcRef : ViewContainerRef ,
51+ public locationStrategy : NSLocationStrategy ,
52+ public fakeFrameService : FrameService ,
53+ ) { }
4954}
5055
5156@NgModule ( {
@@ -89,64 +94,55 @@ describe('modal-dialog', () => {
8994 }
9095 } ) ;
9196
92- it (
93- 'showModal does not throws when there is no viewContainer provided' ,
94- waitForAsync ( async ( ) => {
95- const fixture = TestBed . createComponent ( FailComponent ) ;
96- const service = < ModalDialogService > fixture . componentRef . instance . service ;
97- await fixture . whenRenderingDone ( ) ;
98- // expect(() => service.showModal(ModalComponent, {})).toThrow("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
99- expect ( ( ) => service . showModal ( ModalComponent , { } ) ) . not . toThrow ( ) ;
100- } )
101- ) ;
102-
103- it (
104- 'showModal succeeds when there is viewContainer provided' ,
105- waitForAsync ( async ( ) => {
106- const fixture = TestBed . createComponent ( SuccessComponent ) ;
107- const service = fixture . componentRef . instance . service ;
108- const locStrategy = fixture . componentRef . instance . locationStrategy ;
109- await fixture . whenRenderingDone ( ) ;
110- const outlet = new Outlet ( 'primary' , null , 'primary' , 0 ) ;
111- let parentView = fixture . componentRef . instance . vcRef . element . nativeElement ;
112- parentView = parentView . page && parentView . page . frame ;
113- outlet . frames . push ( parentView ) ;
114- locStrategy . _getOutlets ( ) . push ( outlet ) ;
115-
116- locStrategy . pushState ( null , 'test' , '/test' , null ) ;
117-
118- const comp = fixture . componentRef . instance ;
119- service . showModal ( ModalComponent , { viewContainerRef : comp . vcRef } ) . catch ( ( e ) => fail ( e ) ) ;
120- } )
121- ) ;
122-
123- it (
124- 'showModal passes modal params and gets result when resolved' ,
125- waitForAsync ( async ( ) => {
126- const context = { property : 'my context' } ;
127- const fixture = TestBed . createComponent ( SuccessComponent ) ;
128-
129- const service = < ModalDialogService > fixture . componentRef . instance . service ;
130- const locStrategy = < NSLocationStrategy > fixture . componentRef . instance . locationStrategy ;
131- const outlet = new Outlet ( 'primary' , null , 'primary' , 0 ) ;
132-
133- let parentView = fixture . componentRef . instance . vcRef . element . nativeElement ;
134- parentView = parentView . page && parentView . page . frame ;
135- outlet . frames . push ( parentView ) ;
136- locStrategy . _getOutlets ( ) . push ( outlet ) ;
137-
138- locStrategy . pushState ( null , 'test' , '/test' , null ) ;
139-
140- const comp = < SuccessComponent > fixture . componentRef . instance ;
141- service
142- . showModal ( ModalComponent , {
143- viewContainerRef : comp . vcRef ,
144- context : context ,
145- } )
146- . then ( ( res ) => {
147- expect ( res ) . toEqual ( context ) ;
148- } )
149- . catch ( ( e ) => fail ( e ) ) ;
150- } )
151- ) ;
97+ it ( 'showModal does not throws when there is no viewContainer provided' , waitForAsync ( async ( ) => {
98+ const fixture = TestBed . createComponent ( FailComponent ) ;
99+ const service = < ModalDialogService > fixture . componentRef . instance . service ;
100+ await fixture . whenRenderingDone ( ) ;
101+ // expect(() => service.showModal(ModalComponent, {})).toThrow("No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions.");
102+ expect ( ( ) => service . showModal ( ModalComponent , { } ) ) . not . toThrow ( ) ;
103+ } ) ) ;
104+
105+ it ( 'showModal succeeds when there is viewContainer provided' , waitForAsync ( async ( ) => {
106+ const fixture = TestBed . createComponent ( SuccessComponent ) ;
107+ const service = fixture . componentRef . instance . service ;
108+ const locStrategy = fixture . componentRef . instance . locationStrategy ;
109+ await fixture . whenRenderingDone ( ) ;
110+ const outlet = new Outlet ( 'primary' , null , 'primary' , 0 ) ;
111+ let parentView = fixture . componentRef . instance . vcRef . element . nativeElement ;
112+ parentView = parentView . page && parentView . page . frame ;
113+ outlet . frames . push ( parentView ) ;
114+ locStrategy . _getOutlets ( ) . push ( outlet ) ;
115+
116+ locStrategy . pushState ( null , 'test' , '/test' , null ) ;
117+
118+ const comp = fixture . componentRef . instance ;
119+ service . showModal ( ModalComponent , { viewContainerRef : comp . vcRef } ) . catch ( ( e ) => fail ( e ) ) ;
120+ } ) ) ;
121+
122+ it ( 'showModal passes modal params and gets result when resolved' , waitForAsync ( async ( ) => {
123+ const context = { property : 'my context' } ;
124+ const fixture = TestBed . createComponent ( SuccessComponent ) ;
125+
126+ const service = < ModalDialogService > fixture . componentRef . instance . service ;
127+ const locStrategy = < NSLocationStrategy > fixture . componentRef . instance . locationStrategy ;
128+ const outlet = new Outlet ( 'primary' , null , 'primary' , 0 ) ;
129+
130+ let parentView = fixture . componentRef . instance . vcRef . element . nativeElement ;
131+ parentView = parentView . page && parentView . page . frame ;
132+ outlet . frames . push ( parentView ) ;
133+ locStrategy . _getOutlets ( ) . push ( outlet ) ;
134+
135+ locStrategy . pushState ( null , 'test' , '/test' , null ) ;
136+
137+ const comp = < SuccessComponent > fixture . componentRef . instance ;
138+ service
139+ . showModal ( ModalComponent , {
140+ viewContainerRef : comp . vcRef ,
141+ context : context ,
142+ } )
143+ . then ( ( res ) => {
144+ expect ( res ) . toEqual ( context ) ;
145+ } )
146+ . catch ( ( e ) => fail ( e ) ) ;
147+ } ) ) ;
152148} ) ;
0 commit comments