Files
TREK/client/src/hooks/useKeyboardInset.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

61 lines
1.7 KiB
TypeScript

// FE-HOOK-KBINSET-001 to FE-HOOK-KBINSET-004
import { act, renderHook } from '@testing-library/react';
import { useKeyboardInset } from './useKeyboardInset';
class FakeVisualViewport extends EventTarget {
height = 800;
offsetTop = 0;
}
let viewport: FakeVisualViewport;
beforeEach(() => {
viewport = new FakeVisualViewport();
vi.stubGlobal('visualViewport', viewport);
vi.stubGlobal('innerHeight', 800);
});
afterEach(() => {
vi.unstubAllGlobals();
});
function keyboard(height: number, offsetTop = 0) {
act(() => {
viewport.height = 800 - height - offsetTop;
viewport.offsetTop = offsetTop;
viewport.dispatchEvent(new Event('resize'));
});
}
describe('useKeyboardInset', () => {
it('FE-HOOK-KBINSET-001: is zero while no keyboard is up', () => {
const { result } = renderHook(() => useKeyboardInset());
expect(result.current).toBe(0);
});
it('FE-HOOK-KBINSET-002: follows the keyboard as it opens and closes', () => {
const { result } = renderHook(() => useKeyboardInset());
keyboard(320);
expect(result.current).toBe(320);
keyboard(0);
expect(result.current).toBe(0);
});
it('FE-HOOK-KBINSET-003: leaves out the part the page scrolled the viewport by', () => {
const { result } = renderHook(() => useKeyboardInset());
act(() => {
viewport.height = 480;
viewport.offsetTop = 40;
viewport.dispatchEvent(new Event('scroll'));
});
expect(result.current).toBe(280);
});
it('FE-HOOK-KBINSET-004: stays at zero where the browser has no visual viewport', () => {
vi.stubGlobal('visualViewport', null);
const { result } = renderHook(() => useKeyboardInset());
expect(result.current).toBe(0);
});
});