|
1 | 1 | import React from 'react'; |
2 | | -import { Text } from 'react-native'; |
| 2 | +import { Text, View } from 'react-native'; |
3 | 3 | import TestRenderer from 'react-test-renderer'; |
4 | 4 | import { Canal } from '../Canal'; |
5 | 5 | import { Screen } from '../Screen'; |
6 | 6 | import { Subject } from 'rxjs'; |
7 | 7 | import { BackEvent } from '../Navigation/BackHandlerDelegate'; |
8 | 8 | import { BackContext } from '../Navigation/BackContext'; |
| 9 | +import { Navigation } from '../Navigation'; |
9 | 10 |
|
10 | 11 | describe('Canal', () => { |
11 | 12 | it('renders its children', () => { |
@@ -34,6 +35,47 @@ describe('Canal', () => { |
34 | 35 | ); |
35 | 36 | expect(testRenderer.toJSON()).toMatchSnapshot(); |
36 | 37 | }); |
| 38 | + it('notifies the fullScreenDelegate of the full-screen screens after any render', () => { |
| 39 | + const spy = jest.spyOn( |
| 40 | + Navigation.instance.fullScreenDelegate.canalsFullScreenStackProperties$, |
| 41 | + 'next' |
| 42 | + ); |
| 43 | + const ScreenB = <Screen Component={() => <Text>b</Text>} name="b" visible isFullScreen />; |
| 44 | + const testRenderer = TestRenderer.create( |
| 45 | + <Canal> |
| 46 | + <Screen Component={() => <Text>a</Text>} name="a" visible /> |
| 47 | + {ScreenB} |
| 48 | + </Canal> |
| 49 | + ); |
| 50 | + expect(spy).toHaveBeenCalledWith({ canalId: '0', fullScreenStack: [ScreenB] }); |
| 51 | + const ScreenC = ( |
| 52 | + <Screen Component={() => <Text>c</Text>} name="c" visible={false} isFullScreen /> |
| 53 | + ); |
| 54 | + testRenderer.update( |
| 55 | + <Canal> |
| 56 | + <Screen Component={() => <Text>a</Text>} name="a" visible /> |
| 57 | + {ScreenC} |
| 58 | + </Canal> |
| 59 | + ); |
| 60 | + expect(spy).toHaveBeenCalledWith({ canalId: '0', fullScreenStack: [ScreenC] }); |
| 61 | + }); |
| 62 | + it('notifies the fullScreenDelegate on unmount', () => { |
| 63 | + const spy = jest.spyOn( |
| 64 | + Navigation.instance.fullScreenDelegate.canalsFullScreenStackProperties$, |
| 65 | + 'next' |
| 66 | + ); |
| 67 | + const ScreenB = <Screen Component={() => <Text>b</Text>} name="b" visible isFullScreen />; |
| 68 | + const testRenderer = TestRenderer.create( |
| 69 | + <Canal> |
| 70 | + <Screen Component={() => <Text>a</Text>} name="a" visible /> |
| 71 | + {ScreenB} |
| 72 | + </Canal> |
| 73 | + ); |
| 74 | + expect(spy).not.toHaveBeenCalledWith({ canalId: '0', fullScreenStack: [] }); |
| 75 | + expect(spy).toHaveBeenCalledWith({ canalId: '0', fullScreenStack: [ScreenB] }); |
| 76 | + testRenderer.update(<View></View>); |
| 77 | + expect(spy).toHaveBeenCalledWith({ canalId: '0', fullScreenStack: [] }); |
| 78 | + }); |
37 | 79 | it('passes back events on', () => { |
38 | 80 | const back$ = new Subject<BackEvent>(); |
39 | 81 | const spy = jest.fn(); |
|
0 commit comments