Skip to content

Commit

Permalink
(PC-33349)[PRO] fix: The app preview should not display the venue det…
Browse files Browse the repository at this point in the history
…ails.
  • Loading branch information
Amine Louveau committed Jan 13, 2025
1 parent 2bd9a89 commit acbfc0d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const OfferSection = ({
descriptions={[
{
title: 'Intitulé',
text: offerData.address?.label,
text: offerData.address?.label || '-',
},
{
title: 'Adresse',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,38 @@ describe('Summary', () => {
expect(screen.getAllByText('mon adresse')).toHaveLength(2)
expect(screen.getAllByText('ma street 1 ma ville')).toHaveLength(2)
})

it('should render component with new sections and empty address data', async () => {
vi.spyOn(api, 'getOfferer').mockResolvedValue(
defaultGetOffererResponseModel
)
customContext.offer = getIndividualOfferFactory({
isEvent: true,
address: null,
})

renderSummary(
customContext,
generatePath(
getIndividualOfferPath({
step: OFFER_WIZARD_STEP_IDS.SUMMARY,
mode: OFFER_WIZARD_MODE.CREATION,
}),
{ offerId: 'AA' }
),
{ features: ['WIP_ENABLE_OFFER_ADDRESS'] }
)

expect(await screen.findByText(/Structure/)).toBeInTheDocument()
expect(
await screen.findByText('Localisation de l’offre')
).toBeInTheDocument()

expect(screen.getByText('Intitulé : -')).toBeInTheDocument()
expect(screen.getByText('Adresse : -')).toBeInTheDocument()

expect(screen.getAllByText('-')).toHaveLength(9)
})
})

describe('banners', () => {
Expand Down
38 changes: 28 additions & 10 deletions pro/src/components/OfferAppPreview/VenueDetails/VenueDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AddressResponseIsLinkedToVenueModel,
GetOfferVenueResponseModel,
} from 'apiClient/v1'
import { useActiveFeature } from 'commons/hooks/useActiveFeature'
import { computeAddressDisplayName } from 'repository/venuesService'

import style from './VenueDetails.module.scss'
Expand All @@ -17,18 +18,35 @@ export const VenueDetails = ({
address,
withdrawalDetails,
}: VenueDetailsProps): JSX.Element => {
const { street, postalCode, city } = address || venue
const isOfferAddressEnabled = useActiveFeature('WIP_ENABLE_OFFER_ADDRESS')

const label = address ? address.label || '' : venue.publicName || venue.name
function computeAddress() {
let venueAddressString = '-'
let label = '-'

const venueAddressString = computeAddressDisplayName(
{
street,
postalCode: postalCode || '',
city: city || '',
},
false
)
if (!isOfferAddressEnabled) {
label = venue.publicName || venue.name
venueAddressString = [label, venue.street, venue.postalCode, venue.city]
.filter((str) => Boolean(str))
.join(' - ')
} else if (address) {
const { street, postalCode, city } = address

label = address.label || '-'

venueAddressString = computeAddressDisplayName(
{
street,
postalCode: postalCode || '',
city: city || '',
},
false
)
}
return { label, venueAddressString }
}

const { label, venueAddressString } = computeAddress()

return (
<div className={style['venue-details']}>
Expand Down

0 comments on commit acbfc0d

Please sign in to comment.