diff --git a/apps/web/src/features/entity/composed/list-entity/calendar.test.tsx b/apps/web/src/features/entity/composed/list-entity/calendar.test.tsx new file mode 100644 index 00000000000..a368f396513 --- /dev/null +++ b/apps/web/src/features/entity/composed/list-entity/calendar.test.tsx @@ -0,0 +1,68 @@ +import { render, screen } from '@solidjs/testing-library'; +import { describe, expect, it, vi } from 'vitest'; +import type { CalendarEventEntity } from '../../types/entity'; +import { CalendarEventWhen } from './calendar'; + +vi.mock('@core/user', () => ({ + emailToMacroId: (email: string) => + email.includes('@') ? `macro|${email}` : undefined, + getDisplayName: (id: string) => + id === 'macro|jacob@macro.com' + ? 'Jacob Beckerman' + : id.replace(/^macro\|/, ''), +})); +vi.mock('@core/component/UserIcon', () => ({ UserIcon: () => null })); +vi.mock('../../entity', () => ({ Entity: {} })); + +function event( + organizer: CalendarEventEntity['organizer'] +): CalendarEventEntity { + return { + id: 'event', + name: 'Out of office', + ownerId: 'macro|gab@macro.com', + type: 'calendar_event', + status: 'confirmed', + isReadOnly: false, + organizer, + time: { + kind: 'timed', + startsAt: '2026-08-14T04:00:00Z', + endsAt: '2026-08-15T04:00:00Z', + }, + }; +} + +describe('CalendarEventWhen organizer', () => { + it('names a shared calendar by the name the source supplied, not its address', () => { + render(() => ( + + )); + + expect(screen.getByText('Macro Vacation')).toBeTruthy(); + expect(screen.queryByText(/group\.calendar\.google\.com/)).toBeNull(); + }); + + it('prefers the Macro profile name when the organizer has one', () => { + render(() => ( + + )); + + expect(screen.getByText('Jacob Beckerman')).toBeTruthy(); + }); + + it('falls back to the email when the organizer has neither a profile nor a name', () => { + render(() => ( + + )); + + expect(screen.getByText('someone@example.com')).toBeTruthy(); + }); +}); diff --git a/apps/web/src/features/entity/composed/list-entity/calendar.tsx b/apps/web/src/features/entity/composed/list-entity/calendar.tsx index 86782bf338a..7322600cbbf 100644 --- a/apps/web/src/features/entity/composed/list-entity/calendar.tsx +++ b/apps/web/src/features/entity/composed/list-entity/calendar.tsx @@ -96,12 +96,15 @@ function organizerIconProps( /** Organizer display: the Macro profile name when resolved, else the source's * own name, else the email. Read reactively so it fills in when the user's - * name cache resolves. */ + * name cache resolves. The profile lookup falls back to the email for an + * address without a profile, such as a shared calendar's, so that fallback + * must not win over the name the source supplied. */ function organizerName(entity: CalendarEventEntity): string { const email = entity.organizer?.email; const macroId = email ? emailToMacroId(email) : undefined; const resolved = macroId ? getDisplayName(macroId).trim() : ''; - return resolved || entity.organizer?.name || email || ''; + const profileName = resolved && resolved !== email ? resolved : ''; + return profileName || entity.organizer?.name || email || ''; } const Dot = () => ยท;