Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

4.0 KB
Raw Blame
/**
 * @vitest-environment jsdom
 */

import type { CalendarEvent } from '@app/features/calendar/types';
import type { CalendarAttendee } from '@service-storage/generated/schemas/calendarAttendee';
import { cleanup, render, screen } from '@solidjs/testing-library';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { EventAttendeesSection, EventDetails } from './EventDetails';

vi.mock('@core/component/UserIcon', () => ({
  UserIcon: () => document.createElement('span'),
}));
vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => false }));
// Macro profile and contact names; any other address has no name and falls
// back to itself, as the real lookup does.
vi.mock('@core/user', async (importOriginal) => {
  const names: Record<string, string> = {
    'macro|[email protected]': 'Bea Booker',
    'macro|[email protected]': 'Mo Viewer',
    'macro|[email protected]': 'Hana Host',
  };
  return {
    ...(await importOriginal<typeof import('@core/user')>()),
    getDisplayName: (id?: string) =>
      id ? (names[id] ?? id.replace(/^macro\|/, '')) : '',
  };
});

class ResizeObserverStub {
  observe() {}
  unobserve() {}
  disconnect() {}
}

beforeEach(() => {
  vi.stubGlobal('ResizeObserver', ResizeObserverStub);
});

afterEach(() => {
  cleanup();
  vi.unstubAllGlobals();
});

function attendee(overrides: Partial<CalendarAttendee>): CalendarAttendee {
  return {
    email: '[email protected]',
    isOptional: false,
    isOrganizer: false,
    isSelf: false,
    responseStatus: 'accepted',
    ...overrides,
  };
}

function event(overrides: Partial<CalendarEvent> = {}): CalendarEvent {
  return {
    id: '["event-1","2026-10-22T14:00:00Z"]',
    eventId: 'event-1',
    occurrenceKey: '2026-10-22T14:00:00Z',
    isCancelled: false,
    isReadOnly: false,
    guestPolicy: {
      canModify: false,
      canInviteOthers: true,
      canSeeOtherGuests: true,
    },
    viewerCan: {
      editDetails: false,
      inviteGuests: false,
      removeGuests: false,
      setGuestPolicy: false,
      rsvp: true,
      organize: false,
    },
    attendees: [],
    recurrenceLines: [],
    sourceCalendarIds: ['calendar-1'],
    calendarId: 'calendar-1',
    title: 'Planning',
    start: '2026-10-22T14:00:00Z',
    end: '2026-10-22T15:00:00Z',
    allDay: false,
    calendar: { id: 'calendar-1', name: 'Calendar', color: 'orange' },
    visibleCalendars: [],
    ...overrides,
  };
}

describe('the guest list in event details', () => {
  it('shows each named guest’s address under their name', () => {
    render(() => (
      <EventAttendeesSection
        attendees={[
          attendee({ email: '[email protected]' }),
          attendee({ email: '[email protected]', isSelf: true }),
        ]}
      />
    ));

    expect(screen.getByText('Bea Booker')).toBeTruthy();
    expect(screen.getByText('[email protected]')).toBeTruthy();
    expect(screen.getByText('Mo Viewer (you)')).toBeTruthy();
    expect(screen.getByText('[email protected]')).toBeTruthy();
  });

  it('shows a guest without a name by their address, once', () => {
    render(() => (
      <EventAttendeesSection
        attendees={[attendee({ email: '[email protected]' })]}
      />
    ));

    expect(screen.getAllByText('[email protected]')).toHaveLength(1);
  });
});

describe('the organizer in event details', () => {
  it('shows the organizer’s address under their name', () => {
    render(() => (
      <EventDetails
        event={event({
          organizerName: 'Hana Host',
          organizerEmail: '[email protected]',
        })}
        timeFormat="12-hour"
      />
    ));

    expect(screen.getByText('Hana Host')).toBeTruthy();
    expect(screen.getByText('[email protected]')).toBeTruthy();
  });

  it('shows an organizer known only by address once', () => {
    render(() => (
      <EventDetails
        event={event({ organizerEmail: '[email protected]' })}
        timeFormat="12-hour"
      />
    ));

    expect(screen.getAllByText('[email protected]')).toHaveLength(1);
  });
});