Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-33973) fix(VideoModal): remove unnecessary test #7542

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading