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
vi.mock('@components/app/GlobalAppState', () => ({
useGlobalNotificationSource: () => ({}),
}));
vi.mock('@notifications/mark-row-seen', () => ({
markRowNotificationsSeenOnOpen: vi.fn(),
}));
import type { TagSetResponse } from '@service-properties/generated/schemas/tagSetResponse';
import { cleanup, render } from '@solidjs/testing-library';
import { createStore } from 'solid-js/store';
import { afterEach, describe, expect, it, vi } from 'vitest';
import {
type EmailViewContext,
EmailViewProvider,
useEmailView,
} from './email-view-context';
const mocks = vi.hoisted(() => ({
navigate: vi.fn(),
useRouteParams: vi.fn(),
useEmailLinksQuery: vi.fn(),
/** Whether the remote flag with this PostHog key is on. */
flag: (_key: string): boolean => true,
tab: (): string => 'important',
tagSets: (): TagSetResponse[] => [],
}));
vi.mock('@app/lib/analytics/posthog', () => ({
useFeatureFlag:
({ key }: { key: string }) =>
() => ({ enabled: mocks.flag(key), loading: false }),
}));
vi.mock('@app/components/list', () => ({
createListController: () => ({}),
listOwnedSlotName: (name: string) => name,
}));
vi.mock('@app/components/view-shell', () => ({}));
vi.mock(
'@app/features/soup',
async () => import('../soup/filters/facets/selection')
);
vi.mock('@app/features/soup/collection/list-navigation-source', () => ({
registerListNavigationSource: () => {},
}));
vi.mock('@app/lib/persistence', () => ({
makePersistedState: <T,>(store: T) => store,
}));
vi.mock('@app/lib/split-router', async (importOriginal) => ({
...(await importOriginal<typeof import('@app/lib/split-router')>()),
useNavigate: () => mocks.navigate,
useRouteParams: () => mocks.useRouteParams(),
useMatches: () => () => [],
createSearchParams: () => [
{
get tab() {
return mocks.tab();
},
},
],
}));
vi.mock('@service-storage/websocket', () => ({
storageWS: { reconnectIfDisconnected: vi.fn() },
createWebSocketJob: vi.fn(),
}));
vi.mock('@service-connection/websocket', () => ({
ws: { addEventListener: vi.fn(), send: vi.fn() },
state: () => 'closed',
createConnectionBlockWebsocketEffect: vi.fn(),
createConnectionWebsocketEffect: vi.fn(),
}));
vi.mock('@components/app/createPreviewSelectionGuard', () => ({
createPreviewSelectionGuard: () =>
Object.assign(() => true, { canSelect: () => true }),
}));
vi.mock('@components/app/split-layout/layoutUtils', () => ({
useSplitPanelOrThrow: () => ({ handle: { id: 'mail-panel' } }),
withSplitPanelOwner: (_slot: string, create: () => unknown) => create(),
}));
vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));
vi.mock('@core/mobile/isTouchDevice', () => ({ isTouchDevice: () => false }));
vi.mock('@property/tags/tag-sets-context', () => ({
useTagSets: () => () => mocks.tagSets(),
useTagSetsReady: () => () => true,
}));
vi.mock('@queries/email/link', () => ({
useEmailLinksQuery: () => mocks.useEmailLinksQuery(),
}));
vi.mock('./persistence', () => ({ createEmailViewPersistence: () => ({}) }));
vi.mock('./queries/use-email-query', () => ({
useEmailDataSource: () => ({ items: () => [] }),
}));
vi.mock('./route', () => ({
emailSplitRoute: { id: 'view-mail' },
emailThreadRoute: { id: 'mail-thread' },
}));
vi.mock('./email-route', () => ({
emailTabSearch: { namespace: 'mail' },
emailDetailSearch: { namespace: 'email-detail' },
emailTabSearchCodec: { serialize: (value: unknown) => value },
}));
afterEach(() => {
cleanup();
vi.clearAllMocks();
mocks.flag = () => true;
mocks.tab = () => 'important';
mocks.tagSets = () => [];
});
function mount() {
const [linksQuery, setLinksQuery] = createStore({
isSuccess: false,
data: { links: [] as { id: string }[] },
});
const [params, setParams] = createStore<{ threadId?: string }>({
threadId: 'open-thread',
});
mocks.useEmailLinksQuery.mockReturnValue(linksQuery);
mocks.useRouteParams.mockReturnValue(params);
mocks.navigate.mockImplementation(
(target: { params: { threadId?: string } }) =>
setParams('threadId', target.params.threadId)
);
let view!: EmailViewContext;
function ReadContext() {
view = useEmailView();
return null;
}
render(() => (
<EmailViewProvider initialState={{ inboxIds: ['saved-inbox'] }}>
<ReadContext />
</EmailViewProvider>
));
return { view, setLinksQuery };
}
describe('email view inbox reconciliation', () => {
it('selects an alias atomically without clearing it or navigating twice', () => {
const { view } = mount();
view.setAliasFilter({
inboxId: 'saved-inbox',
emailAddress: '[email protected]',
});
expect(view.state.aliasFilter).toEqual({
inboxId: 'saved-inbox',
emailAddress: '[email protected]',
});
expect(view.state.inboxIds).toEqual(['saved-inbox']);
expect(mocks.navigate).toHaveBeenCalledOnce();
view.setInboxIds(undefined);
expect(view.state.aliasFilter).toBeUndefined();
expect(view.state.inboxIds).toBeUndefined();
});
it.each([{ links: [] }, { links: [{ id: 'remaining-inbox' }] }])(
'preserves the thread when loaded accounts invalidate the saved scope: %j',
({ links }) => {
const { view, setLinksQuery } = mount();
expect(view.state.inboxIds).toEqual(['saved-inbox']);
expect(view.selectedThread()?.id).toBe('open-thread');
setLinksQuery({ isSuccess: true, data: { links } });
expect(view.state.inboxIds).toBeUndefined();
expect(view.selectedThread()?.id).toBe('open-thread');
expect(mocks.navigate).not.toHaveBeenCalled();
}
);
it('still closes the thread when the user explicitly selects All inboxes', () => {
const { view, setLinksQuery } = mount();
setLinksQuery({
isSuccess: true,
data: { links: [{ id: 'saved-inbox' }] },
});
view.setInboxIds(undefined);
expect(view.state.inboxIds).toBeUndefined();
expect(view.selectedThread()).toBeUndefined();
expect(mocks.navigate).toHaveBeenCalledOnce();
});
});
it('clears persisted text search when entering and leaving Email Reminders', () => {
const { view } = mount();
view.setState('search', 'prior inbox search');
view.setTab('reminders');
expect(view.state.search).toBe('');
view.setState('search', 'stale restored search');
view.setTab('all');
expect(view.state.search).toBe('');
});
describe('tag view title', () => {
const qaTag = '019a1f40-2c7e-7d10-9a4b-6f2b0c1d2e40';
const userTags = (): TagSetResponse[] => [
{
scope: 'user',
options: [
{
id: qaTag,
displayOrder: 0,
propertyDefinitionId: 'user-tags',
value: { type: 'string', value: 'QA test tag' },
},
],
},
];
it('names the view after the tag chosen in the sidebar', () => {
mocks.tagSets = userTags;
const { view } = mount();
view.showTags([qaTag]);
expect(view.tagViewTitle()).toBe('QA test tag');
});
it('keeps the tab name when a tag only filters a tab', () => {
mocks.tagSets = userTags;
const { view } = mount();
view.filterByTag(qaTag);
expect(view.state.tab).toBe('important');
expect(view.tagViewTitle()).toBeUndefined();
});
});
it('normalizes restored and route-driven Reminders when the rollout is disabled', () => {
const [flag, setFlag] = createStore({ enabled: true });
mocks.flag = (key) => key !== 'enable-reminders' || flag.enabled;
mocks.tab = () => 'reminders';
const { view } = mount();
expect(view.state.tab).toBe('reminders');
setFlag('enabled', false);
expect(view.state.tab).toBe('important');
expect(view.state.search).toBe('');
view.setTab('reminders');
expect(view.state.tab).toBe('important');
});
it('leaves a restored Focus tab when Focus or GraphQL Soup turns off', () => {
for (const off of ['enable-email-focus', 'enable-graphql-soup']) {
const [flag, setFlag] = createStore({ enabled: true });
mocks.flag = (key) => key !== off || flag.enabled;
mocks.tab = () => 'focus';
const { view } = mount();
expect(view.state.tab).toBe('focus');
setFlag('enabled', false);
expect(view.state.tab).toBe('important');
view.setTab('focus');
expect(view.state.tab).toBe('important');
cleanup();
}
});