|
| 1 | +import React, {ReactElement} from 'react' |
| 2 | +import {describe, expect, test} from '@jest/globals' |
| 3 | +import {renderHook, waitFor} from '@testing-library/react-native' |
| 4 | +import {QueryClient, QueryClientProvider} from '@tanstack/react-query' |
| 5 | +import {useCourseSearchRecentsScreen} from '../index' |
| 6 | + |
| 7 | +jest.mock('../../../source/lib/storage', () => ({ |
| 8 | + getFeatureFlag: jest.fn(), |
| 9 | +})) |
| 10 | + |
| 11 | +jest.mock('@frogpond/constants', () => ({ |
| 12 | + isDevMode: jest.fn(), |
| 13 | +})) |
| 14 | + |
| 15 | +describe('useCourseSearchRecentsScreen', () => { |
| 16 | + let queryClient: QueryClient |
| 17 | + |
| 18 | + beforeAll(() => { |
| 19 | + queryClient = new QueryClient() |
| 20 | + }) |
| 21 | + |
| 22 | + afterAll(() => { |
| 23 | + queryClient.clear() |
| 24 | + queryClient.removeQueries() |
| 25 | + }) |
| 26 | + |
| 27 | + const queryWrapper = ({children}: {children: ReactElement}) => ( |
| 28 | + <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> |
| 29 | + ) |
| 30 | + |
| 31 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 32 | + const isDevModeMock = require('@frogpond/constants').isDevMode |
| 33 | + |
| 34 | + const getFeatureFlagMock = |
| 35 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 36 | + require('../../../source/lib/storage').getFeatureFlag |
| 37 | + |
| 38 | + test('it should return true in dev when feature is enabled', async () => { |
| 39 | + isDevModeMock.mockReturnValue(true) |
| 40 | + getFeatureFlagMock.mockReturnValue(true) |
| 41 | + |
| 42 | + const {result} = renderHook(() => useCourseSearchRecentsScreen(), { |
| 43 | + wrapper: queryWrapper, |
| 44 | + }) |
| 45 | + |
| 46 | + await waitFor(() => { |
| 47 | + expect(result.current).toBe(true) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + test('it should return false in prod when feature is enabled', async () => { |
| 52 | + isDevModeMock.mockReturnValue(false) |
| 53 | + getFeatureFlagMock.mockReturnValue(true) |
| 54 | + |
| 55 | + const {result} = renderHook(() => useCourseSearchRecentsScreen(), { |
| 56 | + wrapper: queryWrapper, |
| 57 | + }) |
| 58 | + |
| 59 | + await waitFor(() => { |
| 60 | + expect(result.current).toBe(false) |
| 61 | + }) |
| 62 | + }) |
| 63 | +}) |
0 commit comments