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

(BSR) refactor(Settings): remove SettingsContext #7593

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -239,7 +239,7 @@ exports[`<SetAddress/> should render correctly 1`] = `
class="css-text-1rynq56 r-color-1rmcaf9 r-fontFamily-g6644c r-fontSize-cygvgh r-lineHeight-u6qrkm"
dir="ltr"
>
Entre ton adresse
Recherche et sélectionne ton adresse
</div>
</div>
</label>
Expand Down
65 changes: 31 additions & 34 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if (process.env.NODE_ENV === 'development') {

import { AccessibilityFiltersWrapper } from 'features/accessibility/context/AccessibilityFiltersWrapper'
import { AuthWrapper } from 'features/auth/context/AuthWrapper'
import { SettingsWrapper } from 'features/auth/context/SettingsContext'
import { CulturalSurveyContextProvider } from 'features/culturalSurvey/context/CulturalSurveyContextProvider'
import { AsyncErrorBoundaryWithoutNavigation } from 'features/errors/pages/AsyncErrorBoundary'
import { ScreenErrorProvider } from 'features/errors/pages/ScreenErrorProvider'
Expand Down Expand Up @@ -91,39 +90,37 @@ const App: FunctionComponent = function () {
{/* All react-query calls should be nested inside NetInfoWrapper to ensure the user has internet connection */}
<NetInfoWrapper>
<FirestoreNetworkObserver />
<SettingsWrapper>
<AuthWrapper>
<LocationWrapper>
<AccessibilityFiltersWrapper>
<FavoritesWrapper>
<SearchAnalyticsWrapper>
<SearchWrapper>
<SnackBarProvider>
<CulturalSurveyContextProvider>
<SubscriptionContextProvider>
<SplashScreenProvider>
<PushNotificationsWrapper>
<ShareAppWrapper>
<OnboardingWrapper>
<OfflineModeContainer>
<ScreenErrorProvider>
<AppNavigationContainer />
</ScreenErrorProvider>
</OfflineModeContainer>
</OnboardingWrapper>
</ShareAppWrapper>
</PushNotificationsWrapper>
</SplashScreenProvider>
</SubscriptionContextProvider>
</CulturalSurveyContextProvider>
</SnackBarProvider>
</SearchWrapper>
</SearchAnalyticsWrapper>
</FavoritesWrapper>
</AccessibilityFiltersWrapper>
</LocationWrapper>
</AuthWrapper>
</SettingsWrapper>
<AuthWrapper>
<LocationWrapper>
<AccessibilityFiltersWrapper>
<FavoritesWrapper>
<SearchAnalyticsWrapper>
<SearchWrapper>
<SnackBarProvider>
<CulturalSurveyContextProvider>
<SubscriptionContextProvider>
<SplashScreenProvider>
<PushNotificationsWrapper>
<ShareAppWrapper>
<OnboardingWrapper>
<OfflineModeContainer>
<ScreenErrorProvider>
<AppNavigationContainer />
</ScreenErrorProvider>
</OfflineModeContainer>
</OnboardingWrapper>
</ShareAppWrapper>
</PushNotificationsWrapper>
</SplashScreenProvider>
</SubscriptionContextProvider>
</CulturalSurveyContextProvider>
</SnackBarProvider>
</SearchWrapper>
</SearchAnalyticsWrapper>
</FavoritesWrapper>
</AccessibilityFiltersWrapper>
</LocationWrapper>
</AuthWrapper>
</NetInfoWrapper>
</AnalyticsInitializer>
</ErrorBoundary>
Expand Down
63 changes: 30 additions & 33 deletions src/App.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ErrorBoundary } from 'react-error-boundary'

import { AccessibilityFiltersWrapper } from 'features/accessibility/context/AccessibilityFiltersWrapper'
import { AuthWrapper } from 'features/auth/context/AuthWrapper'
import { SettingsWrapper } from 'features/auth/context/SettingsContext'
import { CulturalSurveyContextProvider } from 'features/culturalSurvey/context/CulturalSurveyContextProvider'
import { AsyncErrorBoundaryWithoutNavigation } from 'features/errors/pages/AsyncErrorBoundary'
import { ScreenErrorProvider } from 'features/errors/pages/ScreenErrorProvider'
Expand Down Expand Up @@ -62,38 +61,36 @@ export function App() {
<ThemeProvider theme={theme}>
<SupportedBrowsersGate>
<SafeAreaProvider>
<SettingsWrapper>
<GoogleOAuthProvider clientId={env.GOOGLE_CLIENT_ID}>
<AuthWrapper>
<ErrorBoundary FallbackComponent={AsyncErrorBoundaryWithoutNavigation}>
<LocationWrapper>
<AccessibilityFiltersWrapper>
<FavoritesWrapper>
<SearchAnalyticsWrapper>
<SearchWrapper>
<SnackBarProvider>
<CulturalSurveyContextProvider>
<SubscriptionContextProvider>
<AppWebHead />
<OnboardingWrapper>
<ScreenErrorProvider>
<Suspense fallback={<LoadingPage />}>
<AppNavigationContainer />
</Suspense>
</ScreenErrorProvider>
</OnboardingWrapper>
</SubscriptionContextProvider>
</CulturalSurveyContextProvider>
</SnackBarProvider>
</SearchWrapper>
</SearchAnalyticsWrapper>
</FavoritesWrapper>
</AccessibilityFiltersWrapper>
</LocationWrapper>
</ErrorBoundary>
</AuthWrapper>
</GoogleOAuthProvider>
</SettingsWrapper>
<GoogleOAuthProvider clientId={env.GOOGLE_CLIENT_ID}>
<AuthWrapper>
<ErrorBoundary FallbackComponent={AsyncErrorBoundaryWithoutNavigation}>
<LocationWrapper>
<AccessibilityFiltersWrapper>
<FavoritesWrapper>
<SearchAnalyticsWrapper>
<SearchWrapper>
<SnackBarProvider>
<CulturalSurveyContextProvider>
<SubscriptionContextProvider>
<AppWebHead />
<OnboardingWrapper>
<ScreenErrorProvider>
<Suspense fallback={<LoadingPage />}>
<AppNavigationContainer />
</Suspense>
</ScreenErrorProvider>
</OnboardingWrapper>
</SubscriptionContextProvider>
</CulturalSurveyContextProvider>
</SnackBarProvider>
</SearchWrapper>
</SearchAnalyticsWrapper>
</FavoritesWrapper>
</AccessibilityFiltersWrapper>
</LocationWrapper>
</ErrorBoundary>
</AuthWrapper>
</GoogleOAuthProvider>
</SafeAreaProvider>
</SupportedBrowsersGate>
</ThemeProvider>
Expand Down
44 changes: 0 additions & 44 deletions src/features/auth/context/SettingsContext.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/features/auth/context/__mocks__/SettingsContext.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions src/features/auth/context/__mocks__/useSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defaultSettings } from 'features/auth/fixtures/fixtures'

export const useSettings = jest.fn().mockReturnValue({
xlecunff-pass marked this conversation as resolved.
Show resolved Hide resolved
data: defaultSettings,
isLoading: false,
})
22 changes: 22 additions & 0 deletions src/features/auth/context/useSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useQuery } from 'react-query'

import { api } from 'api/api'
import { SettingsResponse } from 'api/gen'
import { defaultSettings } from 'features/auth/fixtures/fixtures'
import { QueryKeys } from 'libs/queryKeys'

// arbitrary. Should not change that often though
const STALE_TIME_APP_SETTINGS = 5 * 60 * 1000

export const useSettings = () => {
const { data, isLoading } = useQuery<SettingsResponse>(
xlecunff-pass marked this conversation as resolved.
Show resolved Hide resolved
[QueryKeys.SETTINGS],
() => api.getNativeV1Settings(),
{
staleTime: STALE_TIME_APP_SETTINGS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avant on avait, ça, ce n'est plus nécessaire ?

enabled: !!netInfo.isConnected && !!netInfo.isInternetReachable,

initialData: defaultSettings,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avant, on n'avait pas de données par défaut

le defaultSettings actuellement utilisé est censé etre utilisé par des tests, avec des données invalides en prod

exemple: on a un localhost qui traine dedans

objectStorageUrl: 'https://localhost-storage',

je ne suis pas contre avoir des données par défaut

je pense qu'il faudrait éviter d'utiliser cette fixture

}
)

return { data, isLoading }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'

import { navigate, replace } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/tests/setSettings'
import { StepperOrigin } from 'features/navigation/RootNavigator/types'
import { captureMonitoringError } from 'libs/monitoring/errors'
import { eventMonitoring } from 'libs/monitoring/services'
import { useNetInfoContext as useNetInfoContextDefault } from 'libs/network/NetInfoWrapper'
import { NetworkErrorFixture, UnknownErrorFixture } from 'libs/recaptcha/fixtures'
import { mockSettings } from 'tests/mockSettings'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen, simulateWebviewMessage, waitFor } from 'tests/utils'
Expand Down Expand Up @@ -38,7 +38,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('<ForgottenPassword />', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should match snapshot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { api } from 'api/api'
import { ApiError } from 'api/ApiError'
import { isAPIExceptionCapturedAsInfo } from 'api/apiHelpers'
import { SettingsResponse } from 'api/gen'
import { useSettingsContext } from 'features/auth/context/SettingsContext'
import { useSettings } from 'features/auth/context/useSettings'
import { StepperOrigin, UseNavigationType } from 'features/navigation/RootNavigator/types'
import { captureMonitoringError } from 'libs/monitoring/errors'
import { useNetInfoContext } from 'libs/network/NetInfoWrapper'
Expand All @@ -31,7 +31,7 @@ type FormValues = {
}

export const ForgottenPassword = () => {
const { data: settings, isLoading: areSettingsLoading } = useSettingsContext()
const { data: settings, isLoading: areSettingsLoading } = useSettings()

const {
control,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { SafeAreaProvider } from 'react-native-safe-area-context'

import { mockSettings } from 'tests/mockSettings'
import { render, checkAccessibilityFor, screen, waitFor } from 'tests/utils/web'

import { ForgottenPassword } from './ForgottenPassword'
Expand All @@ -13,6 +14,7 @@ jest.mock('uuid', () => {
v4: jest.fn(() => value++),
}
})
mockSettings()

describe('<ForgottenPassword/>', () => {
describe('Accessibility', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/features/auth/pages/login/Login.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
UserProfileResponse,
} from 'api/gen'
import { AuthContext } from 'features/auth/context/AuthContext'
import { setSettings } from 'features/auth/tests/setSettings'
import { SignInResponseFailure } from 'features/auth/types'
import { favoriteOfferResponseSnap } from 'features/favorites/fixtures/favoriteOfferResponseSnap'
import { favoriteResponseSnap } from 'features/favorites/fixtures/favoriteResponseSnap'
Expand All @@ -30,6 +29,7 @@ import { RemoteStoreFeatureFlags } from 'libs/firebase/firestore/types'
import * as monitoringErrorsModule from 'libs/monitoring/errors'
import { NetworkErrorFixture, UnknownErrorFixture } from 'libs/recaptcha/fixtures'
import { storage } from 'libs/storage'
import { mockSettings } from 'tests/mockSettings'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen, simulateWebviewMessage } from 'tests/utils'
Expand Down Expand Up @@ -85,6 +85,8 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {
}
})

mockSettings({ isRecaptchaEnabled: false })

describe('<Login/>', () => {
beforeEach(() => {
setFeatureFlags([RemoteStoreFeatureFlags.WIP_ENABLE_GOOGLE_SSO])
Expand Down Expand Up @@ -644,7 +646,11 @@ describe('<Login/>', () => {

describe('Login with ReCatpcha', () => {
beforeAll(() => {
setSettings()
mockSettings({ isRecaptchaEnabled: true })
})

afterAll(() => {
mockSettings({ isRecaptchaEnabled: false })
})

it('should not open reCAPTCHA challenge modal before clicking on login button', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/features/auth/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import styled from 'styled-components/native'
import { useSignIn } from 'features/auth/api/useSignIn'
import { AuthenticationButton } from 'features/auth/components/AuthenticationButton/AuthenticationButton'
import { SSOButtonBase } from 'features/auth/components/SSOButton/SSOButtonBase'
import { useSettingsContext } from 'features/auth/context/SettingsContext'
import { useSettings } from 'features/auth/context/useSettings'
import { loginSchema } from 'features/auth/pages/login/schema/loginSchema'
import { SignInResponseFailure } from 'features/auth/types'
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ type Props = {

export const Login: FunctionComponent<Props> = memo(function Login(props) {
const enableGoogleSSO = useFeatureFlag(RemoteStoreFeatureFlags.WIP_ENABLE_GOOGLE_SSO)
const { data: settings } = useSettingsContext()
const { data: settings } = useSettings()
const { params } = useRoute<UseRouteType<'Login'>>()
const { navigate } = useNavigation<UseNavigationType>()
const { showInfoSnackBar, showErrorSnackBar } = useSnackBarContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react'
import { Linking } from 'react-native'

import { navigate } from '__mocks__/@react-navigation/native'
import { setSettings } from 'features/auth/tests/setSettings'
import { analytics } from 'libs/analytics/provider'
import { env } from 'libs/environment/env'
import { useNetInfoContext as useNetInfoContextDefault } from 'libs/network/NetInfoWrapper'
import { UnknownErrorFixture } from 'libs/recaptcha/fixtures'
import { mockAuthContextWithoutUser } from 'tests/AuthContextUtils'
import { mockSettings } from 'tests/mockSettings'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
import { act, fireEvent, render, screen, simulateWebviewMessage, waitFor } from 'tests/utils'

Expand Down Expand Up @@ -50,7 +50,7 @@ jest.mock('react-native/Libraries/Animated/createAnimatedComponent', () => {

describe('<AcceptCgu/>', () => {
beforeEach(() => {
setSettings()
mockSettings()
})

it('should render correctly', () => {
Expand Down
Loading
Loading