All files / src/components/shared/EventEditionLabel EventEditionLabel.tsx

80% Statements 4/5
61.53% Branches 8/13
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39                                                      16x 16x 16x 16x                
/**
 * EventEditionLabel — the "BATbern <n>" edition kicker shown above an event title.
 *
 * Post-event-#2 feedback #15: the edition number should appear before/above the title everywhere
 * the event is shown (public homepage, archive, event detail, speaker "My Sessions", attendee
 * "My Past Events"). Derives the number from `eventNumber` when present, else from the trailing
 * digits of `eventCode` (e.g. "BATbern59" → "BATbern 59"). Renders nothing when neither is usable.
 *
 * "BATbern <n>" is a brand string — intentionally NOT translated (no i18n key). MUI-free so it is
 * safe to use on the Tailwind-only public bundle.
 */
import { type JSX } from 'react';
 
interface EventEditionLabelProps {
  eventCode?: string | null;
  eventNumber?: number | null;
  className?: string;
  'data-testid'?: string;
}
 
export function EventEditionLabel({
  eventCode,
  eventNumber,
  className,
  'data-testid': testId = 'event-edition-label',
}: EventEditionLabelProps): JSX.Element | null {
  const parsed =
    eventNumber ?? (eventCode ? Number.parseInt(eventCode.replace(/\D/g, ''), 10) : NaN);
  const label = Number.isFinite(parsed) && parsed > 0 ? `BATbern ${parsed}` : (eventCode ?? '');
  Iif (!label) return null;
  return (
    <span className={className} data-testid={testId}>
      {label}
    </span>
  );
}
 
export default EventEditionLabel;