Skip to content

Commit

Permalink
refactor: rename setSettings => mockSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
xlecunff-pass committed Feb 7, 2025
1 parent 0a5fdad commit f68e8cb
Show file tree
Hide file tree
Showing 34 changed files with 88 additions and 89 deletions.
8 changes: 0 additions & 8 deletions src/features/auth/context/__mocks__/SettingsContext.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/features/auth/context/__mocks__/useSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defaultSettings } from 'features/auth/fixtures/fixtures'

export const useSettings = jest.fn().mockReturnValue({
data: defaultSettings,
isLoading: false,
})
11 changes: 11 additions & 0 deletions src/features/auth/context/mockSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SettingsResponse } from 'api/gen'
import * as useSettingsModule from 'features/auth/context/useSettings'
import { defaultSettings } from 'features/auth/fixtures/fixtures'

export const mockSettings = (settings: Partial<SettingsResponse> = {}) => {
const useSettingsContextSpy = jest.spyOn(useSettingsModule, 'useSettings')
useSettingsContextSpy.mockImplementation(() => ({
data: { ...defaultSettings, ...settings },
isLoading: false,
}))
}
19 changes: 0 additions & 19 deletions src/features/auth/context/setSettings.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { navigate, replace } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { StepperOrigin } from 'features/navigation/RootNavigator/types'
import { captureMonitoringError } from 'libs/monitoring/errors'
import { eventMonitoring } from 'libs/monitoring/services'
Expand Down Expand Up @@ -38,7 +38,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('<ForgottenPassword />', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should match snapshot', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/features/auth/pages/login/Login.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
UserProfileResponse,
} from 'api/gen'
import { AuthContext } from 'features/auth/context/AuthContext'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { SignInResponseFailure } from 'features/auth/types'
import { favoriteOfferResponseSnap } from 'features/favorites/fixtures/favoriteOfferResponseSnap'
import { favoriteResponseSnap } from 'features/favorites/fixtures/favoriteResponseSnap'
Expand Down Expand Up @@ -644,7 +644,7 @@ describe('<Login/>', () => {

describe('Login with ReCatpcha', () => {
beforeAll(() => {
setSettings()
mockSettings()
})

it('should not open reCAPTCHA challenge modal before clicking on login button', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Linking } from 'react-native'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { analytics } from 'libs/analytics/provider'
import { env } from 'libs/environment/env'
import { useNetInfoContext as useNetInfoContextDefault } from 'libs/network/NetInfoWrapper'
Expand Down Expand Up @@ -50,7 +50,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('<AcceptCgu/>', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should render correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import mockdate from 'mockdate'
import React from 'react'

import { useRoute } from '__mocks__/@react-navigation/native'
import { mockSettings } from 'features/auth/context/mockSettings'
import {
CURRENT_DATE,
DEFAULT_SELECTED_DATE,
ELIGIBLE_AGE_DATE,
} from 'features/auth/fixtures/fixtures'
import { setSettings } from 'features/auth/context/setSettings'
import { NonEligible } from 'features/tutorial/enums'
import { formatDateToISOStringWithoutTime } from 'libs/parsers/formatDates'
import { storage } from 'libs/storage'
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('<SetBirthday />', () => {
beforeEach(async () => {
mockdate.set(CURRENT_DATE)
await storage.clear(USER_AGE_KEY)
setSettings()
mockSettings()
})

it('should render correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mockdate from 'mockdate'
import React from 'react'

import { mockSettings } from 'features/auth/context/mockSettings'
import { CURRENT_DATE } from 'features/auth/fixtures/fixtures'
import { setSettings } from 'features/auth/context/setSettings'
import { act, fireEvent, render, screen } from 'tests/utils/web'

import { SetBirthday } from './SetBirthday'
Expand All @@ -26,7 +26,7 @@ jest.mock('ui/theme/customFocusOutline/customFocusOutline')
describe('<SetBirthday />', () => {
beforeEach(() => {
mockdate.set(CURRENT_DATE)
setSettings()
mockSettings()
})

describe('submit button behavior', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { AccountState } from 'api/gen'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { navigateToHome } from 'features/navigation/helpers/navigateToHome'
import { useCurrentRoute } from 'features/navigation/helpers/useCurrentRoute'
import { render, screen } from 'tests/utils'
Expand Down Expand Up @@ -34,7 +34,7 @@ jest.mock('libs/firebase/analytics/analytics')

describe('<AccountStatusScreenHandler />', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should display SuspendedAccountUponUserRequest component if account is suspended upon user request', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mockdate from 'mockdate'
import React from 'react'

import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { underageBeneficiaryUser } from 'fixtures/user'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('<RecreditBirthdayNotification />', () => {

beforeEach(() => {
setFeatureFlags()
setSettings()
mockSettings()
})

it('should have correct credit text', async () => {
Expand All @@ -56,7 +56,7 @@ describe('<RecreditBirthdayNotification />', () => {

describe('when enableCreditV3 activated', () => {
beforeEach(() => {
setSettings({ wipEnableCreditV3: true })
mockSettings({ wipEnableCreditV3: true })
})

it('should have correct credit information text', async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/features/favorites/pages/Favorites.perf.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import * as jwt from '__mocks__/jwt-decode'
import { UserProfileResponse } from 'api/gen'
import { AuthWrapper } from 'features/auth/context/AuthWrapper'
import { mockSettings } from 'features/auth/context/mockSettings'
import { paginatedFavoritesResponseSnap } from 'features/favorites/fixtures/paginatedFavoritesResponseSnap'
import { simulateBackend } from 'features/favorites/helpers/simulateBackend'
import { Favorites } from 'features/favorites/pages/Favorites'
Expand All @@ -21,6 +22,8 @@ jest.mock('features/favorites/context/FavoritesWrapper')

jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')

mockSettings()

// Performance measuring is run multiple times so we need to increase the timeout
const TEST_TIMEOUT_IN_MS = 30000
jest.setTimeout(TEST_TIMEOUT_IN_MS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { SignupBanner } from 'features/home/components/banners/SignupBanner'
import { StepperOrigin } from 'features/navigation/RootNavigator/types'
import { analytics } from 'libs/analytics/provider'
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('SignupBanner', () => {

describe('when enableCreditV3 activated', () => {
beforeEach(() => {
setSettings({ wipEnableCreditV3: true })
mockSettings({ wipEnableCreditV3: true })
})

it('should display banner with credit V3 subtitle', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { BeneficiaryAccountCreated } from 'features/identityCheck/pages/confirmation/BeneficiaryAccountCreated'
import * as ShareAppWrapperModule from 'features/share/context/ShareAppWrapper'
import { ShareAppWrapper } from 'features/share/context/ShareAppWrapper'
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('<BeneficiaryAccountCreated/>', () => {

describe('when enableCreditV3 activated', () => {
beforeEach(() => {
setSettings({ wipEnableCreditV3: true })
mockSettings({ wipEnableCreditV3: true })
})

it('should have correct credit information text', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UseQueryResult } from 'react-query'

import { SubscriptionStepperResponseV2 } from 'api/gen'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { useGetStepperInfo } from 'features/identityCheck/api/useGetStepperInfo'
import { usePhoneValidationRemainingAttempts } from 'features/identityCheck/api/usePhoneValidationRemainingAttempts'
import { initialSubscriptionState as mockState } from 'features/identityCheck/context/reducer'
Expand Down Expand Up @@ -57,7 +57,7 @@ jest.mock('features/identityCheck/context/SubscriptionContextProvider', () => ({
describe('useStepperInfo', () => {
beforeEach(() => {
setFeatureFlags()
setSettings({ enablePhoneValidation: true })
mockSettings({ enablePhoneValidation: true })
})

it('should return title and subtitle', () => {
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('useStepperInfo', () => {
},
})

setSettings({ enablePhoneValidation: false })
mockSettings({ enablePhoneValidation: false })

const { stepsDetails } = useStepperInfo()
const phoneValidationStep = stepsDetails.find(
Expand Down
3 changes: 3 additions & 0 deletions src/features/offer/pages/Offer/Offer.perf.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'

import { useRoute } from '__mocks__/@react-navigation/native'
import { OfferResponseV2, SimilarOffersResponse, SubcategoriesResponseModelv2 } from 'api/gen'
import { mockSettings } from 'features/auth/context/mockSettings'
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import * as GetInstalledAppsAPI from 'features/offer/helpers/getInstalledApps/getInstalledApps'
import * as useArtistResults from 'features/offer/helpers/useArtistResults/useArtistResults'
Expand Down Expand Up @@ -44,6 +45,8 @@ jest.useFakeTimers()

jest.mock('libs/network/NetInfoWrapper')

mockSettings()

useRoute.mockReturnValue({
params: {
id: offerResponseSnap.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { CitySearchInput } from 'features/profile/components/CitySearchInput/CitySearchInput'
import { mockedSuggestedCities } from 'libs/place/fixtures/mockedSuggestedCities'
import { CitiesResponse, CITIES_API_URL } from 'libs/place/useCities'
Expand All @@ -18,7 +18,7 @@ jest.useFakeTimers()

describe('<CitySearchInput />', () => {
beforeEach(() => {
setSettings({ ineligiblePostalCodes: [NEW_CALEDONIA_NORTHERN_PROVINCE_POSTAL_CODE] })
mockSettings({ ineligiblePostalCodes: [NEW_CALEDONIA_NORTHERN_PROVINCE_POSTAL_CODE] })
})

it('should display error message when the user enters a valid postal code but no city found', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { CreditExplanation } from 'features/profile/components/CreditExplanation/CreditExplanation'
import { analytics } from 'libs/analytics/provider'
import { act, fireEvent, render, screen } from 'tests/utils'
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('<CreditExplanation/>', () => {

describe('With redirection to tutorial', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should navigate to tutorial when button is triggered', async () => {
Expand All @@ -49,7 +49,7 @@ describe('<CreditExplanation/>', () => {
})

it('should navigate to tutorial CreditV3 when button is triggered and enableCreditV3 is true', async () => {
setSettings({ wipEnableCreditV3: true })
mockSettings({ wipEnableCreditV3: true })

render(<CreditExplanation isDepositExpired={false} age={18} />)
const explanationButton = screen.getByTestId('Comment ça marche\u00a0?')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/context/setSettings'
import { mockSettings } from 'features/auth/context/mockSettings'
import { StepperOrigin } from 'features/navigation/RootNavigator/types'
import { analytics } from 'libs/analytics/provider'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('LoggedOutHeader', () => {

describe('when enableCreditV3 activated', () => {
beforeEach(() => {
setSettings({ wipEnableCreditV3: true })
mockSettings({ wipEnableCreditV3: true })
})

it('should display subtitle with credit V3', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { mockSettings } from 'features/auth/context/mockSettings'
import * as LogoutRoutine from 'features/auth/helpers/useLogoutRoutine'
import { setSettings } from 'features/auth/context/setSettings'
import { navigateToHomeConfig } from 'features/navigation/helpers/navigateToHome'
import { navigateFromRef } from 'features/navigation/navigationRef'
import { StepperOrigin } from 'features/navigation/RootNavigator/types'
Expand All @@ -27,7 +27,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('DeactivateProfileSuccess component', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should render delete profile success', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'

import { navigate } from '__mocks__/@react-navigation/native'
import { mockSettings } from 'features/auth/context/mockSettings'
import * as LogoutRoutine from 'features/auth/helpers/useLogoutRoutine'
import { setSettings } from 'features/auth/context/setSettings'
import { DeleteProfileReason } from 'features/profile/pages/DeleteProfileReason/DeleteProfileReason'
import { beneficiaryUser, nonBeneficiaryUser } from 'fixtures/user'
import { analytics } from 'libs/analytics/provider'
Expand Down Expand Up @@ -30,7 +30,7 @@ jest.useFakeTimers()
describe('<DeleteProfileReason />', () => {
beforeEach(() => {
jest.setSystemTime(new Date('2020-01-01'))
setSettings()
mockSettings()
})

it('should match snapshot', () => {
Expand Down
Loading

0 comments on commit f68e8cb

Please sign in to comment.