diff --git a/src/features/home/components/modules/video/VideoModal.native.test.tsx b/src/features/home/components/modules/video/VideoModal.native.test.tsx index 62e38abbdfa..3f402d001bf 100644 --- a/src/features/home/components/modules/video/VideoModal.native.test.tsx +++ b/src/features/home/components/modules/video/VideoModal.native.test.tsx @@ -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') @@ -28,6 +28,9 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => { } }) +jest.useFakeTimers() +const user = userEvent.setup() + describe('VideoModal', () => { beforeEach(() => { setFeatureFlags() @@ -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', @@ -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() { diff --git a/src/features/home/components/modules/video/VideoModule.native.test.tsx b/src/features/home/components/modules/video/VideoModule.native.test.tsx index 806028c83d2..3aac922f18d 100644 --- a/src/features/home/components/modules/video/VideoModule.native.test.tsx +++ b/src/features/home/components/modules/video/VideoModule.native.test.tsx @@ -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', () => ({ @@ -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('/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) }) @@ -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, @@ -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 () => { @@ -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() }) @@ -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() }) @@ -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 = { diff --git a/src/features/home/components/modules/video/VideoMonoOfferTile.native.test.tsx b/src/features/home/components/modules/video/VideoMonoOfferTile.native.test.tsx index a7da6cf378d..77639ae5f3b 100644 --- a/src/features/home/components/modules/video/VideoMonoOfferTile.native.test.tsx +++ b/src/features/home/components/modules/video/VideoMonoOfferTile.native.test.tsx @@ -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') @@ -28,7 +28,6 @@ const mockAnalyticsParams: OfferAnalyticsParams = { const hideModalMock = jest.fn() const user = userEvent.setup() - jest.useFakeTimers() describe('VideoMonoOfferTile', () => { @@ -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 }) }) @@ -49,7 +54,7 @@ describe('VideoMonoOfferTile', () => { const offerWithoutImage = omit(mockOffer, 'offer.thumbUrl') renderOfferVideoModule(offerWithoutImage) - await act(async () => {}) + await screen.findByText(mockOffer.offer.name) expect(screen.getByTestId('imagePlaceholder')).toBeOnTheScreen() }) @@ -57,23 +62,13 @@ describe('VideoMonoOfferTile', () => { 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) {