Files
TREK/client/src/components/Settings/ai/AiConnectionSection.mapFollow.test.tsx
T
Maurice b64da26651 feat(assistant): trip assistant chat with your own AI connection
Adds an in-app assistant that reads and plans the open trip. Users connect
their own provider (Sign in with ChatGPT, or an Anthropic, OpenAI, Gemini or
OpenRouter key) or use the one the admin set up, including a custom
OpenAI-compatible server. It is an addon and only shows while a connection
is usable.

The chat runs on the existing MCP tools, pinned to the trip. Every change is
held as a change card the user applies or discards, and applied changes can
be undone. On the desktop it is a floating window that can be moved and
resized; on the phone it is fullscreen. Search results show as place cards
that can go onto a day, weather lookups as a strip, proposed places as
ghost markers on the map with a before/after switch, and an answer can be
shared into the trip chat. Booking files can be dropped in and are read
into change cards.
2026-10-22 21:30:12 +00:00

81 lines
3.6 KiB
TypeScript

// FE-COMP-AI-FOLLOW-001 to 003: the "map follows the assistant" switch, in both AI settings shells.
import userEvent from '@testing-library/user-event';
import type { AiStatusResponse } from '@trek/shared';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { buildUser } from '../../../../tests/helpers/factories';
import { render, screen } from '../../../../tests/helpers/render';
import { resetAllStores, seedStore } from '../../../../tests/helpers/store';
import { useAssistantStore } from '../../../store/assistantStore';
import { useAuthStore } from '../../../store/authStore';
import { useSettingsStore } from '../../../store/settingsStore';
const repo = vi.hoisted(() => ({ status: vi.fn(), models: vi.fn() }));
vi.mock('../../../repo/aiConnectionsRepo', () => ({ aiConnectionsRepo: repo }));
const { default: AiConnectionSection } = await import('./AiConnectionSection');
const { default: MAiConnectionSection } = await import('../../../mobile/screens/settings/MAiConnectionSection');
const INSTANCE: AiStatusResponse = {
available: true,
policy: 'instance',
canConnectOwn: false,
effective: { source: 'instance', kind: 'openai', model: 'gpt', host: 'api.openai.com', paidBy: 'instance' },
own: null,
instance: { kind: 'openai', model: 'gpt', host: 'api.openai.com' },
quota: null,
privacyAcked: true,
retention: { mode: 'days', days: 90 },
openrouterOAuth: false,
};
beforeEach(() => {
resetAllStores();
vi.clearAllMocks();
useAssistantStore.setState({ status: null });
seedStore(useAuthStore, { user: buildUser(), isAuthenticated: true });
repo.models.mockResolvedValue([]);
});
describe('AI settings: the map follows the assistant', () => {
it('FE-COMP-AI-FOLLOW-001: on by default once the assistant runs, and switching it off saves the setting', async () => {
const user = userEvent.setup();
repo.status.mockResolvedValue(INSTANCE);
const updateSetting = vi.fn().mockResolvedValue(undefined);
useSettingsStore.setState({ updateSetting });
render(<AiConnectionSection />);
const toggle = await screen.findByRole('button', { name: 'Map follows the assistant' });
expect(toggle).toHaveAttribute('aria-pressed', 'true');
expect(screen.getByText('The map pans to where the assistant searches and suggests places.')).toBeInTheDocument();
await user.click(toggle);
expect(updateSetting).toHaveBeenCalledWith('assistant_map_follow', false);
});
it('FE-COMP-AI-FOLLOW-002: not offered before there is an assistant to follow', async () => {
repo.status.mockResolvedValue({
...INSTANCE,
available: false,
instance: null,
effective: null,
policy: 'instance_or_user',
canConnectOwn: true,
});
render(<AiConnectionSection />);
expect(await screen.findByText('What would you like to chat with?')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Map follows the assistant' })).not.toBeInTheDocument();
});
it('FE-COMP-AI-FOLLOW-003: the phone card has the same switch on the same setting', async () => {
const user = userEvent.setup();
repo.status.mockResolvedValue(INSTANCE);
const updateSetting = vi.fn().mockResolvedValue(undefined);
useSettingsStore.setState((s) => ({ updateSetting, settings: { ...s.settings, assistant_map_follow: false } }));
render(<MAiConnectionSection />);
const toggle = await screen.findByRole('switch', { name: 'Map follows the assistant' });
expect(toggle).toHaveAttribute('aria-checked', 'false');
await user.click(toggle);
expect(updateSetting).toHaveBeenCalledWith('assistant_map_follow', true);
});
});