Skip to content

Commit

Permalink
removed last useFF spyOns
Browse files Browse the repository at this point in the history
  • Loading branch information
cgerrard-pass committed Feb 6, 2025
1 parent e8e403a commit 1ffcbaa
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { beneficiaryUser } from 'fixtures/user'
import * as logOfferConversionAPI from 'libs/algolia/analytics/logOfferConversion'
import { analytics } from 'libs/analytics/provider'
import { CampaignEvents, campaignTracker } from 'libs/campaign'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen, waitFor } from 'tests/utils'
import { SnackBarHelperSettings } from 'ui/components/snackBar/types'
Expand All @@ -27,8 +27,6 @@ jest.mock('libs/campaign')
const mockDismissModal = jest.fn()
const mockDispatch = jest.fn()

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

const mockOffer = { ...baseOffer, subcategoryId: SubcategoryIdEnum.SEANCE_CINE }

const mockUseBookingContext: jest.Mock<IBookingContext> = jest.fn(() => ({
Expand Down Expand Up @@ -135,6 +133,10 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {
})

describe('<BookingOfferModalComponent />', () => {
beforeEach(() => {
setFeatureFlags()
})

it('should dismiss modal when click on rightIconButton and reset state', async () => {
render(reactQueryProviderHOC(<BookingOfferModalComponent visible offerId={mockOffer.id} />))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React from 'react'

import { AnimatedCategoryThematicHomeHeader } from 'features/home/components/headers/AnimatedCategoryThematicHomeHeader'
import { Color } from 'features/home/types'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen } from 'tests/utils'

const mockUseFeatureFlag = jest.spyOn(useFeatureFlag, 'useFeatureFlag')

jest.mock('features/profile/pages/NotificationSettings/usePushPermission', () => ({
usePushPermission: jest.fn(() => ({
pushPermission: 'granted',
Expand All @@ -18,8 +17,8 @@ jest.mock('libs/firebase/analytics/analytics')

describe('AnimatedCategoryThematicHomeHeader', () => {
describe('when WIP_APP_V2_THEMATIC_HOME_HEADER is on', () => {
beforeAll(() => {
mockUseFeatureFlag.mockReturnValue(true)
beforeEach(() => {
setFeatureFlags([RemoteStoreFeatureFlags.WIP_APP_V2_THEMATIC_HOME_HEADER])
})

it('should render the v1 header and not the v2', async () => {
Expand All @@ -38,8 +37,8 @@ describe('AnimatedCategoryThematicHomeHeader', () => {
})

describe('when WIP_APP_V2_THEMATIC_HOME_HEADER is off', () => {
beforeAll(() => {
mockUseFeatureFlag.mockReturnValue(false)
beforeEach(() => {
setFeatureFlags()
})

it('should render the v2 header and not the v1', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import React from 'react'

import { CategoryThematicHomeHeader } from 'features/home/components/headers/CategoryThematicHomeHeader'
import { Color } from 'features/home/types'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { render, screen } from 'tests/utils'

const mockUseFeatureFlag = jest.spyOn(useFeatureFlag, 'useFeatureFlag')

jest.mock('libs/firebase/analytics/analytics')

describe('CategoryThematicHomeHeader', () => {
describe('when WIP_APP_V2_THEMATIC_HOME_HEADER is on', () => {
beforeAll(() => {
mockUseFeatureFlag.mockReturnValue(true)
beforeEach(() => {
setFeatureFlags([RemoteStoreFeatureFlags.WIP_APP_V2_THEMATIC_HOME_HEADER])
})

it('should render the v1 header and not the v2', async () => {
Expand Down Expand Up @@ -45,8 +44,8 @@ describe('CategoryThematicHomeHeader', () => {
})

describe('when WIP_APP_V2_THEMATIC_HOME_HEADER is off', () => {
beforeAll(() => {
mockUseFeatureFlag.mockReturnValue(false)
beforeEach(() => {
setFeatureFlags()
})

it('should render the v2 header and not the v1', async () => {
Expand Down
8 changes: 1 addition & 7 deletions src/features/home/components/modules/HomeModule.web.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { HomepageModule, ModuleData } from 'features/home/types'
import { SimilarOffersResponse } from 'features/offer/types'
import { mockedAlgoliaResponse } from 'libs/algolia/fixtures/algoliaFixtures'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { useFeatureFlag } from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { GeoCoordinates, Position } from 'libs/location'
import { subcategoriesDataTest } from 'libs/subcategories/fixtures/subcategoriesResponse'
Expand All @@ -33,9 +32,6 @@ const homeEntryId = '7tfixfH64pd5TMZeEKfNQ'

const highlightOfferFixture = offersFixture[0]

jest.mock('libs/firebase/firestore/featureFlags/useFeatureFlag')
const mockedUseFeatureFlag = useFeatureFlag as jest.Mock

jest.mock('features/home/api/useHighlightOffer')
const mockUseHighlightOffer = useHighlightOffer as jest.Mock
const mockUseAuthContext = jest.fn().mockReturnValue({
Expand Down Expand Up @@ -81,7 +77,6 @@ describe('<HomeModule />', () => {
// because it's easier to test them one by one
describe('Accessibility', () => {
it('OldBusiness module should not have basic accessibility issues', async () => {
mockedUseFeatureFlag.mockReturnValueOnce(false)
const { container } = renderHomeModule(formattedBusinessModule)

expect(screen.getByText('Débloque ton crédit !')).toBeInTheDocument()
Expand All @@ -92,7 +87,7 @@ describe('<HomeModule />', () => {
})

it('NewBusiness module should not have basic accessibility issues', async () => {
mockedUseFeatureFlag.mockReturnValueOnce(true)
setFeatureFlags([RemoteStoreFeatureFlags.WIP_APP_V2_BUSINESS_BLOCK])

const { container } = renderHomeModule(formattedNewBusinessModule)

Expand All @@ -107,7 +102,6 @@ describe('<HomeModule />', () => {
})

it('Highlight module should not have basic accessibility issues', async () => {
mockedUseFeatureFlag.mockReturnValueOnce(true)
mockUseHighlightOffer.mockReturnValueOnce(highlightOfferFixture)

const { container } = renderHomeModule(highlightOfferModuleFixture)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react'

import { VenueMapModule } from 'features/home/components/modules/VenueMapModule'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { render, screen } from 'tests/utils/web'

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(true)

jest.mock('libs/firebase/remoteConfig/remoteConfig.services')

describe('VenueMapModule', () => {
it('should not display venue map block on web', () => {
setFeatureFlags()
render(<VenueMapModule />)

expect(screen.queryByText('Explorer les lieux')).not.toBeOnTheScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
BusinessModule,
BusinessModuleProps,
} from 'features/home/components/modules/business/BusinessModule'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen } from 'tests/utils'

Expand All @@ -25,20 +26,18 @@ const props: BusinessModuleProps = {
date: undefined,
}

const mockFeatureFlag = jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

jest.mock('libs/firebase/analytics/analytics')

describe('BusinessModule component', () => {
it('should render NewBusinessModule if FF WIP_APP_V2_BUSINESS_BLOCK is on', () => {
mockFeatureFlag.mockReturnValueOnce(true)
setFeatureFlags([RemoteStoreFeatureFlags.WIP_APP_V2_BUSINESS_BLOCK])
renderBusinessModule(props)

expect(screen.getByText('En savoir plus')).toBeOnTheScreen()
})

it('should render OldBusinessModule if FF WIP_APP_V2_BUSINESS_BLOCK is off', async () => {
mockFeatureFlag.mockReturnValueOnce(false)
setFeatureFlags()
renderBusinessModule(props)

expect(screen.queryByText('En savoir plus')).not.toBeOnTheScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
import { useStepperInfo } from 'features/identityCheck/pages/helpers/useStepperInfo'
import { IdentityCheckStep } from 'features/identityCheck/types'
import { beneficiaryUser } from 'fixtures/user'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'

const mockIdentityCheckState = mockState
Expand Down Expand Up @@ -53,11 +54,9 @@ jest.mock('features/identityCheck/context/SubscriptionContextProvider', () => ({
})),
}))

const useFeatureFlagSpy = jest.spyOn(useFeatureFlag, 'useFeatureFlag')
useFeatureFlagSpy.mockReturnValue(false)

describe('useStepperInfo', () => {
beforeEach(() => {
setFeatureFlags()
setSettings({ enablePhoneValidation: true })
})

Expand Down Expand Up @@ -182,7 +181,7 @@ describe('useStepperInfo', () => {

it('should have firstScreen to "CulturalSurveyIntro" when feature flag FF enableCulturalSurveyMandatory is enabled and user needsToFillCulturalSurvey', () => {
mockAuthContextWithUser({ ...beneficiaryUser, needsToFillCulturalSurvey: true })
useFeatureFlagSpy.mockReturnValueOnce(true)
setFeatureFlags([RemoteStoreFeatureFlags.ENABLE_CULTURAL_SURVEY_MANDATORY])
const { stepsDetails } = useStepperInfo()
const confirmationStep = stepsDetails.find(
(step) => step.name === IdentityCheckStep.CONFIRMATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'

import { LocationWidget } from 'features/location/components/LocationWidget'
import { ScreenOrigin } from 'features/location/enums'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { act, fireEvent, render, screen } from 'tests/utils'

jest.unmock('@react-navigation/native')
Expand All @@ -18,9 +18,11 @@ jest.mock('ui/components/modals/useModal', () => ({
}),
}))

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(true)

describe('LocationWidget', () => {
beforeEach(() => {
setFeatureFlags() // TODO(PC-34435): add tests for WIP_APP_V2_LOCATION_WIDGET
})

it('should show modal when pressing widget', async () => {
renderLocationWidget()

Expand Down
7 changes: 5 additions & 2 deletions src/features/location/components/LocationWidget.web.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import React from 'react'

import { LocationWidget } from 'features/location/components/LocationWidget'
import { ScreenOrigin } from 'features/location/enums'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { act, fireEvent, render, screen } from 'tests/utils/web'

jest.unmock('@react-navigation/native')
jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(true)
jest.mock('libs/firebase/remoteConfig/remoteConfig.services')

describe('LocationWidget', () => {
beforeEach(() => {
setFeatureFlags() // TODO(PC-34435): add tests for WIP_APP_V2_LOCATION_WIDGET
})

afterEach(async () => {
await act(async () => {
jest.runOnlyPendingTimers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NavigationContainer } from '@react-navigation/native'
import React from 'react'

import { LocationWidgetDesktop } from 'features/location/components/LocationWidgetDesktop'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { useLocation } from 'libs/location'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { storage } from 'libs/storage'
Expand All @@ -23,9 +23,11 @@ jest.mock('ui/components/modals/useModal', () => ({
jest.mock('libs/location')
const mockUseLocation = useLocation as jest.Mock

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

describe('LocationWidgetDesktop', () => {
beforeEach(() => {
setFeatureFlags()
})

it('should show modal when pressing widget', async () => {
mockUseLocation.mockReturnValueOnce({
hasGeolocPosition: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { NavigationContainer } from '@react-navigation/native'
import React from 'react'

import { LocationWidgetDesktop } from 'features/location/components/LocationWidgetDesktop'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { act, fireEvent, render, screen } from 'tests/utils/web'

jest.unmock('@react-navigation/native')
jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(true)
jest.mock('libs/firebase/remoteConfig/remoteConfig.services')

describe('LocationWidgetDesktop', () => {
beforeEach(() => {
setFeatureFlags() // TODO(PC-34435): add tests for WIP_APP_V2_LOCATION_WIDGET
})

afterEach(async () => {
await act(async () => {
jest.runOnlyPendingTimers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import { MoviesScreeningCalendar } from 'features/offer/components/MoviesScreeni
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import { offersStocksResponseSnap } from 'features/offer/fixtures/offersStocksResponse'
import { VenueOffers } from 'features/venue/types'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { subcategoriesDataTest } from 'libs/subcategories/fixtures/subcategoriesResponse'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, render, screen } from 'tests/utils'
import { AnchorProvider } from 'ui/components/anchor/AnchorContext'

jest.mock('libs/network/NetInfoWrapper')
jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(true)
jest.mock('libs/firebase/analytics/analytics')

const MOCK_TIMESTAMP = '2024-05-08T12:50:00Z'
Expand Down Expand Up @@ -58,6 +57,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('MoviesScreeningCalendar', () => {
beforeEach(() => {
setFeatureFlags()
mockdate.set(MOCK_DATE)
mockServer.postApi<OffersStocksResponseV2>(`/v2/offers/stocks`, mockedOfferStockResponse)
mockServer.getApi<OfferResponseV2>(`/v2/offer/${ID}`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import React from 'react'
import { OfferResponseV2 } from 'api/gen'
import { OfferAbout } from 'features/offer/components/OfferAbout/OfferAbout'
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { render, screen } from 'tests/utils'

jest.mock('libs/firebase/analytics/analytics')
jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

describe('<OfferAbout />', () => {
beforeEach(() => {
setFeatureFlags()
})

const metadata = [
{ label: 'Speaker', value: 'Donald' },
{ label: 'Author', value: 'Mickey' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import React from 'react'

import { OfferAccessibility } from 'features/offer/components/OfferAccessibility/OfferAccessibility'
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { render, screen } from 'tests/utils'

jest.mock('libs/firebase/analytics/analytics')
jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

const accessibility = offerResponseSnap.accessibility

describe('<OfferAccessibility />', () => {
beforeEach(() => {
setFeatureFlags()
})

it('should display section title when there is at least one handicap information', () => {
render(<OfferAccessibility accessibility={accessibility} />)

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

import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { fireEvent, render, screen } from 'tests/utils'
import { theme } from 'theme'

Expand Down Expand Up @@ -30,9 +30,11 @@ const items: VenueListItem[] = [
const nbLoadedHits = 3
const nbHits = 40

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)

describe('<VenueSelectionList />', () => {
beforeEach(() => {
setFeatureFlags()
})

it('should show list of items', () => {
render(
<VenueSelectionList
Expand Down
Loading

0 comments on commit 1ffcbaa

Please sign in to comment.