license import { asapScheduler , concat , Observable , of , range } from 'rxjs' ; import { concatAll , concatMap , concatMapTo , map } from 'rxjs/operators' ; import { asyncTest } from '../test-util' ; describe ( 'Observable instance method concat' , ( ) => { let log ; const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const constructorZone3 = Zone . current . fork ( { name : 'Constructor Zone3' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; let observable1 ; let observable2 ; let concatObservable ; beforeEach ( ( ) => { log = [ ] ; } ) ; it ( 'concat func callback should run in the correct zone' , ( ) => { observable1 = constructorZone1 . run ( ( ) => { return new Observable ( subscriber => { expect ( Zone . current . name ) . toEqual ( constructorZone1 . name ) ; subscriber . next ( 1 ) ; subscriber . next ( 2 ) ; subscriber . complete ( ) ; } ) ; } ) ; observable2 = constructorZone2 . run ( ( ) => { return range ( 3 , 4 ) ; } ) ; constructorZone3 . run ( ( ) => { concatObservable = concat ( observable1 , observable2 ) ; } ) ; subscriptionZone . run ( ( ) => { concatObservable . subscribe ( ( concat ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( concat ) ; } ) ; } ) ; expect ( log ) . toEqual ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ; } ) ; xit ( 'concat func callback should run in the correct zone with scheduler' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const constructorZone3 = Zone . current . fork ( { name : 'Constructor Zone3' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return of ( 1 , 2 ) ; } ) ; observable2 = constructorZone2 . run ( ( ) => { return range ( 3 , 4 ) ; } ) ; constructorZone3 . run ( ( ) => { concatObservable = concat ( observable1 , observable2 , asapScheduler ) ; } ) ; subscriptionZone . run ( ( ) => { concatObservable . subscribe ( ( concat ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( concat ) ; } , ( error ) => { fail ( 'subscribe failed' + error ) ; } , ( ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ; done ( ) ; } ) ; } ) ; expect ( log ) . toEqual ( [ ] ) ; } , Zone . root ) ) ; it ( 'concatAll func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return of ( 0 , 1 , 2 ) ; } ) ; constructorZone2 . run ( ( ) => { const highOrder = observable1 . pipe ( map ( ( v ) => { expect ( Zone . current . name ) . toEqual ( constructorZone2 . name ) ; return of ( v + 1 ) ; } ) ) ; concatObservable = highOrder . pipe ( concatAll ( ) ) ; } ) ; subscriptionZone . run ( ( ) => { concatObservable . subscribe ( ( concat ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( concat ) ; } , ( error ) => { fail ( 'subscribe failed' + error ) ; } , ( ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 1 , 2 , 3 ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; it ( 'concatMap func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return new Observable ( subscriber => { expect ( Zone . current . name ) . toEqual ( constructorZone1 . name ) ; subscriber . next ( 1 ) ; subscriber . next ( 2 ) ; subscriber . next ( 3 ) ; subscriber . next ( 4 ) ; subscriber . complete ( ) ; } ) ; } ) ; constructorZone2 . run ( ( ) => { concatObservable = observable1 . pipe ( concatMap ( ( v ) => { expect ( Zone . current . name ) . toEqual ( constructorZone2 . name ) ; return of ( 0 , 1 ) ; } ) ) ; } ) ; subscriptionZone . run ( ( ) => { concatObservable . subscribe ( ( concat ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( concat ) ; } , ( error ) => { fail ( 'subscribe failed' + error ) ; } , ( ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; it ( 'concatMapTo func callback should run in the correct zone' , asyncTest ( ( done ) => { const constructorZone1 = Zone . current . fork ( { name : 'Constructor Zone1' } ) ; const constructorZone2 = Zone . current . fork ( { name : 'Constructor Zone2' } ) ; const subscriptionZone = Zone . current . fork ( { name : 'Subscription Zone' } ) ; observable1 = constructorZone1 . run ( ( ) => { return new Observable ( subscriber => { expect ( Zone . current . name ) . toEqual ( constructorZone1 . name ) ; subscriber . next ( 1 ) ; subscriber . next ( 2 ) ; subscriber . next ( 3 ) ; subscriber . next ( 4 ) ; subscriber . complete ( ) ; } ) ; } ) ; constructorZone2 . run ( ( ) => { concatObservable = observable1 . pipe ( concatMapTo ( of ( 0 , 1 ) ) ) ; } ) ; subscriptionZone . run ( ( ) => { concatObservable . subscribe ( ( concat ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; log . push ( concat ) ; } , ( error ) => { fail ( 'subscribe failed' + error ) ; } , ( ) => { expect ( Zone . current . name ) . toEqual ( subscriptionZone . name ) ; expect ( log ) . toEqual ( [ 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 ] ) ; done ( ) ; } ) ; } ) ; } , Zone . root ) ) ; } ) ;