-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/new-md-styles
- Loading branch information
Showing
4 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/native/src/__tests__/createStaticNavigation.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { | ||
createNavigationContainerRef, | ||
createNavigatorFactory, | ||
type ParamListBase, | ||
StackRouter, | ||
TabRouter, | ||
useNavigationBuilder, | ||
} from '@react-navigation/core'; | ||
import { act, render, waitFor } from '@testing-library/react-native'; | ||
import * as React from 'react'; | ||
|
||
import { window } from '../__stubs__/window'; | ||
import { createStaticNavigation } from '../createStaticNavigation'; | ||
|
||
Object.assign(global, window); | ||
|
||
// We want to use the web version of useLinking | ||
// eslint-disable-next-line import/extensions | ||
jest.mock('../useLinking', () => require('../useLinking.tsx')); | ||
|
||
it('integrates with the history API', async () => { | ||
const createStackNavigator = createNavigatorFactory((props: any) => { | ||
const { state, descriptors, NavigationContent } = useNavigationBuilder( | ||
StackRouter, | ||
props | ||
); | ||
|
||
return ( | ||
<NavigationContent> | ||
{state.routes.map((route, i) => ( | ||
<div key={route.key} aria-current={state.index === i || undefined}> | ||
{descriptors[route.key].render()} | ||
</div> | ||
))} | ||
</NavigationContent> | ||
); | ||
}); | ||
|
||
const createTabNavigator = createNavigatorFactory((props: any) => { | ||
const { state, descriptors, NavigationContent } = useNavigationBuilder( | ||
TabRouter, | ||
props | ||
); | ||
|
||
return ( | ||
<NavigationContent> | ||
{state.routes.map((route, i) => ( | ||
<div key={route.key} aria-current={state.index === i || undefined}> | ||
{descriptors[route.key].render()} | ||
</div> | ||
))} | ||
</NavigationContent> | ||
); | ||
}); | ||
|
||
const TestScreen = ({ route }: any): any => | ||
`${route.name} ${JSON.stringify(route.params)}`; | ||
|
||
const Stack = createStackNavigator({ | ||
initialRouteName: 'Feed', | ||
screens: { | ||
Profile: { | ||
screen: TestScreen, | ||
linking: ':user', | ||
}, | ||
Settings: { | ||
screen: TestScreen, | ||
linking: 'edit', | ||
}, | ||
Updates: { | ||
screen: TestScreen, | ||
linking: 'updates', | ||
}, | ||
Feed: { | ||
screen: TestScreen, | ||
linking: 'feed', | ||
}, | ||
}, | ||
}); | ||
|
||
const Tab = createTabNavigator({ | ||
screens: { | ||
Home: Stack, | ||
Chat: { | ||
screen: TestScreen, | ||
linking: 'chat', | ||
}, | ||
}, | ||
}); | ||
|
||
const Navigation = createStaticNavigation(Tab); | ||
|
||
const navigation = createNavigationContainerRef<ParamListBase>(); | ||
|
||
render( | ||
<Navigation | ||
ref={navigation} | ||
linking={{ | ||
prefixes: [], | ||
}} | ||
/> | ||
); | ||
|
||
expect(window.location.pathname).toBe('/feed'); | ||
|
||
act(() => navigation.current?.navigate('Profile', { user: 'jane' })); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/jane')); | ||
|
||
act(() => navigation.current?.navigate('Updates')); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/updates')); | ||
|
||
act(() => navigation.current?.goBack()); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/jane')); | ||
|
||
act(() => { | ||
window.history.back(); | ||
}); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/feed')); | ||
|
||
act(() => { | ||
window.history.forward(); | ||
}); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/jane')); | ||
|
||
act(() => navigation.current?.navigate('Settings')); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/edit')); | ||
|
||
act(() => { | ||
window.history.go(-2); | ||
}); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/feed')); | ||
|
||
act(() => navigation.current?.navigate('Settings')); | ||
act(() => navigation.current?.navigate('Chat')); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/chat')); | ||
|
||
act(() => navigation.current?.navigate('Home')); | ||
|
||
await waitFor(() => expect(window.location.pathname).toBe('/edit')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters