Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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(() => (
<CalendarEventWhen
entity={event({
name: 'Macro Vacation',
email: 'c_03728f99@group.calendar.google.com',
})}
/>
));

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(() => (
<CalendarEventWhen
entity={event({ name: 'jacob', email: 'jacob@macro.com' })}
/>
));

expect(screen.getByText('Jacob Beckerman')).toBeTruthy();
});

it('falls back to the email when the organizer has neither a profile nor a name', () => {
render(() => (
<CalendarEventWhen entity={event({ email: 'someone@example.com' })} />
));

expect(screen.getByText('someone@example.com')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => <span class="shrink-0 text-ink/30">·</span>;
Expand Down
Loading