mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 15:06:32 +00:00
214984f398
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.
92 lines
3.4 KiB
TypeScript
92 lines
3.4 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { server } from '../../helpers/msw/server';
|
|
import { useAddonStore } from '../../../src/store/addonStore';
|
|
import { resetAllStores } from '../../helpers/store';
|
|
|
|
beforeEach(() => {
|
|
resetAllStores();
|
|
});
|
|
|
|
describe('addonStore', () => {
|
|
describe('FE-ADDON-001: loadAddons()', () => {
|
|
it('fetches and stores enabled addons', async () => {
|
|
await useAddonStore.getState().loadAddons();
|
|
const state = useAddonStore.getState();
|
|
|
|
expect(state.loaded).toBe(true);
|
|
expect(state.addons.length).toBeGreaterThan(0);
|
|
expect(state.addons[0]).toHaveProperty('id');
|
|
expect(state.addons[0]).toHaveProperty('enabled', true);
|
|
expect(state.bagTracking).toBe(false);
|
|
});
|
|
|
|
it('captures the global bagTracking flag from the response', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ bagTracking: true, addons: [] })
|
|
)
|
|
);
|
|
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().bagTracking).toBe(true);
|
|
});
|
|
|
|
it('captures whether wanderer may be used under Tours', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () => HttpResponse.json({ toursWanderer: true, toursHikingMap: true, addons: [] }))
|
|
);
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().toursWanderer).toBe(true);
|
|
|
|
server.use(http.get('/api/addons', () => HttpResponse.json({ addons: [] })));
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().toursWanderer).toBe(false);
|
|
});
|
|
|
|
it('keeps the collab chat on unless the response turns it off', async () => {
|
|
server.use(http.get('/api/addons', () => HttpResponse.json({ addons: [] })));
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().collabChat).toBe(true);
|
|
|
|
server.use(http.get('/api/addons', () => HttpResponse.json({ addons: [], collabFeatures: { chat: true } })));
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().collabChat).toBe(true);
|
|
|
|
server.use(http.get('/api/addons', () => HttpResponse.json({ addons: [], collabFeatures: { chat: false } })));
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().collabChat).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('FE-ADDON-002: isEnabled returns true for known addon', () => {
|
|
it('returns true when addon is in the list and enabled', async () => {
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().isEnabled('vacay')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('FE-ADDON-003: isEnabled returns false for unknown addon', () => {
|
|
it('returns false when addon is not in the list', async () => {
|
|
await useAddonStore.getState().loadAddons();
|
|
expect(useAddonStore.getState().isEnabled('nonexistent')).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('FE-ADDON-004: API failure', () => {
|
|
it('sets loaded: true and keeps addons empty on API error', async () => {
|
|
server.use(
|
|
http.get('/api/addons', () =>
|
|
HttpResponse.json({ error: 'Server error' }, { status: 500 })
|
|
)
|
|
);
|
|
|
|
await useAddonStore.getState().loadAddons();
|
|
const state = useAddonStore.getState();
|
|
|
|
expect(state.loaded).toBe(true);
|
|
expect(state.addons).toEqual([]);
|
|
});
|
|
});
|
|
});
|