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 14, 2025
1 parent 52b6449 commit 6c69711
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ export const OfferSection = ({
{!offerData.isVenueVirtual && isOfferAddressEnabled && (
<SummarySubSection title="Localisation de l’offre">
<SummaryDescriptionList
listDataTestId="localisation-offer-details"
descriptions={[
{
title: 'Intitulé',
text: offerData.address?.label ?? '-',
},
{
title: 'Adresse',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { screen, waitFor } from '@testing-library/react'
import { screen, waitFor, within } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import { addDays, format } from 'date-fns'
import { generatePath, Route, Routes } from 'react-router-dom'
Expand Down Expand Up @@ -663,6 +663,39 @@ 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(
within(screen.getByTestId('localisation-offer-details')).getAllByText(
'-'
)
).toHaveLength(2)
})
})

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 6c69711

Please sign in to comment.