Skip to content

Commit

Permalink
(PC-33608) refactor(LocationLabel): use Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
nmajorfrances-pass committed Nov 29, 2024
1 parent 7fd7435 commit 851c926
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ exports[`HomeLocationModal should render correctly if modal visible 1`] = `
]
}
>
France entière
France Entière
</Text>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ exports[`SearchLocationModal should render correctly if modal visible 1`] = `
]
}
>
France entière
France Entière
</Text>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ exports[`<ThematicSearch/> book offerCategory should render <ThematicSearch /> 1
]
}
>
Me localiser
France Entière
</Text>
</View>
<Modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import * as Auth from 'features/auth/context/AuthContext'
import { nonBeneficiaryUser } from 'fixtures/user'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { LocationLabel } from 'libs/location/types'
import { Credit, useAvailableCredit } from 'shared/user/useAvailableCredit'
import { mockServer } from 'tests/mswServer'
import { reactQueryProviderHOC } from 'tests/reactQueryProviderHOC'
Expand Down Expand Up @@ -96,7 +97,7 @@ describe('HomeHeader', () => {

await screen.findByTestId('Ouvrir la modale de localisation depuis le widget')

expect(screen.getByText('France entière')).toBeTruthy()
expect(screen.getByText(LocationLabel.everywhereLabel)).toBeTruthy()
})

it('should not show LocationWidget isDesktopViewport is true', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'

import { LocationFilterChoice } from 'features/internal/marketingAndCommunication/atoms/LocationFilterChoice'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { render, fireEvent, screen } from 'tests/utils'

describe('<LocationFilterChoice />', () => {
it('should call onChange with LocationMode.AROUND_ME or EVERYWHERE', () => {
const onChange = jest.fn()
render(<LocationFilterChoice onChange={onChange} />)

fireEvent.press(screen.getByText('France entière'))
fireEvent.press(screen.getByText(LocationLabel.everywhereLabel))

expect(onChange).toHaveBeenNthCalledWith(1, {
locationType: LocationMode.EVERYWHERE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState } from 'react'

import { LocationChoice } from 'features/search/components/LocationChoice'
import { LocationFilter } from 'features/search/types'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { Li } from 'ui/components/Li'
import { VerticalUl } from 'ui/components/Ul'
import { BicolorEverywhere as Everywhere } from 'ui/svg/icons/BicolorEverywhere'
Expand All @@ -25,7 +25,7 @@ export const LocationFilterChoice = ({ onChange }: Props) => {
<Li>
<Spacer.Column numberOfSpaces={4} />
<LocationChoice
label="France entière"
label={LocationLabel.everywhereLabel}
Icon={Everywhere}
onPress={onPressEverywhere}
isSelected={LocationMode.EVERYWHERE === selected}
Expand Down
4 changes: 2 additions & 2 deletions src/features/location/components/LocationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LocationModalFooter } from 'features/location/components/LocationModalF
import { LOCATION_PLACEHOLDER } from 'features/location/constants'
import { LocationState } from 'features/location/types'
import { Action } from 'features/search/context/reducer'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { SuggestedPlace } from 'libs/place/types'
import { LocationSearchFilters } from 'shared/location/LocationSearchFilters'
import { LocationSearchInput } from 'shared/location/LocationSearchInput'
Expand Down Expand Up @@ -168,7 +168,7 @@ export const LocationModal = ({
onPress={selectLocationMode(LocationMode.EVERYWHERE)}
icon={WorldPosition}
color={everywhereLocationModeColor}
title="France entière"
title={LocationLabel.everywhereLabel}
/>
</StyledScrollView>
</AppModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'

import { LocationSearchWidget } from 'features/location/components/LocationSearchWidget'
import { useLocation } from 'libs/location'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { act, fireEvent, render, screen } from 'tests/utils'

const mockShowModal = jest.fn()
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('LocationSearchWidget', () => {
${true} | ${null}
${true} | ${undefined}
`(
"should render a filled location pointer and the text 'Ma position' if the user is geolocated",
`should render a filled location pointer and the text ${LocationLabel.aroundMeLabel} if the user is geolocated`,
async ({ hasGeolocPosition, place }) => {
mockUseLocation.mockReturnValueOnce({
hasGeolocPosition,
Expand All @@ -55,7 +55,7 @@ describe('LocationSearchWidget', () => {
render(<LocationSearchWidget />)

expect(screen.getByTestId('location pointer filled')).toBeOnTheScreen()
expect(screen.getByText('Ma position')).toBeOnTheScreen()
expect(screen.getByText(LocationLabel.aroundMeLabel)).toBeOnTheScreen()
}
)

Expand All @@ -64,7 +64,7 @@ describe('LocationSearchWidget', () => {
${false} | ${null}
${false} | ${undefined}
`(
"should render a location pointer(not filled ) and the text 'France entière' if the user is not geolocated and has not selected a custom position",
`should render a location pointer(not filled ) and the text ${LocationLabel.everywhereLabel} if the user is not geolocated and has not selected a custom position`,
async ({ hasGeolocPosition, place }) => {
mockUseLocation.mockReturnValueOnce({
hasGeolocPosition,
Expand All @@ -76,7 +76,7 @@ describe('LocationSearchWidget', () => {
render(<LocationSearchWidget />)

expect(screen.getByTestId('location pointer not filled')).toBeOnTheScreen()
expect(screen.getByText('France entière')).toBeOnTheScreen()
expect(screen.getByText(LocationLabel.everywhereLabel)).toBeOnTheScreen()
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import { LocationWidgetDesktop } from 'features/location/components/LocationWidgetDesktop'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { useLocation } from 'libs/location'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { storage } from 'libs/storage'
import { act, fireEvent, render, screen } from 'tests/utils'

Expand Down Expand Up @@ -46,7 +46,7 @@ describe('LocationWidgetDesktop', () => {
${true} | ${null}
${true} | ${undefined}
`(
"should render a filled location pointer and the text 'Ma position' if the user is geolocated",
`should render a filled location pointer and the text ${LocationLabel.aroundMeLabel} if the user is geolocated`,
async ({ hasGeolocPosition, place }) => {
mockUseLocation.mockReturnValueOnce({
hasGeolocPosition,
Expand All @@ -58,7 +58,7 @@ describe('LocationWidgetDesktop', () => {
renderLocationWidgetDesktop()

expect(screen.getByTestId('location pointer filled')).toBeOnTheScreen()
expect(screen.getByText('Ma position')).toBeOnTheScreen()
expect(screen.getByText(LocationLabel.aroundMeLabel)).toBeOnTheScreen()
}
)

Expand All @@ -67,7 +67,7 @@ describe('LocationWidgetDesktop', () => {
${false} | ${null}
${false} | ${undefined}
`(
"should render a location pointer(not filled ) and the text 'France entière' if the user is not geolocated and has not selected a custom position",
'should render a location pointer(not filled ) and the text LocationLabel.everywhereLabel if the user is not geolocated and has not selected a custom position',
async ({ hasGeolocPosition, place }) => {
mockUseLocation.mockReturnValueOnce({
hasGeolocPosition,
Expand All @@ -80,7 +80,7 @@ describe('LocationWidgetDesktop', () => {
renderLocationWidgetDesktop()

expect(screen.getByTestId('location pointer not filled')).toBeOnTheScreen()
expect(screen.getByText('France entière')).toBeOnTheScreen()
expect(screen.getByText(LocationLabel.everywhereLabel)).toBeOnTheScreen()
}
)

Expand Down Expand Up @@ -167,7 +167,7 @@ describe('LocationWidgetDesktop', () => {
).not.toBeOnTheScreen()
})

it('should hide tooltip when taping “France entière”', async () => {
it(`should hide tooltip when taping ${LocationLabel.everywhereLabel}`, async () => {
jest.useFakeTimers()
renderLocationWidgetDesktop()

Expand All @@ -179,7 +179,7 @@ describe('LocationWidgetDesktop', () => {
'Configure ta position et découvre les offres dans la zone géographique de ton choix.'
)

const locationButton = screen.getByText('France entière')
const locationButton = screen.getByText(LocationLabel.everywhereLabel)
fireEvent.press(locationButton)

expect(
Expand Down
8 changes: 4 additions & 4 deletions src/features/location/helpers/getLocationTitle.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { SuggestedPlace } from 'libs/place/types'

export const getLocationTitle = (place: SuggestedPlace | null, locationMode: LocationMode) => {
switch (locationMode) {
case LocationMode.AROUND_PLACE:
return place?.label ?? ''
case LocationMode.EVERYWHERE:
return 'France entière'
return LocationLabel.everywhereLabel
case LocationMode.AROUND_ME:
return 'Ma position'
return LocationLabel.aroundMeLabel

default:
return 'France entière'
return LocationLabel.everywhereLabel
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as useFilterCountAPI from 'features/search/helpers/useFilterCount/useFi
import { BooksNativeCategoriesEnum, SearchState, SearchView } from 'features/search/types'
import * as useFeatureFlagAPI from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { GeoCoordinates, Position } from 'libs/location'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { mockedSuggestedVenue } from 'libs/venue/fixtures/mockedSuggestedVenues'
import { act, fireEvent, render, screen } from 'tests/utils'

Expand Down Expand Up @@ -553,7 +553,7 @@ describe('SearchBox component', () => {

await act(async () => {})

expect(screen.getByText('France entière')).toBeOnTheScreen()
expect(screen.getByText(LocationLabel.everywhereLabel)).toBeOnTheScreen()
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SearchHeader } from 'features/search/components/SearchHeader/SearchHead
import { initialSearchState } from 'features/search/context/reducer'
import * as useFilterCountAPI from 'features/search/helpers/useFilterCount/useFilterCount'
import * as useFeatureFlag from 'libs/firebase/firestore/featureFlags/useFeatureFlag'
import { LocationLabel } from 'libs/location/types'
import { render, screen, waitFor, within } from 'tests/utils'

jest.spyOn(useFeatureFlag, 'useFeatureFlag').mockReturnValue(false)
Expand Down Expand Up @@ -68,7 +69,7 @@ describe('SearchHeader component', () => {
await waitFor(() => {
const insideLocationWidget = within(screen.getByTestId('InsideLocationWidget'))

expect(insideLocationWidget.getByText('France entière')).toBeOnTheScreen()
expect(insideLocationWidget.getByText(LocationLabel.everywhereLabel)).toBeOnTheScreen()
})
})

Expand All @@ -78,7 +79,7 @@ describe('SearchHeader component', () => {
await waitFor(() => {
const insideLocationWidget = within(screen.getByTestId('InsideLocationWidget'))

expect(insideLocationWidget.queryByText('France entière')).not.toBeOnTheScreen()
expect(insideLocationWidget.queryByText(LocationLabel.everywhereLabel)).not.toBeOnTheScreen()
})
})

Expand All @@ -88,7 +89,9 @@ describe('SearchHeader component', () => {
await waitFor(() => {
const searchHeaderTitleContainer = within(screen.getByTestId('SearchHeaderTitleContainer'))

expect(searchHeaderTitleContainer.queryByText('France entière')).not.toBeOnTheScreen()
expect(
searchHeaderTitleContainer.queryByText(LocationLabel.everywhereLabel)
).not.toBeOnTheScreen()
})
})

Expand All @@ -98,7 +101,7 @@ describe('SearchHeader component', () => {
await waitFor(() => {
const insideLocationWidget = within(screen.getByTestId('InsideLocationWidget'))

expect(insideLocationWidget.queryByText('France entière')).not.toBeOnTheScreen()
expect(insideLocationWidget.queryByText(LocationLabel.everywhereLabel)).not.toBeOnTheScreen()
})
})

Expand All @@ -108,7 +111,7 @@ describe('SearchHeader component', () => {
await waitFor(() => {
const searchHeaderTitleContainer = within(screen.getByTestId('SearchHeaderTitleContainer'))

expect(searchHeaderTitleContainer.getByText('France entière')).toBeOnTheScreen()
expect(searchHeaderTitleContainer.getByText(LocationLabel.everywhereLabel)).toBeOnTheScreen()
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/features/search/context/SearchWrapper.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useLocation,
} from 'libs/location'
import { getGeolocPosition } from 'libs/location/geolocation/getGeolocPosition/getGeolocPosition'
import { LocationMode } from 'libs/location/types'
import { LocationLabel, LocationMode } from 'libs/location/types'
import { SuggestedPlace } from 'libs/place/types'
import { act, fireEvent, render, screen } from 'tests/utils'

Expand Down Expand Up @@ -61,7 +61,7 @@ describe('SearchWrapper', () => {
expect(screen.getByText(LocationMode.AROUND_ME)).toBeOnTheScreen()
})

it('should update locationType with type Everywhere when Location Context is switched to "France Entière"', async () => {
it(`should update locationType with type Everywhere when Location Context is switched to ${LocationLabel.everywhereLabel}`, async () => {
renderDummyComponent()

await act(async () => {
Expand Down
5 changes: 5 additions & 0 deletions src/libs/location/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export enum LocationMode {
EVERYWHERE = 'EVERYWHERE',
}

export const enum LocationLabel {
everywhereLabel = 'France Entière',
aroundMeLabel = 'Ma position',
}

export type GeolocationError = {
type: GeolocPositionError
message: string
Expand Down

0 comments on commit 851c926

Please sign in to comment.