Skip to content

Commit

Permalink
(PC-31828)[PRO] fix: make EAN search input required on subcat error
Browse files Browse the repository at this point in the history
  • Loading branch information
asaez-pass committed Sep 17, 2024
1 parent fb242ee commit f6a208b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const DetailsEanSearch = ({
}

const shouldInputBeDisabled = isProductBased || isFetchingProduct
const shouldInputBeRequired = !!subcatError
const shouldButtonBeDisabled =
isProductBased || !ean || !!formikError || !!apiError || isFetchingProduct
const displayClearButton = isNotAnOfferYetButProductBased
Expand All @@ -167,7 +168,10 @@ export const DetailsEanSearch = ({
>
Nouveau
</Tag>
<span>Scanner ou rechercher un produit par EAN</span>
<span>
Scanner ou rechercher un produit par EAN
{shouldInputBeRequired && ' *'}
</span>
</>
)

Expand All @@ -187,7 +191,8 @@ export const DetailsEanSearch = ({
type="text"
disabled={shouldInputBeDisabled}
maxLength={13}
isOptional
isOptional={!shouldInputBeRequired}
showMandatoryAsterisk={false}
countCharacters
{...(externalError && {
externalError,
Expand Down

0 comments on commit f6a208b

Please sign in to comment.