diff --git a/__tests__/client/components/LocationPopover.client.test.tsx b/__tests__/client/components/LocationPopover.client.test.tsx new file mode 100644 index 000000000..b8f8cee0c --- /dev/null +++ b/__tests__/client/components/LocationPopover.client.test.tsx @@ -0,0 +1,43 @@ +import { LocationPopover } from '@/components/EventPreview/LocationPopover' +import type { Event } from '@/payload-types' +import '@testing-library/jest-dom' +import { render, screen } from '@testing-library/react' + +const buildLocation = ( + overrides: Partial> = {}, +): NonNullable => ({ + isVirtual: false, + placeName: 'Snoqualmie Pass Trailhead', + city: 'Snoqualmie Pass', + state: 'WA', + ...overrides, +}) + +describe('LocationPopover', () => { + it('shows City, State at a glance without opening the popover', () => { + render() + + expect(screen.getByText('Snoqualmie Pass Trailhead')).toBeInTheDocument() + expect(screen.getByText('Snoqualmie Pass, WA')).toBeInTheDocument() + }) + + it('shows only the city when no state is set', () => { + render() + + expect(screen.getByText('Snoqualmie Pass')).toBeInTheDocument() + }) + + it('shows only the state when no city is set', () => { + render() + + expect(screen.getByText('WA')).toBeInTheDocument() + }) + + it('omits the City, State line when neither city nor state is set', () => { + render() + + // Only the placeName should remain as visible location text + expect(screen.getByText('Snoqualmie Pass Trailhead')).toBeInTheDocument() + expect(screen.queryByText(/,/)).not.toBeInTheDocument() + }) +}) diff --git a/src/components/EventPreview/LocationPopover.tsx b/src/components/EventPreview/LocationPopover.tsx index d1bd2a402..92488c06b 100644 --- a/src/components/EventPreview/LocationPopover.tsx +++ b/src/components/EventPreview/LocationPopover.tsx @@ -16,56 +16,65 @@ type LocationPopoverProps = { export const LocationPopover = ({ location }: LocationPopoverProps) => { const [isLocationOpen, setIsLocationOpen] = useState(false) + const cityState = [location.city, location.state].filter(Boolean).join(', ') + return ( - - -
- -

- {location.placeName} -

- -
-
- -
- {location.address &&
{location.address}
} -
- {location.city && `${location.city}, `} - {location.state && `${location.state} `} - {location.zip} +
+ + +
+ +

+ {location.placeName} +

+ +
+
+ +
+ {location.address &&
{location.address}
} +
+ {location.city && `${location.city}, `} + {location.state && `${location.state} `} + {location.zip} +
-
- - - + .join(', ')} + className="flex items-center gap-1 text-xs hover:text-foreground transition-colors" + /> + + + Open in Maps + +
+ + + {cityState && ( +

+ {cityState} +

+ )} +
) }