Skip to content

Commit

Permalink
(BSR) refactor(tests): replace last spyon FF
Browse files Browse the repository at this point in the history
  • Loading branch information
cgerrard-pass committed Jan 14, 2025
1 parent 614e12a commit 4ce6217
Show file tree
Hide file tree
Showing 41 changed files with 197 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mockSubcategory } from 'features/offer/fixtures/mockSubcategory'
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import * as useArtistResults from 'features/offer/helpers/useArtistResults/useArtistResults'
import { mockedAlgoliaOffersWithSameArtistResponse } from 'libs/algolia/fixtures/algoliaFixtures'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { fireEvent, render, screen } from 'tests/utils'

Expand Down Expand Up @@ -40,8 +40,6 @@ useRoute.mockReturnValue({
},
})

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

const spyUseArtistResults = jest.spyOn(useArtistResults, 'useArtistResults')

const mockArtist = {
Expand All @@ -51,6 +49,7 @@ const mockArtist = {

describe('<ArtistBody />', () => {
beforeEach(() => {
setFeatureFlags()
spyUseArtistResults.mockReturnValue({
artistTopOffers: mockedAlgoliaOffersWithSameArtistResponse.slice(0, 4),
artistPlaylist: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import React from 'react'
import { ArtistPlaylist } from 'features/artist/components/ArtistPlaylist/ArtistPlaylist'
import { mockOffer } from 'features/bookOffer/fixtures/offer'
import { mockedAlgoliaOffersWithSameArtistResponse } from 'libs/algolia/fixtures/algoliaFixtures'
import * as useFeatureFlagAPI 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'

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

jest.mock('@shopify/flash-list', () => {
const ActualFlashList = jest.requireActual('@shopify/flash-list').FlashList
class MockFlashList extends ActualFlashList {
Expand All @@ -26,6 +25,10 @@ jest.mock('@shopify/flash-list', () => {
})

describe('ArtistPlaylist', () => {
beforeEach(() => {
setFeatureFlags([RemoteStoreFeatureFlags.WIP_NEW_HOME_MODULE_SIZES])
})

it('should display artist playlist when there is some offer from this artist', () => {
render(
reactQueryProviderHOC(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import React from 'react'

import { ArtistTopOffers } from 'features/artist/components/ArtistTopOffers/ArtistTopOffers'
import { mockedAlgoliaOffersWithSameArtistResponse } from 'libs/algolia/fixtures/algoliaFixtures'
import * as useFeatureFlagAPI 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'

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

describe('ArtistPlaylist', () => {
describe('ArtistTopOffers', () => {
beforeEach(() => {
setFeatureFlags([RemoteStoreFeatureFlags.WIP_NEW_HOME_MODULE_SIZES])
})

it('should display top offers when there is some offer from this artist', () => {
render(
reactQueryProviderHOC(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import { AccountState, OauthStateResponse, SigninResponse, UserProfileResponse }
import { SSOButton } from 'features/auth/components/SSOButton/SSOButton'
import { beneficiaryUser } from 'fixtures/user'
import { analytics } from 'libs/analytics'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import { DEFAULT_REMOTE_CONFIG } from 'libs/firebase/remoteConfig/remoteConfig.constants'
import * as useRemoteConfigContext from 'libs/firebase/remoteConfig/RemoteConfigProvider'
import { eventMonitoring } from 'libs/monitoring'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen } from 'tests/utils'

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

jest.mock('libs/monitoring')
jest.mock('libs/react-native-device-info/getDeviceId')
jest.mock('features/identityCheck/context/SubscriptionContextProvider', () => ({
Expand Down Expand Up @@ -48,6 +47,7 @@ describe('<SSOButton />', () => {
mockServer.getApi<OauthStateResponse>('/v1/oauth/state', {
oauthStateToken: 'oauth_state_token',
})
setFeatureFlags([RemoteStoreFeatureFlags.WIP_ENABLE_GOOGLE_SSO])
})

it('should sign in with device info when sso button is clicked', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react'
import { EmailValidationRemainingResendsResponse } from 'api/gen'
import { SignupConfirmationEmailSentPage } from 'features/auth/pages/signup/SignupConfirmationEmailSent/SignupConfirmationEmailSentPage'
import { RootStackParamList } from 'features/navigation/RootNavigator/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen } from 'tests/utils'
Expand All @@ -13,8 +12,6 @@ const navigationProps = {
route: { params: { email: '[email protected]' } },
} as StackScreenProps<RootStackParamList, 'SignupConfirmationEmailSent'>

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

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

jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react'

import { EmailValidationRemainingResendsResponse } from 'api/gen'
import { RootStackParamList } from 'features/navigation/RootNavigator/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, checkAccessibilityFor, render } from 'tests/utils/web'
Expand All @@ -14,8 +13,6 @@ const navigationProps = {
route: { params: { email: '[email protected]' } },
} as StackScreenProps<RootStackParamList, 'SignupConfirmationEmailSent'>

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

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

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

import { navigate } from '__mocks__/@react-navigation/native'
import { nonBeneficiaryUser } from 'fixtures/user'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { storage } from 'libs/storage'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { fireEvent, render, screen } from 'tests/utils'

import { EighteenBirthday } from './EighteenBirthday'

jest.spyOn(useFeatureFlagAPI, 'useFeatureFlag').mockReturnValue(true)
jest.mock('features/auth/context/AuthContext')

afterEach(() => {
Expand All @@ -24,6 +23,10 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {
})

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

it('should render eighteen birthday', () => {
render(reactQueryProviderHOC(<EighteenBirthday />))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import mockdate from 'mockdate'
import React from 'react'

import { underageBeneficiaryUser } from 'fixtures/user'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen } from 'tests/utils'

import { RecreditBirthdayNotification } from './RecreditBirthdayNotification'

jest.spyOn(useFeatureFlagAPI, 'useFeatureFlag').mockReturnValue(true)
jest.mock('features/auth/context/AuthContext')
jest.mock('features/profile/api/useUpdateProfileMutation', () => ({
useResetRecreditAmountToShow: jest.fn().mockReturnValue({
Expand All @@ -36,6 +35,10 @@ describe('<RecreditBirthdayNotification />', () => {
mockdate.set(new Date('2023-02-28'))
})

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

it('should have correct text', async () => {
render(reactQueryProviderHOC(<RecreditBirthdayNotification />))

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

import { BookingState, Step } from 'features/bookOffer/context/reducer'
import { mockOffer } from 'features/bookOffer/fixtures/offer'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { fireEvent, render, screen } from 'tests/utils'

import { BookDuoChoice } from './BookDuoChoice'

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

const mockStep = Step.DUO

const mockDismissModal = jest.fn()
Expand Down Expand Up @@ -44,6 +42,10 @@ jest.mock('features/offer/helpers/useHasEnoughCredit/useHasEnoughCredit', () =>
}))

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

it('should display two blocs if offer is duo', () => {
render(<BookDuoChoice />)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { BookingState, Step } from 'features/bookOffer/context/reducer'
import { mockOffer as mockBaseOffer } from 'features/bookOffer/fixtures/offer'
import { stock1, stock2, stock3, stock4 } from 'features/bookOffer/fixtures/stocks'
import { IBookingContext } from 'features/bookOffer/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { fireEvent, render, screen } from 'tests/utils'

import { BookHourChoice } from './BookHourChoice'

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

const mockStep = Step.HOUR
const mockDuoStep = Step.DUO

Expand Down Expand Up @@ -60,6 +58,7 @@ describe('BookHourChoice when hour is already selected', () => {
dismissModal: jest.fn(),
dispatch: mockDispatch,
})
setFeatureFlags()
})

it('should change step to Hour', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { BookPricesChoice } from 'features/bookOffer/components/BookPricesChoice
import { BookingState, initialBookingState } from 'features/bookOffer/context/reducer'
import { mockStocks } from 'features/bookOffer/fixtures/stocks'
import { IBookingContext } from 'features/bookOffer/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { fireEvent, render, screen } from 'tests/utils'

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

const mockInitialBookingState = initialBookingState

const mockOfferId = 1337
Expand Down Expand Up @@ -40,6 +38,7 @@ describe('BookPricesChoice', () => {
dismissModal: jest.fn(),
dispatch: mockDispatch,
})
setFeatureFlags()
})

it('should render prices of stocks in parameter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import { offerStockResponseSnap } from 'features/offer/fixtures/offerStockResponse'
import * as UnderageUserAPI from 'features/profile/helpers/useIsUserUnderage'
import * as logOfferConversionAPI from 'libs/algolia/analytics/logOfferConversion'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { LocationMode } from 'libs/location/types'
import { SuggestedPlace } from 'libs/place/types'
import { mockServer } from 'tests/mswServer'
Expand All @@ -22,8 +22,6 @@ import { SnackBarHelperSettings } from 'ui/components/snackBar/types'

import { BookingDetails, BookingDetailsProps } from './BookingDetails'

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

const mockDismissModal = jest.fn()
const mockDispatch = jest.fn()

Expand Down Expand Up @@ -173,6 +171,7 @@ describe('<BookingDetails />', () => {
dismissModal: mockDismissModal,
dispatch: mockDispatch,
})
setFeatureFlags()
})

it('should initialize correctly state when offer isDigital', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { Step } from 'features/bookOffer/context/reducer'
import { useBookingContext } from 'features/bookOffer/context/useBookingContext'
import { offerResponseSnap } from 'features/offer/fixtures/offerResponse'
import { beneficiaryUser } from 'fixtures/user'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen, waitFor } from 'tests/utils'

import { BookingEventChoices } from './BookingEventChoices'

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

jest.mock('features/auth/context/AuthContext')

const mockUseBooking = useBookingContext as jest.Mock
Expand All @@ -35,6 +33,7 @@ jest.mock('features/bookOffer/context/useBookingContext', () => ({
describe('<BookingEventChoices />', () => {
beforeEach(() => {
mockServer.getApi<OfferResponseV2>(`/v2/offer/116656`, offerResponseSnap)
setFeatureFlags()
})

beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { useBookingContext } from 'features/bookOffer/context/useBookingContext'
import { mockOffer as baseOffer } from 'features/bookOffer/fixtures/offer'
import { useBookingStock } from 'features/bookOffer/helpers/useBookingStock'
import { offerStockResponseSnap } from 'features/offer/fixtures/offerStockResponse'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { formatDateTimezone } from 'libs/parsers/formatDates'
import { render, screen } from 'tests/utils'

import { BookingInformations } from './BookingInformations'

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

const randomDatetime = '2020-12-01T00:00:00Z'

jest.mock('features/bookOffer/context/useBookingContext')
Expand Down Expand Up @@ -45,6 +43,10 @@ jest.mock('features/bookOffer/helpers/useBookingOffer', () => ({
const ANY_CHARACTER = /./

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

it('should return empty component when no offer', async () => {
mockUseBookingOffer.mockReturnValueOnce(undefined)
render(<BookingInformations />)
Expand Down
8 changes: 5 additions & 3 deletions src/features/bookOffer/components/PriceLine.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from 'react'

import { PriceLine } from 'features/bookOffer/components/PriceLine'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { render, screen } from 'tests/utils'

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

const attributes = ['VOSTFR', '3D', 'IMAX']

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

it('should show total price', () => {
render(<PriceLine unitPrice={500} quantity={1} />)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { BookingPropertiesSection } from 'features/bookings/components/BookingPr
import { bookingsSnap } from 'features/bookings/fixtures/bookingsSnap'
import { Booking } from 'features/bookings/types'
import { beneficiaryUser } from 'fixtures/user'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/setFeatureFlags'
import { mockAuthContextWithUser } from 'tests/AuthContextUtils'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { render, screen, waitFor } from 'tests/utils'

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

jest.mock('features/auth/context/AuthContext')

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

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

beforeAll(() => {
mockAuthContextWithUser(
{
Expand Down
Loading

0 comments on commit 4ce6217

Please sign in to comment.