55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
/**
|
|
* App entry redirect (app/index.tsx) — real router.
|
|
*
|
|
* This file must NOT mock expo-router (the real router is the point).
|
|
*/
|
|
|
|
import React from 'react'
|
|
import { ActivityIndicator, Text } from 'react-native'
|
|
import { screen, waitFor } from '@testing-library/react-native'
|
|
|
|
import Index from '@/app/index'
|
|
import { resetStorage, setupApiMocks } from '../mocks/api'
|
|
import { authMock, resetAuthMock } from '../mocks/auth'
|
|
import { Providers } from '../helpers/render'
|
|
import { renderRoute } from '../helpers/real-router'
|
|
|
|
const HomeStub = () => <Text testID="home-screen">home</Text>
|
|
|
|
/** Index renders AppContainer, which needs the refresh context. */
|
|
const IndexRoute = () => (
|
|
<Providers centralStores={false}>
|
|
<Index />
|
|
</Providers>
|
|
)
|
|
|
|
const ROUTES = {
|
|
index: IndexRoute,
|
|
'(drawer)/(tabs)/home/index': HomeStub,
|
|
}
|
|
|
|
describe('App entry', () => {
|
|
beforeEach(async () => {
|
|
resetAuthMock()
|
|
setupApiMocks()
|
|
await resetStorage()
|
|
})
|
|
|
|
it('redirects to the home route once auth has settled', async () => {
|
|
const nav = renderRoute(ROUTES, '/')
|
|
|
|
await screen.findByTestId('home-screen')
|
|
expect(nav.getPathname()).toBe('/home')
|
|
})
|
|
|
|
it('stays on the entry route and shows a spinner while auth loads', async () => {
|
|
authMock.isLoading = true
|
|
const nav = renderRoute(ROUTES, '/')
|
|
|
|
await waitFor(() =>
|
|
expect(screen.UNSAFE_queryByType(ActivityIndicator)).not.toBeNull()
|
|
)
|
|
expect(screen.queryByTestId('home-screen')).toBeNull()
|
|
expect(nav.getPathname()).toBe('/')
|
|
})
|
|
})
|