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.3 KB
Raw Blame
import { cleanup, render } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { EntityEmailParticipants } from '../extractors/entity-email-participants';
import type { EmailEntity } from '../types/entity';

// The viewer's address book knows [email protected] as "Nathan Flurry"
// (the first person who booked through it) and [email protected] as a Macro user.
const addressBook: Record<string, string> = {
  'macro|[email protected]': 'Nathan Flurry',
  'macro|[email protected]': 'Wolf Ryan',
};

vi.mock('@core/user', () => ({
  emailToMacroId: (email: string) => `macro|${email.toLowerCase()}`,
  getDisplayName: (id: string) => addressBook[id] ?? id.replace('macro|', ''),
}));
vi.mock('@core/context/user', () => ({
  useEmail: () => () => '[email protected]',
}));
vi.mock('@queries/email/link', () => ({
  useEmailLinksQuery: () => ({
    isPending: false,
    data: {
      links: [{ id: 'outlook', email_address: '[email protected]' }],
    },
  }),
}));
vi.mock('@core/component/HoverCard', () => ({
  HoverCard: (props: { trigger: unknown }) => <>{props.trigger}</>,
}));
vi.mock('@core/component/UserTooltip', () => ({
  UserTooltip: () => null,
}));
vi.mock('@core/component/Toast/Toast', () => ({
  toast: { success: () => {} },
}));
vi.mock(
  '@core/component/LexicalMarkdown/component/core/StaticMarkdown',
  () => ({
    StaticMarkdown: (props: { markdown: string }) => <>{props.markdown}</>,
  })
);
vi.mock('@core/component/LexicalMarkdown/theme', () => ({
  unifiedListMarkdownTheme: {},
}));

afterEach(cleanup);

const emailEntity = (
  participants: NonNullable<EmailEntity['participants']>,
  linkId?: string
): EmailEntity =>
  ({
    id: 'thread-1',
    type: 'email',
    name: 'Subject',
    participants,
    linkId,
  }) as unknown as EmailEntity;

describe('EntityEmailParticipants', () => {
  it('shows the From display name of the message, not the address-book name of a shared sender', () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity([
          { email: '[email protected]', name: 'Cal.com' },
        ])}
      />
    ));

    expect(container.textContent).toBe('Cal.com');
  });

  it('keeps distinct From names apart for messages from the same shared address', () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity([
          { email: '[email protected]', name: 'Cal.com' },
          { email: '[email protected]', name: 'Nathan Flurry' },
        ])}
      />
    ));

    expect(container.textContent).toBe('Cal.com, Nathan');
  });

  it('falls back to the Macro display name when the message carries no From name', () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity([{ email: '[email protected]' }])}
      />
    ));

    expect(container.textContent).toBe('Wolf Ryan');
  });

  it('falls back to the address local part when neither source has a name', () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity([{ email: '[email protected]' }])}
      />
    ));

    expect(container.textContent).toBe('someone');
  });

  it('ignores names that are just an email address', () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity([
          { email: '[email protected]', name: '[email protected]' },
        ])}
      />
    ));

    expect(container.textContent).toBe('Nathan Flurry');
  });

  it("treats the row's inbox address, not the Macro login, as me", () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity(
          [{ email: '[email protected]', name: 'Riley Park' }],
          'outlook'
        )}
      />
    ));

    expect(container.textContent).toBe('me');
  });

  it("recognizes the row's inbox address whatever its case", () => {
    const { container } = render(() => (
      <EntityEmailParticipants
        entity={emailEntity(
          [
            { email: '[email protected]', name: 'Riley Park' },
            { email: '[email protected]' },
          ],
          'outlook'
        )}
      />
    ));

    expect(container.textContent).toBe('Wolf Ryan');
  });
});