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.

1.9 KB
Raw Blame
import { cleanup, render } from '@solidjs/testing-library';
import { createSignal, type JSX } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
import type { EntityProperty } from '../types';
import { PropertyUserStack } from './PropertyUserStack';

const avatars = vi.hoisted(() => ({ mounts: [] as string[] }));

vi.mock('@core/component/UserIcon', () => ({
  UserIcon: (props: { id: string }) => {
    avatars.mounts.push(props.id);
    return <span>{props.id}</span>;
  },
}));
vi.mock('@ui', () => ({
  AvatarGroup: Object.assign(
    (props: { children: JSX.Element }) => <div>{props.children}</div>,
    {
      Count: (props: { children: JSX.Element }) => (
        <span>{props.children}</span>
      ),
    }
  ),
}));

const assignees: EntityProperty = {
  propertyId: 'task-assignees',
  propertyDefinitionId: 'assignees-definition',
  displayName: 'Assignees',
  isMultiSelect: true,
  owner: { scope: 'system' },
  createdAt: new Date(0),
  updatedAt: new Date(0),
  valueType: 'ENTITY',
  specificEntityType: 'USER',
  value: [
    { entity_id: 'macro|[email protected]', entity_type: 'USER' },
    { entity_id: 'macro|[email protected]', entity_type: 'USER' },
  ],
};

afterEach(() => {
  cleanup();
  avatars.mounts = [];
});

it('keeps each avatar in place while the assignees re-emit', () => {
  const [property, setProperty] = createSignal(assignees);
  const view = render(() => <PropertyUserStack property={property()} />);
  const alice = view.getByText('macro|[email protected]');

  setProperty({
    ...assignees,
    value: [
      { entity_id: 'macro|[email protected]', entity_type: 'USER' },
      { entity_id: 'macro|[email protected]', entity_type: 'USER' },
      { entity_id: 'macro|[email protected]', entity_type: 'USER' },
    ],
  });

  expect(view.getByText('macro|[email protected]')).toBe(alice);
  expect(avatars.mounts).toEqual([
    'macro|[email protected]',
    'macro|[email protected]',
    'macro|[email protected]',
  ]);
});