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
/**
* @vitest-environment jsdom
*/
import { cleanup, render, screen } from '@solidjs/testing-library';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { EmailSettings } from './email-settings';
const mocks = vi.hoisted(() => ({
query: {} as Record<string, unknown>,
}));
vi.mock('@app/lib/analytics/posthog', () => ({
useFeatureFlag: () => () => ({ enabled: true }),
}));
vi.mock('@core/component/Toast/Toast', () => ({
toast: { success: vi.fn(), failure: vi.fn() },
}));
vi.mock('@core/constant/SettingsState', () => ({
useSettingsState: () => ({ openSettings: vi.fn() }),
}));
vi.mock('@core/constant/settingsTabsConfig', () => ({
useSettingsTabAvailable: () => () => false,
}));
vi.mock('@core/context/user', () => ({
useUserId: () => () => 'macro|[email protected]',
}));
vi.mock('@core/email-link', () => ({
useEmailLinks: () => ({ query: mocks.query }),
}));
vi.mock('@queries/email/settings', () => ({
useUpdateEmailSettingsMutation: () => ({ isPending: false, mutate: vi.fn() }),
}));
vi.mock('./Email', () => ({ EmailCard: () => null }));
vi.mock('./SignatureSection', () => ({
SignatureSection: (props: {
link: { email_address: string };
shared?: boolean;
}) => {
const row = document.createElement('p');
row.textContent = `Signature for ${props.link.email_address}${props.shared ? ', shared' : ''}`;
return row;
},
}));
const link = {
id: 'link-1',
macro_id: 'macro|[email protected]',
email_address: '[email protected]',
settings: { read_receipts_enabled: true },
};
afterEach(() => {
cleanup();
});
describe('EmailSettings read receipts', () => {
it('keeps cached account switches when a refetch fails', () => {
mocks.query = {
isPending: false,
isError: true,
isSuccess: false,
data: { links: [link] },
refetch: vi.fn(),
};
render(() => <EmailSettings />);
expect(
screen.getByRole('switch', {
name: 'Read receipts for [email protected]',
})
).toBeTruthy();
expect(screen.queryByText("Couldn't load accounts")).toBeNull();
});
it('offers a retry only when no accounts have loaded', () => {
mocks.query = {
isPending: false,
isError: true,
isSuccess: false,
data: undefined,
refetch: vi.fn(),
};
render(() => <EmailSettings />);
expect(screen.getByText("Couldn't load accounts")).toBeTruthy();
expect(screen.queryByRole('switch')).toBeNull();
});
});
describe('EmailSignatures', () => {
it('lists shared inboxes beside owned ones and marks them shared', () => {
mocks.query = {
isPending: false,
isError: false,
isSuccess: true,
data: {
links: [
link,
{
id: 'link-2',
macro_id: 'macro|[email protected]',
email_address: '[email protected]',
settings: { read_receipts_enabled: true },
},
],
},
refetch: vi.fn(),
};
render(() => <EmailSettings />);
expect(screen.getByText('Signature for [email protected]')).toBeTruthy();
expect(
screen.getByText('Signature for [email protected], shared')
).toBeTruthy();
});
});