From d27489f69345f0ded5fea0c091bcab1c6c0ed2cc Mon Sep 17 00:00:00 2001 From: Mathieu Meissonnier <173043140+mmeissonnier-pass@users.noreply.github.com> Date: Tue, 24 Dec 2024 14:19:21 +0100 Subject: [PATCH] test: fix failing tests --- .../auth/context/AuthContext.native.test.tsx | 2 +- .../network/NetInfoWrapper.native.test.tsx | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/features/auth/context/AuthContext.native.test.tsx b/src/features/auth/context/AuthContext.native.test.tsx index 7769eae700c..f46bd2c3070 100644 --- a/src/features/auth/context/AuthContext.native.test.tsx +++ b/src/features/auth/context/AuthContext.native.test.tsx @@ -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 () => { diff --git a/src/libs/network/NetInfoWrapper.native.test.tsx b/src/libs/network/NetInfoWrapper.native.test.tsx index aacc1e5ce35..0ad982e3ddf 100644 --- a/src/libs/network/NetInfoWrapper.native.test.tsx +++ b/src/libs/network/NetInfoWrapper.native.test.tsx @@ -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 @@ -14,6 +16,10 @@ const mockedUseNetInfo = useNetInfo as unknown as jest.Mock<{ details?: Record }> +jest.mock('libs/splashscreen') +const mockUseSplashScreenContext = useSplashScreenContext as jest.Mock +mockUseSplashScreenContext.mockReturnValue({ isSplashScreenHidden: true }) + describe('NetInfoWrapper', () => { describe('useNetInfoContext', () => { const onConnection = jest.fn() @@ -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() + }) }) }) @@ -160,7 +199,7 @@ const DumbComponent = ({ onInternetConnectionLost, }) - return null + return } function renderNetInfoWrapper({