Skip to content

Commit

Permalink
(PC-30797) feat(tests): Bump msw from 1 to 2 (#6614)
Browse files Browse the repository at this point in the history
* (BSR) feat: bump msw to latest

* wip

* wip typing

Co-authored-by: bruno ebstein <[email protected]>
Co-authored-by: Inès Mouandjo Lobé <[email protected]>

* codemod msw/2/upgrade-recipe

Co-authored-by: bruno ebstein <[email protected]>
Co-authored-by: Inès Mouandjo Lobé <[email protected]>

* fix tests

* fix tests

* fix web tests

* Fix test apiHelpers

* Fix: OfferCTAButton

* Temporarily fix proxy tests by keeping msw 1.2.3 (on server)

* [DEV_REVIEW]: test -> remove unecessary act

* [DEV-REVIEW]: tests -> remove customExportConditions from config

* [DEV-REVIEW]: tests -> Replace waitFor by findByText

* [DEV_REVIEW]: tests -> remove TextEncoder

* [DEV_REVIEW]: tests -> OfferCTAButton

* [DEV-REVIEW]: tests -> OfferImageContainer

* [DEV_REVIEW]: tests -> ChangePassword

* Fix config (j'ai remis le code existant avant les retours sur la pr) + tentative de fix qq tests flaky connus

---------

Co-authored-by: Dan Nguyen <[email protected]>
Co-authored-by: LucasBeneston <[email protected]>
Co-authored-by: Cédric Le Sausse <[email protected]>
Co-authored-by: bruno ebstein <[email protected]>
Co-authored-by: Inès Mouandjo Lobé <[email protected]>
Co-authored-by: Inès Mouandjo Lobé <[email protected]>
  • Loading branch information
7 people authored Jul 26, 2024
1 parent d0f7990 commit be07e69
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 336 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { excludeCollectCoverageFrom } = require('./jest.excludeCollectCoverageFro
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironmentOptions: { customExportConditions: [''] },
moduleNameMapper: {
'^api(.*)$': '<rootDir>/src/api$1',
'^features(.*)$': '<rootDir>/src/features$1',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
"metro-react-native-babel-preset": "^0.76.9",
"mini-css-extract-plugin": "^1.5.0",
"mockdate": "^3.0.2",
"msw": "^1.2.3",
"msw": "^2.3.1",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"playwright": "^1.28.1",
"pnp-webpack-plugin": "^1.6.4",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@
"ts-node": "^10.7.0",
"typescript": "^4.3.5"
}
}
}
5 changes: 3 additions & 2 deletions src/api/apiHelpers.native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ describe('[api] helpers', () => {

it('needs authentication response when refresh token fails', async () => {
mockServer.postApi<RefreshResponse>('/v1/refresh_access_token', {
requestOptions: { persist: true },
responseOptions: { statusCode: 400 },
responseOptions: {
statusCode: 400,
},
})

mockGetTokenStatus.mockReturnValueOnce('expired')
Expand Down
8 changes: 5 additions & 3 deletions src/features/auth/pages/login/Login.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { NetworkErrorFixture, UnknownErrorFixture } from 'libs/recaptcha/fixture
import { storage } from 'libs/storage'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { fireEvent, render, act, screen, simulateWebviewMessage } from 'tests/utils'
import { act, fireEvent, render, screen, simulateWebviewMessage } from 'tests/utils'
import { SUGGESTION_DELAY_IN_MS } from 'ui/components/inputs/EmailInputWithSpellingHelp/useEmailSpellingHelp'
import { SNACK_BAR_TIME_OUT_LONG } from 'ui/components/snackBar/SnackBarContext'

Expand Down Expand Up @@ -804,8 +804,10 @@ function simulateSigninEmailNotValidated() {
function simulateSigninNetworkFailure() {
mockServer.postApi('/v1/signin', {
responseOptions: {
statusCode: 'network-error',
data: 'Network request failed',
data: {
code: 'NETWORK_REQUEST_FAILED',
general: ['Erreur réseau. Tu peux réessayer une fois la connexion réétablie'],
},
},
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ describe('<EmailResendModal />', () => {
it('should dismiss modal when close icon is pressed', async () => {
renderEmailResendModal({})

await act(async () => {
fireEvent.press(screen.getByLabelText('Fermer la modale'))
})
fireEvent.press(screen.getByLabelText('Fermer la modale'))

expect(onDismissMock).toHaveBeenCalledTimes(1)
})
Expand Down Expand Up @@ -68,14 +66,15 @@ describe('<EmailResendModal />', () => {

it('should display timer when resend email button is clicked', async () => {
renderEmailResendModal({})

await waitFor(() => {
expect(screen.getByText('Demander un nouveau lien')).toBeEnabled()
})

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))
fireEvent.press(screen.getByText('Demander un nouveau lien'))

expect(
screen.getByText(
await screen.findByText(
'Nous t’avons envoyé un nouveau lien. Une autre demande sera possible dans 60s.'
)
).toBeOnTheScreen()
Expand All @@ -87,10 +86,10 @@ describe('<EmailResendModal />', () => {
expect(screen.getByText('Demander un nouveau lien')).toBeEnabled()
})

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))
fireEvent.press(screen.getByText('Demander un nouveau lien'))

expect(
screen.getByText(
await screen.findByText(
'Une erreur s’est produite lors de l’envoi du nouveau lien. Réessaie plus tard.'
)
).toBeOnTheScreen()
Expand All @@ -102,9 +101,11 @@ describe('<EmailResendModal />', () => {
expect(screen.getByText('Demander un nouveau lien')).toBeEnabled()
})

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))
fireEvent.press(screen.getByText('Demander un nouveau lien'))

expect(screen.getByText('Tu as dépassé le nombre de renvois autorisés.')).toBeOnTheScreen()
expect(
await screen.findByText('Tu as dépassé le nombre de renvois autorisés.')
).toBeOnTheScreen()
})

it('should reset error message when another resend attempt is made', async () => {
Expand All @@ -118,8 +119,6 @@ describe('<EmailResendModal />', () => {

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))

expect(
screen.queryByText(
'Une erreur s’est produite lors de l’envoi du nouveau lien. Réessaie plus tard.'
Expand All @@ -132,15 +131,14 @@ describe('<EmailResendModal />', () => {
remainingResends: 0,
counterResetDatetime: '2023-09-30T12:58:04.065652Z',
})

renderEmailResendModal({})

await waitFor(() => {
expect(
screen.queryByText(
'Tu as dépassé le nombre de 3 demandes de lien autorisées. Tu pourras réessayer le 30/09/2023 à 12h58.'
)
).not.toBeOnTheScreen()
})
expect(
screen.queryByText(
'Tu as dépassé le nombre de 3 demandes de lien autorisées. Tu pourras réessayer le 30/09/2023 à 12h58.'
)
).not.toBeOnTheScreen()
})

describe('When shouldLogInfo remote config is false', () => {
Expand Down Expand Up @@ -181,12 +179,14 @@ describe('<EmailResendModal />', () => {
expect(screen.getByText('Demander un nouveau lien')).toBeEnabled()
})

await act(async () => fireEvent.press(screen.getByText('Demander un nouveau lien')))
fireEvent.press(screen.getByText('Demander un nouveau lien'))

expect(eventMonitoring.captureException).toHaveBeenCalledWith(
'Could not resend validation email: error',
{ level: 'info' }
)
await waitFor(() => {
expect(eventMonitoring.captureException).toHaveBeenCalledWith(
'Could not resend validation email: error',
{ level: 'info' }
)
})
})
})
})
Expand Down
38 changes: 29 additions & 9 deletions src/features/auth/pages/signup/SignupForm.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeat
import { eventMonitoring } from 'libs/monitoring'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen } from 'tests/utils'
import { act, fireEvent, render, screen, waitFor } from 'tests/utils'

import { SignupForm } from './SignupForm'

Expand Down Expand Up @@ -486,6 +486,8 @@ describe('Signup Form', () => {

renderSignupForm()

await act(async () => {})

await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))

expect(apiPostGoogleAuthorize).toHaveBeenCalledWith({
Expand All @@ -509,6 +511,8 @@ describe('Signup Form', () => {

renderSignupForm()

await act(async () => {})

await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))

expect(screen.getByText('Renseigne ton âge')).toBeOnTheScreen()
Expand Down Expand Up @@ -541,6 +545,7 @@ describe('Signup Form', () => {

renderSignupForm()

await act(async () => {})
await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))

const datePicker = screen.getByTestId('date-picker-spinner-native')
Expand Down Expand Up @@ -598,6 +603,7 @@ describe('Signup Form', () => {

renderSignupForm()

await act(async () => {})
await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))

const datePicker = screen.getByTestId('date-picker-spinner-native')
Expand Down Expand Up @@ -652,7 +658,13 @@ describe('Signup Form', () => {

renderSignupForm()

await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))
const ssoButton = await screen.findByTestId('S’inscrire avec Google')

await waitFor(async () => {
expect(ssoButton.props.focusable).toBeTruthy()
})

await act(async () => fireEvent.press(ssoButton))

const datePicker = screen.getByTestId('date-picker-spinner-native')
await act(async () =>
Expand Down Expand Up @@ -798,21 +810,29 @@ describe('Signup Form', () => {

renderSignupForm()

const ssoButton = await screen.findByTestId('S’inscrire avec Google')

expect(analytics.logStepperDisplayed).toHaveBeenNthCalledWith(
1,
StepperOrigin.HOME,
PreValidationSignupStep.Email,
undefined
)

await act(async () => fireEvent.press(await screen.findByTestId('S’inscrire avec Google')))
await waitFor(async () => {
expect(ssoButton.props.focusable).toBeTruthy()
})

await act(async () => fireEvent.press(ssoButton))

expect(analytics.logStepperDisplayed).toHaveBeenNthCalledWith(
2,
StepperOrigin.HOME,
PreValidationSignupStep.Birthday,
'SSO_signup'
)
await waitFor(() => {
expect(analytics.logStepperDisplayed).toHaveBeenNthCalledWith(
2,
StepperOrigin.HOME,
PreValidationSignupStep.Birthday,
'SSO_signup'
)
})

const datePicker = screen.getByTestId('date-picker-spinner-native')
await act(async () => {
Expand Down
22 changes: 12 additions & 10 deletions src/features/bookings/api/useOngoingOrEndedBooking.native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bookingsSnap } from 'features/bookings/fixtures/bookingsSnap'
import * as useNetInfoContextDefault from 'libs/network/NetInfoWrapper'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, renderHook } from 'tests/utils'
import { renderHook, waitFor } from 'tests/utils'

jest.mock('libs/react-query/usePersistQuery', () => ({
usePersistQuery: jest.requireActual('react-query').useQuery,
Expand Down Expand Up @@ -38,21 +38,23 @@ describe('useOngoingOrEndedBooking', () => {
const { result } = renderHook(() => useOngoingOrEndedBooking(booking.id), {
wrapper: ({ children }) => reactQueryProviderHOC(children),
})
await act(async () => {})

expect(result.current?.data?.id).toEqual(booking.id)
expect(result.current?.data?.stock.id).toEqual(booking.stock.id)
await waitFor(() => {
expect(result.current?.data?.id).toEqual(booking.id)
expect(result.current?.data?.stock.id).toEqual(booking.stock.id)
})
})

it('should return ended_bookings when there is one', async () => {
const booking = bookingsSnap.ended_bookings[0]
const { result } = renderHook(() => useOngoingOrEndedBooking(booking.id), {
wrapper: ({ children }) => reactQueryProviderHOC(children),
})
await act(async () => {})

expect(result.current?.data?.id).toEqual(booking.id)
expect(result.current?.data?.stock.id).toEqual(booking.stock.id)
await waitFor(() => {
expect(result.current?.data?.id).toEqual(booking.id)
expect(result.current?.data?.stock.id).toEqual(booking.stock.id)
})
})

it('should return null if no ongoing nor ended booking can be found', async () => {
Expand All @@ -61,8 +63,8 @@ describe('useOngoingOrEndedBooking', () => {
wrapper: ({ children }) => reactQueryProviderHOC(children),
})

await act(async () => {})

expect(result.current.data).toBeNull()
await waitFor(() => {
expect(result.current.data).toBeNull()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { analytics } from 'libs/analytics'
import { ContentTypes } from 'libs/contentful/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen } from 'tests/utils'
import { act, fireEvent, render, screen, waitFor } from 'tests/utils'

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

Expand Down Expand Up @@ -181,11 +181,13 @@ describe('<VideoCarouselModule />', () => {
})
await act(async () => fireEvent.press(nextVideoButton))

expect(analytics.logConsultVideo).toHaveBeenNthCalledWith(1, {
from: 'video_carousel_block',
moduleId: videoCarouselModuleFixture.id,
homeEntryId: videoCarouselModuleFixture.homeEntryId,
youtubeId: videoCarouselModuleFixture.items[2].youtubeVideoId,
await waitFor(() => {
expect(analytics.logConsultVideo).toHaveBeenNthCalledWith(1, {
from: 'video_carousel_block',
moduleId: videoCarouselModuleFixture.id,
homeEntryId: videoCarouselModuleFixture.homeEntryId,
youtubeId: videoCarouselModuleFixture.items[2].youtubeVideoId,
})
})
})

Expand Down
Loading

0 comments on commit be07e69

Please sign in to comment.