diff --git a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx index 4ecbe6a7a8..dfcbb31c61 100644 --- a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx +++ b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.spec.tsx @@ -31,15 +31,14 @@ const contextValue: IndividualOfferContextValues = { } type RequiredProps = 'isOfferProductBased' -type DetailsEanSearchTestProps = Pick +type DetailsEanSearchTestProps = Pick & { + subcategoryId?: string +} const EanSearchWrappedWithFormik = ({ - props: { isOfferProductBased }, + isOfferProductBased, subcategoryId = DEFAULT_DETAILS_FORM_VALUES.subcategoryId, -}: { - props: DetailsEanSearchTestProps - subcategoryId?: string -}): JSX.Element => { +}: DetailsEanSearchTestProps): JSX.Element => { const formik = useFormik({ initialValues: { ...DEFAULT_DETAILS_FORM_VALUES, @@ -60,16 +59,10 @@ const EanSearchWrappedWithFormik = ({ ) } -const renderDetailsEanSearch = ({ - props, - subcategoryId = DEFAULT_DETAILS_FORM_VALUES.subcategoryId, -}: { - props: DetailsEanSearchTestProps - subcategoryId?: string -}) => { +const renderDetailsEanSearch = (props: DetailsEanSearchTestProps) => { return renderWithProviders( - + , { storeOverrides: { @@ -99,7 +92,7 @@ describe('DetailsEanSearch', () => { describe('when no EAN search has been performed', () => { it('should display a permanent error message if the subcategory requires an EAN', async () => { renderDetailsEanSearch({ - props: { isOfferProductBased: false }, + isOfferProductBased: false, subcategoryId: 'SUPPORT_PHYSIQUE_MUSIQUE_VINYLE', }) @@ -115,7 +108,7 @@ describe('DetailsEanSearch', () => { }) it('should let the submit button enabled', async () => { - renderDetailsEanSearch({ props: { isOfferProductBased: false } }) + renderDetailsEanSearch({ isOfferProductBased: false }) const eanInput = screen.getByRole('textbox', { name: inputLabel }) await userEvent.type(eanInput, '9781234567897') @@ -138,7 +131,7 @@ describe('DetailsEanSearch', () => { images: {}, }) - renderDetailsEanSearch({ props: { isOfferProductBased: false } }) + renderDetailsEanSearch({ isOfferProductBased: false }) }) it('should display a success message', async () => { @@ -185,7 +178,7 @@ describe('DetailsEanSearch', () => { describe('when an EAN search ends with an API error (only)', () => { beforeEach(() => { vi.spyOn(api, 'getProductByEan').mockRejectedValue(new Error('error')) - renderDetailsEanSearch({ props: { isOfferProductBased: false } }) + renderDetailsEanSearch({ isOfferProductBased: false }) }) it('should display an error message', async () => { @@ -217,7 +210,7 @@ describe('DetailsEanSearch', () => { describe('after POST request (the form has been submitted)', () => { describe('when an EAS search was performed succesfully', () => { beforeEach(() => { - renderDetailsEanSearch({ props: { isOfferProductBased: true } }) + renderDetailsEanSearch({ isOfferProductBased: true }) }) it('should not display the clear button anymore', () => { diff --git a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx index 9328b2fcec..1a1c22341f 100644 --- a/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx +++ b/pro/src/screens/IndividualOffer/DetailsScreen/DetailsEanSearch/DetailsEanSearch.tsx @@ -168,10 +168,7 @@ export const DetailsEanSearch = ({ > Nouveau - - Scanner ou rechercher un produit par EAN - {shouldInputBeRequired && ' *'} - + Scanner ou rechercher un produit par EAN ) @@ -192,7 +189,6 @@ export const DetailsEanSearch = ({ disabled={shouldInputBeDisabled} maxLength={13} isOptional={!shouldInputBeRequired} - showMandatoryAsterisk={false} countCharacters {...(externalError && { externalError, diff --git a/pro/src/screens/IndividualOffer/DetailsScreen/utils.ts b/pro/src/screens/IndividualOffer/DetailsScreen/utils.ts index 506d55c6f1..9e5baa3f4e 100644 --- a/pro/src/screens/IndividualOffer/DetailsScreen/utils.ts +++ b/pro/src/screens/IndividualOffer/DetailsScreen/utils.ts @@ -244,6 +244,8 @@ export function setDefaultInitialValuesFromOffer({ throw Error('La categorie de l’offre est introuvable') } + const ean = offer.extraData?.ean ?? DEFAULT_DETAILS_FORM_VALUES.ean + return { ...DEFAULT_DETAILS_FORM_VALUES, name: offer.name, @@ -259,8 +261,8 @@ export function setDefaultInitialValuesFromOffer({ durationMinutes: offer.durationMinutes ? deSerializeDurationMinutes(offer.durationMinutes) : DEFAULT_DETAILS_FORM_VALUES.durationMinutes, - ean: offer.extraData?.ean ?? DEFAULT_DETAILS_FORM_VALUES.ean, - eanSearch: offer.extraData?.ean ?? DEFAULT_DETAILS_FORM_VALUES.ean, + ean, + eanSearch: ean, visa: offer.extraData?.visa ?? DEFAULT_DETAILS_FORM_VALUES.visa, gtl_id: offer.extraData?.gtl_id ?? DEFAULT_DETAILS_FORM_VALUES.gtl_id, speaker: offer.extraData?.speaker ?? DEFAULT_DETAILS_FORM_VALUES.speaker,