Files
TREK/client/src/store/assistantHintsStore.test.ts
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

67 lines
2.7 KiB
TypeScript

/**
* FE-AI-HINTSTORE-001 to FE-AI-HINTSTORE-004
*
* What one person did with the plan hints of a trip: dismissed and seen ids,
* kept in the browser's storage per trip, and still working without it.
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { useAssistantHintsStore } from './assistantHintsStore';
const INITIAL = useAssistantHintsStore.getState();
const KEY = 'trek:assistant-hints:7';
beforeEach(() => {
window.localStorage.clear();
useAssistantHintsStore.setState(INITIAL, true);
});
afterEach(() => vi.restoreAllMocks());
describe('assistantHintsStore', () => {
it('FE-AI-HINTSTORE-001: keeps dismissed and seen ids per trip, each once, and writes them to storage', () => {
const { dismiss, markSeen } = useAssistantHintsStore.getState();
dismiss(7, 'gap:1:600-780');
dismiss(7, 'gap:1:600-780');
markSeen(7, ['overlap:1:a', 'overlap:1:a', 'closed:2:p3']);
expect(useAssistantHintsStore.getState().byTrip[7]).toEqual({
dismissed: ['gap:1:600-780'],
seen: ['overlap:1:a', 'closed:2:p3'],
});
expect(useAssistantHintsStore.getState().byTrip[8]).toBeUndefined();
expect(JSON.parse(window.localStorage.getItem(KEY) ?? 'null')).toEqual({
dismissed: ['gap:1:600-780'],
seen: ['overlap:1:a', 'closed:2:p3'],
});
});
it('FE-AI-HINTSTORE-002: reads a trip back from storage on load, and drops what is not an id', () => {
window.localStorage.setItem(KEY, JSON.stringify({ dismissed: ['a', 3, null], seen: 'nope' }));
useAssistantHintsStore.getState().load(7);
expect(useAssistantHintsStore.getState().byTrip[7]).toEqual({ dismissed: ['a'], seen: [] });
window.localStorage.setItem('trek:assistant-hints:9', '{not json');
useAssistantHintsStore.getState().load(9);
expect(useAssistantHintsStore.getState().byTrip[9]).toEqual({ dismissed: [], seen: [] });
});
it('FE-AI-HINTSTORE-003: keeps only the most recent hundred ids of a list', () => {
const ids = Array.from({ length: 105 }, (_, i) => `gap:1:${i}`);
useAssistantHintsStore.getState().markSeen(7, ids);
const { seen } = useAssistantHintsStore.getState().byTrip[7];
expect(seen).toHaveLength(100);
expect(seen[0]).toBe('gap:1:5');
});
it('FE-AI-HINTSTORE-004: works on without storage, for as long as the page is up', () => {
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
throw new Error('blocked');
});
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
throw new Error('blocked');
});
useAssistantHintsStore.getState().dismiss(7, 'noStay:2:1');
expect(useAssistantHintsStore.getState().byTrip[7]).toEqual({ dismissed: ['noStay:2:1'], seen: [] });
});
});