Skip to content

Commit

Permalink
(PC-33973) fix(VideoModal): remove unnecessary test
Browse files Browse the repository at this point in the history
  • Loading branch information
imouandjolobe-pass committed Jan 17, 2025
1 parent 906c78a commit 27f78ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { subcategoriesDataTest } from 'libs/subcategories/fixtures/subcategories
import { MODAL_TO_SHOW_TIME } from 'tests/constants'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen } from 'tests/utils'
import { act, userEvent, render, screen } from 'tests/utils'

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

Expand All @@ -28,6 +28,9 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {
}
})

jest.useFakeTimers()
const user = userEvent.setup()

describe('VideoModal', () => {
beforeEach(() => {
setFeatureFlags()
Expand All @@ -49,9 +52,7 @@ describe('VideoModal', () => {

const closeButton = screen.getByTestId('Fermer la modale vidéo')

await act(async () => {
fireEvent.press(closeButton)
})
await user.press(closeButton)

expect(analytics.logHasDismissedModal).toHaveBeenNthCalledWith(1, {
moduleId: 'abcd',
Expand All @@ -60,13 +61,6 @@ describe('VideoModal', () => {
seenDuration: 135,
})
})

it('should render properly with FF on', async () => {
// TODO(PC-33973): test passes with no FF on
renderVideoModal()

expect(await screen.findByText('Découvre Lujipeka')).toBeOnTheScreen()
})
})

function renderVideoModal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { setFeatureFlags } from 'libs/firebase/firestore/featureFlags/__tests__/
import { subcategoriesDataTest } from 'libs/subcategories/fixtures/subcategoriesResponse'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen, waitFor } from 'tests/utils'
import { userEvent, render, screen } from 'tests/utils'

const mockShowModal = jest.fn()
jest.mock('ui/components/modals/useModal', () => ({
Expand All @@ -25,20 +25,29 @@ const mockUseVideoOffers = useVideoOffers as jest.Mock

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

const user = userEvent.setup()
jest.useFakeTimers()

describe('VideoModule', () => {
beforeEach(() => {
setFeatureFlags()
mockServer.getApi<SubcategoriesResponseModelv2>('/v1/subcategories/v2', subcategoriesDataTest)
})

it('should render properly', async () => {
mockUseVideoOffers.mockReturnValueOnce({ offers: [offerFixture] })
renderVideoModule()

expect(await screen.findByText(offerFixture.offer.name)).toBeOnTheScreen()
})

it('should show modal when pressing video thumbnail', async () => {
mockUseVideoOffers.mockReturnValueOnce({ offers: [offerFixture] })
renderVideoModule()
await act(async () => {})

const button = screen.getByTestId('video-thumbnail')

fireEvent.press(button)
await user.press(button)

expect(mockShowModal).toHaveBeenCalledTimes(1)
})
Expand All @@ -47,7 +56,7 @@ describe('VideoModule', () => {
mockUseVideoOffers.mockReturnValueOnce({ offers: [offerFixture] })
renderVideoModule()

await act(async () => {})
await screen.findByText(offerFixture.offer.name)

expect(analytics.logModuleDisplayedOnHomepage).toHaveBeenNthCalledWith(1, {
moduleId: videoModuleFixture.id,
Expand All @@ -62,9 +71,7 @@ describe('VideoModule', () => {
mockUseVideoOffers.mockReturnValueOnce({ offers: [] })
renderVideoModule()

await waitFor(() => {
expect(analytics.logModuleDisplayedOnHomepage).not.toHaveBeenCalled()
})
expect(analytics.logModuleDisplayedOnHomepage).not.toHaveBeenCalled()
})

it('should render multi offer component if multiples offers', async () => {
Expand All @@ -73,7 +80,7 @@ describe('VideoModule', () => {

const multiOfferList = screen.getByTestId('video-multi-offers-module-list')

await act(async () => {})
await screen.findByText(videoModuleFixture.title)

expect(multiOfferList).toBeOnTheScreen()
})
Expand All @@ -84,7 +91,7 @@ describe('VideoModule', () => {

const multiOfferList = screen.getByTestId('mobile-video-module')

await act(async () => {})
await screen.findByText(offerFixture.offer.name)

expect(multiOfferList).toBeOnTheScreen()
})
Expand All @@ -95,19 +102,10 @@ describe('VideoModule', () => {

const multiOfferList = screen.getByTestId('desktop-video-module')

await act(async () => {})
await screen.findByText(offerFixture.offer.name)

expect(multiOfferList).toBeOnTheScreen()
})

it('should render properly with FF on', async () => {
// TODO(PC-33973): test passes with no FF on

mockUseVideoOffers.mockReturnValueOnce({ offers: [offerFixture] })
renderVideoModule()

expect(await screen.findByText('La nuit des temps')).toBeOnTheScreen()
})
})

const offerFixture = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { subcategoriesDataTest } from 'libs/subcategories/fixtures/subcategories
import { Offer } from 'shared/offer/types'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, render, screen, userEvent } from 'tests/utils'
import { render, screen, userEvent } from 'tests/utils'

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

Expand All @@ -28,7 +28,6 @@ const mockAnalyticsParams: OfferAnalyticsParams = {
const hideModalMock = jest.fn()

const user = userEvent.setup()

jest.useFakeTimers()

describe('VideoMonoOfferTile', () => {
Expand All @@ -37,10 +36,16 @@ describe('VideoMonoOfferTile', () => {
setFeatureFlags()
})

it('should render properly', async () => {
renderOfferVideoModule()

expect(await screen.findByText(mockOffer.offer.name)).toBeOnTheScreen()
})

it('should redirect to an offer when pressing it', async () => {
renderOfferVideoModule()

await user.press(screen.getByText('La nuit des temps'))
await user.press(screen.getByText(mockOffer.offer.name))

expect(navigate).toHaveBeenCalledWith('Offer', { id: 102_280 })
})
Expand All @@ -49,31 +54,21 @@ describe('VideoMonoOfferTile', () => {
const offerWithoutImage = omit(mockOffer, 'offer.thumbUrl')
renderOfferVideoModule(offerWithoutImage)

await act(async () => {})
await screen.findByText(mockOffer.offer.name)

expect(screen.getByTestId('imagePlaceholder')).toBeOnTheScreen()
})

it('should log ConsultOffer on when pressing it', async () => {
renderOfferVideoModule()

await user.press(screen.getByText('La nuit des temps'))
await user.press(screen.getByText(mockOffer.offer.name))

expect(analytics.logConsultOffer).toHaveBeenNthCalledWith(1, {
offerId: +mockOffer.objectID,
...mockAnalyticsParams,
})
})

describe('With FF on', () => {
it('should render properly', async () => {
// TODO(PC-33973): test passes with no FF on

renderOfferVideoModule()

expect(await screen.findByText('La nuit des temps')).toBeOnTheScreen()
})
})
})

function renderOfferVideoModule(offer?: Offer) {
Expand Down

0 comments on commit 27f78ba

Please sign in to comment.