Skip to content

Commit

Permalink
test: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeissonnier-pass committed Jan 9, 2025
1 parent a749372 commit d27489f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/features/auth/context/AuthContext.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('AuthContext', () => {

await act(async () => {})

expect(result.current.user).toBeUndefined()
expect(result.current).toBeNull()
})

it('should return the user when logged in with internet connection', async () => {
Expand Down
43 changes: 41 additions & 2 deletions src/libs/network/NetInfoWrapper.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// eslint-disable-next-line no-restricted-imports
import { NetInfoStateType } from '@react-native-community/netinfo'
import React from 'react'
import { View } from 'react-native'

import { analytics } from 'libs/analytics'
import { NetInfoWrapper, useNetInfoContext } from 'libs/network/NetInfoWrapper'
import { useNetInfo } from 'libs/network/useNetInfo'
import { render } from 'tests/utils'
import { useSplashScreenContext } from 'libs/splashscreen'
import { render, screen } from 'tests/utils'

const mockedUseNetInfo = useNetInfo as unknown as jest.Mock<{
isConnected: boolean
Expand All @@ -14,6 +16,10 @@ const mockedUseNetInfo = useNetInfo as unknown as jest.Mock<{
details?: Record<string, unknown>
}>

jest.mock('libs/splashscreen')
const mockUseSplashScreenContext = useSplashScreenContext as jest.Mock
mockUseSplashScreenContext.mockReturnValue({ isSplashScreenHidden: true })

describe('NetInfoWrapper', () => {
describe('useNetInfoContext', () => {
const onConnection = jest.fn()
Expand Down Expand Up @@ -137,6 +143,39 @@ describe('NetInfoWrapper', () => {

expect(analytics.logConnectionInfo).not.toHaveBeenCalled()
})

it('should display children if splashscreen is not visible and there is no network', () => {
mockedUseNetInfo.mockReturnValueOnce({
isConnected: false,
isInternetReachable: false,
type: NetInfoStateType.unknown,
})
renderNetInfoWrapper({
onInternetConnection,
onInternetConnectionLost,
onConnection,
onConnectionLost,
})

expect(screen.getByTestId('dumbComponent')).toBeOnTheScreen()
})

it('should not display children if splashscreen is visible and there is no network', () => {
mockUseSplashScreenContext.mockReturnValueOnce({ isSplashScreenHidden: false })
mockedUseNetInfo.mockReturnValueOnce({
isConnected: false,
isInternetReachable: false,
type: NetInfoStateType.unknown,
})
renderNetInfoWrapper({
onInternetConnection,
onInternetConnectionLost,
onConnection,
onConnectionLost,
})

expect(screen.queryByTestId('dumbComponent')).toBeNull()
})
})
})

Expand All @@ -160,7 +199,7 @@ const DumbComponent = ({
onInternetConnectionLost,
})

return null
return <View testID="dumbComponent" />
}

function renderNetInfoWrapper({
Expand Down

0 comments on commit d27489f

Please sign in to comment.