From f6a208b1d057479c26b1c2eea5d1143e1f1ad612 Mon Sep 17 00:00:00 2001 From: Andrea Saez Date: Tue, 17 Sep 2024 14:14:40 +0200 Subject: [PATCH] (PC-31828)[PRO] fix: make EAN search input required on subcat error --- .../DetailsEanSearch/DetailsEanSearch.spec.tsx | 9 ++++++--- .../DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx index 916d7495cf1..4ecbe6a7a80 100644 --- a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx +++ b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx @@ -103,11 +103,14 @@ describe('DetailsEanSearch', () => { subcategoryId: 'SUPPORT_PHYSIQUE_MUSIQUE_VINYLE', }) - expect(screen.getByText(subCatErrorMessage)).toBeInTheDocument() - const eanInput = screen.getByRole('textbox', { name: inputLabel }) - await userEvent.type(eanInput, '9781234567897') + // Input is now required. + expect(eanInput).toBeRequired() + + // Error cannot be removed by typing in the input. + expect(screen.getByText(subCatErrorMessage)).toBeInTheDocument() + await userEvent.type(eanInput, '9781234567897') expect(screen.getByText(subCatErrorMessage)).toBeInTheDocument() }) diff --git a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx index 56db579b556..9328b2fceca 100644 --- a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx +++ b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx @@ -148,6 +148,7 @@ export const DetailsEanSearch = ({ } const shouldInputBeDisabled = isProductBased || isFetchingProduct + const shouldInputBeRequired = !!subcatError const shouldButtonBeDisabled = isProductBased || !ean || !!formikError || !!apiError || isFetchingProduct const displayClearButton = isNotAnOfferYetButProductBased @@ -167,7 +168,10 @@ export const DetailsEanSearch = ({ > Nouveau - Scanner ou rechercher un produit par EAN + + Scanner ou rechercher un produit par EAN + {shouldInputBeRequired && ' *'} + ) @@ -187,7 +191,8 @@ export const DetailsEanSearch = ({ type="text" disabled={shouldInputBeDisabled} maxLength={13} - isOptional + isOptional={!shouldInputBeRequired} + showMandatoryAsterisk={false} countCharacters {...(externalError && { externalError,