Skip to content

Commit

Permalink
(PC-31828)[PRO] fix: dryer DetailsEanSearch + .spec
Browse files Browse the repository at this point in the history
  • Loading branch information
asaez-pass committed Sep 19, 2024
1 parent afae73d commit 521110d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ const contextValue: IndividualOfferContextValues = {
}

type RequiredProps = 'isOfferProductBased'
type DetailsEanSearchTestProps = Pick<DetailsEanSearchProps, RequiredProps>
type DetailsEanSearchTestProps = Pick<DetailsEanSearchProps, RequiredProps> & {
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,
Expand All @@ -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(
<IndividualOfferContext.Provider value={contextValue}>
<EanSearchWrappedWithFormik props={props} subcategoryId={subcategoryId} />
<EanSearchWrappedWithFormik {...props} />
</IndividualOfferContext.Provider>,
{
storeOverrides: {
Expand Down Expand Up @@ -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',
})

Expand All @@ -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')
Expand All @@ -138,7 +131,7 @@ describe('DetailsEanSearch', () => {
images: {},
})

renderDetailsEanSearch({ props: { isOfferProductBased: false } })
renderDetailsEanSearch({ isOfferProductBased: false })
})

it('should display a success message', async () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ export const DetailsEanSearch = ({
>
Nouveau
</Tag>
<span>
Scanner ou rechercher un produit par EAN
{shouldInputBeRequired && ' *'}
</span>
Scanner ou rechercher un produit par EAN
</>
)

Expand All @@ -192,7 +189,6 @@ export const DetailsEanSearch = ({
disabled={shouldInputBeDisabled}
maxLength={13}
isOptional={!shouldInputBeRequired}
showMandatoryAsterisk={false}
countCharacters
{...(externalError && {
externalError,
Expand Down
6 changes: 4 additions & 2 deletions pro/src/screens/IndividualOffer/DetailsScreen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 521110d

Please sign in to comment.