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-32585) fix(search): bug fix on autocomplete #7067

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 @@ -14,7 +14,9 @@ import {
mockHitUnknownCategory,
mockHitUnknownNativeCategory,
mockHitUnknownNativeCategoryAndCategory,
mockHitWithNativeCategory,
mockHitWithOnlyCategory,
mockHitWithUnavailableCategory,
mockHitWithoutCategoryAndNativeCategory,
mockHitsWithDifferentCounts,
} from 'features/search/fixtures/autocompleteHits'
Expand Down Expand Up @@ -717,5 +719,40 @@ describe('AutocompleteOfferItem component', () => {
expect(await screen.findByText('Livres')).toBeOnTheScreen()
})
})

it('should not display category suggestion when not native category suggested and searchGroup is unavailable', async () => {
render(
<AutocompleteOfferItem
hit={mockHitWithUnavailableCategory}
sendEvent={mockSendEvent}
shouldShowCategory
addSearchHistory={jest.fn()}
/>,
{
wrapper: ({ children }) => reactQueryProviderHOC(children),
}
)

await screen.findByText('cinéma')

expect(screen.queryByText('dans')).not.toBeOnTheScreen()
})

it('should display native category suggestion on search landing', async () => {
render(
<AutocompleteOfferItem
hit={mockHitWithNativeCategory}
sendEvent={mockSendEvent}
shouldShowCategory
addSearchHistory={jest.fn()}
offerCategories={[]}
/>,
{
wrapper: ({ children }) => reactQueryProviderHOC(children),
}
)

expect(await screen.findByText('Séances de cinéma')).toBeOnTheScreen()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function AutocompleteOfferItem({

const shouldDisplayNativeCategory =
hasMostPopularHitNativeCategory &&
isAssociatedMostPopularNativeCategoryToMostPopularCategory &&
((isQueryFromSearchN1 && isNativeCategoryRelatedToSearchGroup) || !isQueryFromSearchN1) &&
!hasSeveralCategoriesFromNativeCategory

const isLivresPapierNativeCategory =
Expand Down Expand Up @@ -190,18 +190,19 @@ export function AutocompleteOfferItem({
hideSuggestions()
}

const shouldDisplaySuggestion =
const shouldDisplayCategorySuggestion =
shouldShowCategory && (hasMostPopularHitNativeCategory || hasMostPopularHitCategory)

const categoryToDisplay = shouldUseSearchGroupInsteadOfNativeCategory
? searchGroupLabel
: mostPopularNativeCategoryValue
const categoryToDisplay =
shouldUseSearchGroupInsteadOfNativeCategory && searchGroupLabel !== 'None'
? searchGroupLabel
: mostPopularNativeCategoryValue

const testID = `autocompleteOfferItem_${hit.objectID}`

return (
<SuggestionContainer hit={hit} onPress={onPress} testID={testID}>
{shouldDisplaySuggestion && categoryToDisplay ? (
{shouldDisplayCategorySuggestion && categoryToDisplay ? (
<Suggestion categoryToDisplay={categoryToDisplay} />
) : undefined}
</SuggestionContainer>
Expand Down
57 changes: 56 additions & 1 deletion src/features/search/fixtures/autocompleteHits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const mockHitSeveralCategoriesWithoutAssociationToNativeCategory: Algolia
{
attribute: '',
operator: '',
value: NativeCategoryIdEnumv2.ARTS_VISUELS,
value: NativeCategoryIdEnumv2.RENCONTRES_EN_LIGNE,
count: 10,
},
],
Expand Down Expand Up @@ -361,3 +361,58 @@ export const mockHitsWithDifferentCounts: AlgoliaSuggestionHit = {
},
},
}

export const mockHitWithUnavailableCategory: AlgoliaSuggestionHit = {
...mockHit,
[env.ALGOLIA_OFFERS_INDEX_NAME]: {
exact_nb_hits: 2,
facets: {
exact_matches: {
'offer.nativeCategoryId': [],
'offer.searchGroupNamev2': [],
},
analytics: {
['offer.searchGroupNamev2']: [
{
attribute: 'offer.searchGroupNamev2',
operator: ':',
value: SearchGroupNameEnumv2.FILMS_SERIES_CINEMA,
count: 6172,
},
],
['offer.nativeCategoryId']: [],
},
},
},
}

export const mockHitWithNativeCategory: AlgoliaSuggestionHit = {
...mockHit,
[env.ALGOLIA_OFFERS_INDEX_NAME]: {
exact_nb_hits: 2,
facets: {
exact_matches: {
'offer.nativeCategoryId': [],
'offer.searchGroupNamev2': [],
},
analytics: {
['offer.searchGroupNamev2']: [
{
attribute: 'offer.searchGroupNamev2',
operator: ':',
value: SearchGroupNameEnumv2.LIVRES,
count: 6172,
},
],
['offer.nativeCategoryId']: [
{
attribute: '',
operator: '',
value: NativeCategoryIdEnumv2.SEANCES_DE_CINEMA,
count: 10,
},
],
},
},
},
}
Loading