Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
type CalendarEvent,
DEFAULT_GUEST_POLICY,
NO_VIEWER_CAPABILITIES,
} from '../calendar/types';
import {
copyCalendarEventMention,
copyCalendarEventMentionTarget,
} from './copy-event-mention';
const writeClipboardData = vi.hoisted(() =>
vi.fn(async (_data: Record<string, string | undefined>) => true)
);
vi.mock('@core/util/dataTransfer', () => ({ writeClipboardData }));
vi.mock('@core/component/Toast/Toast', () => ({
toast: { success: vi.fn(), failure: vi.fn() },
}));
const written = () => writeClipboardData.mock.calls[0]?.[0];
describe('copyCalendarEventMentionTarget', () => {
beforeEach(() => writeClipboardData.mockClear());
it('never copies a team projection as an independently resolvable event', async () => {
const calendar = { id: 'team-ooo:alice', name: 'Alice', color: 'gray' };
const event: CalendarEvent = {
id: 'opaque',
eventId: 'opaque',
occurrenceKey: '2026-10-07T10:00:00Z',
teamProjection: { ownerId: 'alice', kind: 'busy' },
isCancelled: false,
isReadOnly: true,
guestPolicy: DEFAULT_GUEST_POLICY,
viewerCan: NO_VIEWER_CAPABILITIES,
attendees: [],
recurrenceLines: [],
sourceCalendarIds: [],
title: 'Alice: Out of office',
start: '2026-10-07T10:00:00Z',
end: '2026-10-07T11:00:00Z',
allDay: false,
calendar,
visibleCalendars: [calendar],
};
await copyCalendarEventMention(event);
expect(writeClipboardData).not.toHaveBeenCalled();
});
it('writes a mention span an editor can import', async () => {
await copyCalendarEventMentionTarget({
eventId: 'event-1',
title: 'Smart Macro Discussion',
});
const html = written()?.['text/html'];
expect(html).toContain('data-document-mention="true"');
expect(html).toContain('data-document-id="event-1"');
expect(html).toContain('data-block-name="calendar"');
expect(html).not.toContain('data-block-params');
});
it('pins the occurrence when one is given', async () => {
await copyCalendarEventMentionTarget({
eventId: 'event-1',
title: 'Standup',
occurrenceKey: '2026-08-21T18:00:00+00:00',
});
expect(written()?.['text/html']).toContain(
`data-block-params="${JSON.stringify({ occurrenceKey: '2026-08-21T18:00:00+00:00' }).replaceAll('"', '"')}"`
);
});
// `importDOM` reads the title back off the attribute, so a title carrying
// quotes or angle brackets has to survive the round trip intact.
it('round-trips a title that could break the markup', async () => {
const title = 'Q3 "<review>" & retro';
await copyCalendarEventMentionTarget({ eventId: 'event-1', title });
const html = written()?.['text/html'] ?? '';
const span = new DOMParser()
.parseFromString(html, 'text/html')
.querySelector('span');
expect(span?.getAttribute('data-document-name')).toBe(title);
expect(span?.textContent).toBe(title);
});
it('falls back to a deep link for the plain flavor', async () => {
await copyCalendarEventMentionTarget({
eventId: 'event-1',
title: 'Standup',
occurrenceKey: '2026-08-21T18:00:00+00:00',
});
const plain = written()?.['text/plain'] ?? '';
expect(plain).toMatch(/\/app\/calendar\/(month|week|day)\?/);
expect(plain).toContain('s0.calendar.eventId=event-1');
expect(plain).not.toContain('occurrenceKey');
});
});