|
| 1 | +import { renderHook } from '@testing-library/react-hooks'; |
| 2 | +import { useSelector } from 'react-redux'; |
| 3 | +import { useNavigation } from '@react-navigation/native'; |
| 4 | +import { getBuildNumber } from 'react-native-device-info'; |
| 5 | +import useMinimumVersions from './useMinimumVersions'; |
| 6 | + |
| 7 | +jest.mock('react-redux', () => ({ |
| 8 | + useSelector: jest.fn(), |
| 9 | +})); |
| 10 | + |
| 11 | +jest.mock('@react-navigation/native', () => ({ |
| 12 | + useNavigation: jest.fn(), |
| 13 | +})); |
| 14 | + |
| 15 | +jest.mock('react-native-device-info', () => ({ |
| 16 | + getBuildNumber: jest.fn(), |
| 17 | +})); |
| 18 | + |
| 19 | +jest.mock('react-native', () => ({ |
| 20 | + InteractionManager: { |
| 21 | + runAfterInteractions: jest.fn((callback) => callback()), |
| 22 | + }, |
| 23 | +})); |
| 24 | + |
| 25 | +jest.mock('../../UI/UpdateNeeded/UpdateNeeded', () => ({ |
| 26 | + createUpdateNeededNavDetails: jest.fn(), |
| 27 | +})); |
| 28 | + |
| 29 | +describe('useMinimumVersions', () => { |
| 30 | + const mockNavigation = { |
| 31 | + navigate: jest.fn(), |
| 32 | + }; |
| 33 | + |
| 34 | + beforeEach(() => { |
| 35 | + jest.clearAllMocks(); |
| 36 | + (useNavigation as jest.Mock).mockReturnValue(mockNavigation); |
| 37 | + }); |
| 38 | + |
| 39 | + it('requires update only if automaticSecurityChecksEnabled', () => { |
| 40 | + (useSelector as jest.Mock).mockImplementation(() => ({ |
| 41 | + security: { automaticSecurityChecksEnabled: false }, |
| 42 | + featureFlags: { |
| 43 | + featureFlags: { mobileMinimumVersions: { appMinimumBuild: 100 } }, |
| 44 | + }, |
| 45 | + })); |
| 46 | + |
| 47 | + (getBuildNumber as jest.Mock).mockReturnValue('101'); |
| 48 | + |
| 49 | + renderHook(() => useMinimumVersions()); |
| 50 | + |
| 51 | + expect(mockNavigation.navigate).not.toHaveBeenCalled(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('requires update only if currentBuildNumber is lower than appMinimumBuild', () => { |
| 55 | + (useSelector as jest.Mock).mockImplementation(() => ({ |
| 56 | + security: { automaticSecurityChecksEnabled: true }, |
| 57 | + featureFlags: { |
| 58 | + featureFlags: { mobileMinimumVersions: { appMinimumBuild: 100 } }, |
| 59 | + }, |
| 60 | + })); |
| 61 | + |
| 62 | + (getBuildNumber as jest.Mock).mockReturnValue('101'); |
| 63 | + |
| 64 | + renderHook(() => useMinimumVersions()); |
| 65 | + |
| 66 | + expect(mockNavigation.navigate).not.toHaveBeenCalled(); |
| 67 | + }); |
| 68 | +}); |
0 commit comments