Skip to content

Commit 42b3fc1

Browse files
committed
✅ (package) 100% cover new API
1 parent 072b104 commit 42b3fc1

File tree

13 files changed

+421
-595
lines changed

13 files changed

+421
-595
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
'@typescript-eslint/explicit-function-return-type': 'off',
1919
'@typescript-eslint/explicit-member-accessibility': 'off',
2020
'@typescript-eslint/no-explicit-any': 'off',
21+
'@typescript-eslint/no-empty-interface': 'off',
2122
},
2223
settings: {
2324
react: {

src/FullScreenPortal.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import React, { Component, Fragment } from 'react';
22
import { View, StyleSheet } from 'react-native';
3-
import { from } from 'rxjs';
3+
4+
/**
5+
* import order is important between recompose and rxjs
6+
* @see https://stackoverflow.com/questions/53878650/you-provided-an-invalid-object-where-a-stream-was-expected-when-using-rxjs6-an.
7+
*/
48
import { componentFromStreamWithConfig } from 'recompose';
9+
import { from } from 'rxjs';
510

611
import { Navigation } from './Navigation';
712
import { map, publish, withLatestFrom } from 'rxjs/operators';
813
import { withBackContext, WithBackContext } from './withBackContext';
914
import { BackContext } from './Navigation/BackContext';
1015
import { last } from './utils/Array.last';
1116

12-
class FullScreenPortalComponent extends Component<WithBackContext<{}>> {
17+
interface Props {}
18+
19+
class FullScreenPortalComponent extends Component<WithBackContext<Props>> {
1320
static FullScreenStack = componentFromStreamWithConfig({
1421
fromESObservable: from,
1522
toESObservable: stream => stream,

src/__tests__/Canal.test.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
2-
import { Text } from 'react-native';
2+
import { Text, View } from 'react-native';
33
import TestRenderer from 'react-test-renderer';
44
import { Canal } from '../Canal';
55
import { Screen } from '../Screen';
66
import { Subject } from 'rxjs';
77
import { BackEvent } from '../Navigation/BackHandlerDelegate';
88
import { BackContext } from '../Navigation/BackContext';
9+
import { Navigation } from '../Navigation';
910

1011
describe('Canal', () => {
1112
it('renders its children', () => {
@@ -34,6 +35,47 @@ describe('Canal', () => {
3435
);
3536
expect(testRenderer.toJSON()).toMatchSnapshot();
3637
});
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+
});
3779
it('passes back events on', () => {
3880
const back$ = new Subject<BackEvent>();
3981
const spy = jest.fn();
Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,80 @@
11
import React from 'react';
22
import TestRenderer from 'react-test-renderer';
33

4+
/**
5+
* import order is important between recompose and rxjs
6+
* @see https://stackoverflow.com/questions/53878650/you-provided-an-invalid-object-where-a-stream-was-expected-when-using-rxjs6-an.
7+
*/
8+
import 'recompose';
9+
import { Subject } from 'rxjs';
10+
import { View, Text } from 'react-native';
11+
412
import { FullScreenPortal } from '../FullScreenPortal';
13+
import { Navigation } from '../Navigation';
14+
import { BackEvent } from '../Navigation/BackHandlerDelegate';
15+
import { BackContext } from '../Navigation/BackContext';
16+
import { Canal } from '../Canal';
17+
import { Screen } from '../Screen';
518

619
describe('FullScreenPortal', () => {
720
it('renders the full screen portal', () => {
8-
const testRenderer = TestRenderer.create(<FullScreenPortal />);
21+
const testRenderer = TestRenderer.create(
22+
<FullScreenPortal>
23+
<View></View>
24+
</FullScreenPortal>
25+
);
26+
expect(testRenderer.toJSON()).toMatchSnapshot();
27+
});
28+
29+
it('renders the full screen screens', () => {
30+
const testRenderer = TestRenderer.create(
31+
<FullScreenPortal>
32+
<View></View>
33+
</FullScreenPortal>
34+
);
35+
Navigation.instance.fullScreenDelegate.canalsFullScreenStackProperties$.next({
36+
canalId: '1',
37+
fullScreenStack: [
38+
<View key="a">
39+
<Text>I should be rendered</Text>
40+
</View>,
41+
],
42+
});
943
expect(testRenderer.toJSON()).toMatchSnapshot();
1044
});
45+
46+
it('passes on back events', () => {
47+
const back$ = new Subject<BackEvent>();
48+
const spy = jest.fn();
49+
const testRenderer = TestRenderer.create(
50+
<BackContext.Provider value={{ back$ }}>
51+
<FullScreenPortal>
52+
<Canal>
53+
<Screen Component={() => <Text>a</Text>} name="a" visible isFullScreen />
54+
</Canal>
55+
</FullScreenPortal>
56+
</BackContext.Provider>
57+
);
58+
// @ts-ignore
59+
testRenderer.root.children[0].instance.back$.subscribe(spy);
60+
back$.next({ target: null });
61+
expect(spy).toHaveBeenCalledWith({
62+
target: 'a',
63+
});
64+
testRenderer.update(
65+
<BackContext.Provider value={{ back$ }}>
66+
<FullScreenPortal>
67+
<Canal>
68+
<Screen Component={() => <Text>a</Text>} name="a" visible />
69+
</Canal>
70+
</FullScreenPortal>
71+
</BackContext.Provider>
72+
);
73+
// @ts-ignore
74+
testRenderer.root.children[0].instance.back$.subscribe(spy);
75+
back$.next({ target: null });
76+
expect(spy).toHaveBeenCalledWith({
77+
target: null,
78+
});
79+
});
1180
});

src/__tests__/__snapshots__/FullScreenPortal.test.tsx.snap

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,28 @@ exports[`FullScreenPortal renders the full screen portal 1`] = `
1111
"top": 0,
1212
}
1313
}
14-
/>
14+
>
15+
<View />
16+
</View>
17+
`;
18+
19+
exports[`FullScreenPortal renders the full screen screens 1`] = `
20+
<View
21+
style={
22+
Object {
23+
"bottom": 0,
24+
"left": 0,
25+
"position": "absolute",
26+
"right": 0,
27+
"top": 0,
28+
}
29+
}
30+
>
31+
<View />
32+
<View>
33+
<Text>
34+
I should be rendered
35+
</Text>
36+
</View>
37+
</View>
1538
`;

src/__tests__/__snapshots__/createCanal.test.tsx.snap

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)