mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(assistant): green CI round, trip notes the assistant can keep, calmer change cards
- the assistant keeps facts for a trip (remember_for_trip) as a change card, applied into the user's trip notes; existing expenses can be changed - change card fields as a few icon chips with the rest folded under Details, the day band marks only what changes, the week grid as compact tiles - no map button on receipts of things that have no place on the map - tests follow the composer's accessible name, the receipt's status icon and the GL map's container; the hanging stream helper honours an early abort - Postgres probe: qualified columns in the upsert updates; entities restored to the generator's output; strict ratchet reads the SDK client as untyped
This commit is contained in:
@@ -161,7 +161,8 @@ describe('useLlmParsingConfig', () => {
|
||||
await act(async () => result.current.setVision('off'));
|
||||
act(() => result.current.setProvider('anthropic'));
|
||||
await act(() => result.current.save());
|
||||
expect(vi.mocked(adminApi.updateAddon).mock.calls.at(-1)?.[1]).toEqual({
|
||||
const calls = vi.mocked(adminApi.updateAddon).mock.calls;
|
||||
expect(calls[calls.length - 1]?.[1]).toEqual({
|
||||
config: { provider: 'anthropic', model: '', baseUrl: '', apiKey: '', vision: 'off' },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -166,7 +166,7 @@ describe('AssistantChangeCard: the receipt', () => {
|
||||
const onShowOnMap = vi.fn();
|
||||
renderCard([receipt('c1', '2026-10-21T08:15:00.000Z')], { onShowOnMap });
|
||||
|
||||
expect(screen.getByText('Applied')).toBeInTheDocument();
|
||||
expect(screen.getByRole('img', { name: 'Applied' })).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Show on map' }));
|
||||
expect(onShowOnMap).toHaveBeenCalledWith(expect.objectContaining({ toolCallId: 'c1', dayId: 3 }));
|
||||
expect(screen.getByRole('button', { name: 'Undo' })).toBeInTheDocument();
|
||||
@@ -188,7 +188,7 @@ describe('AssistantChangeCard: the receipt', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Undo' }));
|
||||
});
|
||||
expect(undo).toHaveBeenCalledWith(TRIP, 'c1');
|
||||
expect(screen.getByText('Undone')).toBeInTheDocument();
|
||||
expect(screen.getByRole('img', { name: 'Undone' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Undo' })).toBeNull();
|
||||
first.unmount();
|
||||
|
||||
@@ -204,7 +204,7 @@ describe('AssistantChangeCard: the receipt', () => {
|
||||
renderCard([receipt('c1', null), { ...pending('c2', 'Ryoan-ji'), state: 'discarded' }]);
|
||||
expect(screen.queryByRole('button', { name: 'Show on map' })).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: 'Undo' })).toBeNull();
|
||||
expect(screen.getByText('Discarded')).toBeInTheDocument();
|
||||
expect(screen.getByRole('img', { name: 'Discarded' })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { AssistantChangePreview, AssistantChangeRow, AssistantChangeVerbKey } from '@trek/shared';
|
||||
import type { AssistantApplied, AssistantChangePreview, AssistantChangeVerbKey } from '@trek/shared';
|
||||
import {
|
||||
ArrowRight,
|
||||
CalendarArrowUp,
|
||||
CalendarMinus,
|
||||
CalendarPlus,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
Luggage,
|
||||
MapPin,
|
||||
MapPinPlus,
|
||||
NotebookPen,
|
||||
PencilLine,
|
||||
StickyNote,
|
||||
Ticket,
|
||||
@@ -27,10 +27,11 @@ import { useTripStore } from '../../store/tripStore';
|
||||
import ToggleSwitch from '../Settings/ToggleSwitch';
|
||||
import { useToast } from '../shared/Toast';
|
||||
import { Tooltip } from '../shared/Tooltip';
|
||||
import AssistantChangeFields from './AssistantChangeFields';
|
||||
import AssistantCompareSwitch from './AssistantCompareSwitch';
|
||||
import AssistantDayBand from './AssistantDayBand';
|
||||
import AssistantWeekOverview from './AssistantWeekOverview';
|
||||
import { CHANGE_LABELS, type ChangeItem, type ChangeState, undoLeftMs } from './assistantParts';
|
||||
import { type ChangeItem, type ChangeState, undoLeftMs } from './assistantParts';
|
||||
import { useAssistantView } from './assistantViewContext';
|
||||
import { changePoints, type DayChange } from './dayAfterModel';
|
||||
import { useChangeHover } from './useChangeHover';
|
||||
@@ -78,8 +79,10 @@ const VERB_LOOK: Record<AssistantChangeVerbKey, { Icon: typeof Check; tone: Tone
|
||||
updatePackingItem: { Icon: Luggage, tone: 'info' },
|
||||
addTodo: { Icon: ListTodo, tone: 'success' },
|
||||
addBudgetItem: { Icon: Wallet, tone: 'success' },
|
||||
updateBudgetItem: { Icon: Wallet, tone: 'info' },
|
||||
addReservation: { Icon: Ticket, tone: 'success' },
|
||||
importBooking: { Icon: Ticket, tone: 'success' },
|
||||
rememberNote: { Icon: NotebookPen, tone: 'info' },
|
||||
};
|
||||
|
||||
/** How a decided change reads: one quiet mark, its words in the tooltip. */
|
||||
@@ -130,37 +133,6 @@ function ChangeHead({ preview, struck = false }: { preview: AssistantChangePrevi
|
||||
);
|
||||
}
|
||||
|
||||
/** One field as a badge that holds its label as a smaller badge; a change shows the old value struck through. */
|
||||
function FieldBadge({ row }: { row: AssistantChangeRow }) {
|
||||
const { t } = useTranslation();
|
||||
const empty = <span className="italic text-content-faint">{t('assistant.change.empty')}</span>;
|
||||
return (
|
||||
<span className="inline-flex max-w-full items-center gap-1.5 rounded-full bg-surface-secondary py-[3px] pe-2.5 ps-[3px] text-caption text-content">
|
||||
<span className="flex-shrink-0 rounded-full bg-surface-card px-2 py-px text-content-muted">
|
||||
{t(CHANGE_LABELS[row.labelKey].labelKey)}
|
||||
</span>
|
||||
{row.op !== 'add' && (
|
||||
<>
|
||||
<bdi className="min-w-0 truncate text-content-faint line-through">{row.before || empty}</bdi>
|
||||
<ArrowRight size={11} aria-hidden="true" className="flex-shrink-0 text-content-faint rtl:-scale-x-100" />
|
||||
</>
|
||||
)}
|
||||
<bdi className="min-w-0 truncate">{row.after || empty}</bdi>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function ChangeFields({ rows }: { rows: AssistantChangeRow[] }) {
|
||||
if (rows.length === 0) return null;
|
||||
return (
|
||||
<div className="mt-2 flex flex-wrap gap-1.5">
|
||||
{rows.map((row, i) => (
|
||||
<FieldBadge key={`${row.labelKey}-${i}`} row={row} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The time now, ticking once more when the next undo window closes. */
|
||||
function useUndoClock(items: ChangeItem[]): number {
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
@@ -192,6 +164,9 @@ function dayChangesOf(items: readonly ChangeItem[], excluded: ReadonlySet<string
|
||||
);
|
||||
}
|
||||
|
||||
/** What an applied change can be shown as on the map; a kept note, a todo or an expense has no place there. */
|
||||
const ON_MAP: ReadonlySet<AssistantApplied['entity']> = new Set(['place', 'assignment', 'day_note', 'reservation']);
|
||||
|
||||
function Receipt({
|
||||
item,
|
||||
undone,
|
||||
@@ -209,6 +184,7 @@ function Receipt({
|
||||
const receipt = undone ? RECEIPT.discarded : RECEIPT[item.state];
|
||||
const { Icon } = receipt;
|
||||
const applied = item.state === 'applied' && !undone ? item.applied : null;
|
||||
const mappable = applied !== null && ON_MAP.has(applied.entity);
|
||||
const settled = item.state === 'discarded' || item.state === 'expired' || undone;
|
||||
const statusLabel = t(undone ? 'assistant.change.undone' : receipt.labelKey);
|
||||
return (
|
||||
@@ -217,7 +193,7 @@ function Receipt({
|
||||
<div className={`min-w-0 flex-1 ${settled ? 'opacity-60' : ''}`}>
|
||||
<ChangeHead preview={item.preview} struck={settled} />
|
||||
</div>
|
||||
{applied && onShowOnMap && (
|
||||
{applied && mappable && onShowOnMap && (
|
||||
<Tooltip label={t('assistant.change.showOnMap')} placement="top">
|
||||
<button
|
||||
type="button"
|
||||
@@ -276,7 +252,7 @@ function PendingRow({
|
||||
<KindTile verbKey={item.preview?.verbKey ?? null} />
|
||||
<div className="min-w-0 flex-1">
|
||||
<ChangeHead preview={item.preview} />
|
||||
{item.preview && <ChangeFields rows={item.preview.rows} />}
|
||||
{item.preview && <AssistantChangeFields rows={item.preview.rows} />}
|
||||
</div>
|
||||
{withSwitch && (
|
||||
<ToggleSwitch on={!excluded} onToggle={onToggle} label={t('assistant.change.include')} disabled={disabled} />
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import type { AssistantChangeLabelKey, AssistantChangeRow } from '@trek/shared';
|
||||
import {
|
||||
ArrowRight,
|
||||
CalendarClock,
|
||||
CalendarDays,
|
||||
ChevronDown,
|
||||
Clock,
|
||||
Hash,
|
||||
LogIn,
|
||||
LogOut,
|
||||
type LucideIcon,
|
||||
Tag,
|
||||
Wallet,
|
||||
} from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useTranslation } from '../../i18n';
|
||||
import { CHANGE_LABELS } from './assistantParts';
|
||||
|
||||
/**
|
||||
* The fields of one change, read at a glance: the few that decide whether it
|
||||
* fits (when, what, what it costs) as quiet icon chips, a value that changes
|
||||
* as old to new, everything else folded behind one "Details" line. Positions
|
||||
* and colours never show; the map and the trip show those better.
|
||||
*/
|
||||
|
||||
/** The fields worth a chip of their own, each with its glyph, in this order. */
|
||||
const KEY_FIELDS: Partial<Record<AssistantChangeLabelKey, LucideIcon>> = {
|
||||
day: CalendarDays,
|
||||
time: Clock,
|
||||
endTime: Clock,
|
||||
checkIn: LogIn,
|
||||
checkOut: LogOut,
|
||||
dueDate: CalendarClock,
|
||||
category: Tag,
|
||||
price: Wallet,
|
||||
quantity: Hash,
|
||||
};
|
||||
const KEY_ORDER = Object.keys(KEY_FIELDS) as AssistantChangeLabelKey[];
|
||||
|
||||
/** Fields that mean nothing written out. */
|
||||
const HIDDEN: ReadonlySet<AssistantChangeLabelKey> = new Set(['coordinates', 'position', 'icon', 'color', 'currency']);
|
||||
|
||||
/** "#3" is how a day comes from the server; it reads as "Day 3". */
|
||||
function shown(row: AssistantChangeRow, value: string | null | undefined, dayWord: string): string {
|
||||
if (row.labelKey === 'day' && value && /^#\d+$/.test(value)) return `${dayWord} ${value.slice(1)}`;
|
||||
return value ?? '';
|
||||
}
|
||||
|
||||
function Chip({ row }: { row: AssistantChangeRow }) {
|
||||
const { t } = useTranslation();
|
||||
const Icon = KEY_FIELDS[row.labelKey] ?? Tag;
|
||||
const label = t(CHANGE_LABELS[row.labelKey].labelKey);
|
||||
const dayWord = t('assistant.week.day');
|
||||
const changed = row.op !== 'add' && !!row.before;
|
||||
return (
|
||||
<span
|
||||
title={label}
|
||||
className="inline-flex max-w-full items-center gap-1 rounded-md bg-surface-secondary px-1.5 py-0.5 text-caption text-content-secondary"
|
||||
>
|
||||
<Icon size={11} aria-label={label} className="flex-shrink-0 text-content-faint" />
|
||||
{changed && (
|
||||
<>
|
||||
<bdi className="min-w-0 truncate text-content-faint line-through">{shown(row, row.before, dayWord)}</bdi>
|
||||
<ArrowRight size={10} aria-hidden="true" className="flex-shrink-0 text-content-faint rtl:-scale-x-100" />
|
||||
</>
|
||||
)}
|
||||
<bdi className="min-w-0 truncate font-medium text-content">{shown(row, row.after, dayWord)}</bdi>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** A field behind "Details": its name, then the value, old to new where it changes. */
|
||||
function DetailLine({ row }: { row: AssistantChangeRow }) {
|
||||
const { t } = useTranslation();
|
||||
const changed = row.op !== 'add' && !!row.before;
|
||||
return (
|
||||
<div className="flex min-w-0 gap-2 text-caption">
|
||||
<span className="w-20 flex-shrink-0 truncate text-content-faint">{t(CHANGE_LABELS[row.labelKey].labelKey)}</span>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-1 text-content-secondary">
|
||||
{changed && (
|
||||
<>
|
||||
<bdi className="min-w-0 truncate text-content-faint line-through">{row.before}</bdi>
|
||||
<ArrowRight size={10} aria-hidden="true" className="flex-shrink-0 text-content-faint rtl:-scale-x-100" />
|
||||
</>
|
||||
)}
|
||||
<bdi className="min-w-0 truncate">{row.after || t('assistant.change.empty')}</bdi>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AssistantChangeFields({ rows }: { rows: AssistantChangeRow[] }) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const visible = rows.filter((row) => !HIDDEN.has(row.labelKey) && row.labelKey !== 'name');
|
||||
const key = visible
|
||||
.filter((row) => row.labelKey in KEY_FIELDS && row.after)
|
||||
.sort((a, b) => KEY_ORDER.indexOf(a.labelKey) - KEY_ORDER.indexOf(b.labelKey));
|
||||
const rest = visible.filter((row) => !key.includes(row));
|
||||
if (key.length === 0 && rest.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="mt-1.5 flex flex-col gap-1.5">
|
||||
{key.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{key.map((row, i) => (
|
||||
<Chip key={`${row.labelKey}-${i}`} row={row} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{rest.length > 0 && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
aria-expanded={open}
|
||||
className="inline-flex items-center gap-1 self-start rounded-md text-caption text-content-faint transition-colors hover:text-content"
|
||||
>
|
||||
<ChevronDown
|
||||
size={12}
|
||||
aria-hidden="true"
|
||||
className={`transition-transform duration-200 ${open ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
{t(open ? 'assistant.change.detailsHide' : 'assistant.change.details')}
|
||||
</button>
|
||||
{open && (
|
||||
<div className="trek-assistant-enter flex flex-col gap-1 rounded-lg bg-surface-secondary px-2.5 py-2">
|
||||
{rest.map((row, i) => (
|
||||
<DetailLine key={`${row.labelKey}-${i}`} row={row} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ function seed(tripInPlanner = TRIP) {
|
||||
|
||||
async function input(): Promise<HTMLTextAreaElement> {
|
||||
render(<AssistantSurface tripId={TRIP} tripTitle="Paris" variant="window" />);
|
||||
return (await screen.findByPlaceholderText('Ask anything about Paris')) as HTMLTextAreaElement;
|
||||
return (await screen.findByRole('textbox', { name: 'Ask anything about Paris' })) as HTMLTextAreaElement;
|
||||
}
|
||||
|
||||
const mentions = () => chatOf(useAssistantStore.getState(), TRIP).mentions;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChevronDown, CircleCheck, TriangleAlert } from 'lucide-react';
|
||||
import { ChevronDown, CircleCheck, Minus, Plus, TriangleAlert } from 'lucide-react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
|
||||
@@ -20,8 +20,9 @@ import { useChangeHover } from './useChangeHover';
|
||||
|
||||
/**
|
||||
* The days a waiting card touches, as they would read once it ran: per day its
|
||||
* date and its stops in order as small named chips, so a glance shows where the
|
||||
* suggestion lands among the rest. The details (times, the way between stops,
|
||||
* date and its stops in order. What stays reads as quiet text; only what the
|
||||
* card adds is a filled pill and what it takes away is struck, so a glance
|
||||
* finds the suggestion among the rest. The details (times, the way between stops,
|
||||
* free time, a clash) stay folded away until asked for. Two days at most; the
|
||||
* rest are counted. Shown only while the planner holds this trip, since the day
|
||||
* plans come from it.
|
||||
@@ -33,26 +34,33 @@ const MAX_DAYS = 2;
|
||||
const MAX_CHIPS = 6;
|
||||
|
||||
const CHIP: Record<TimelineStop['status'], string> = {
|
||||
kept: 'border-transparent bg-surface-secondary text-content-muted',
|
||||
new: 'border-dashed border-success bg-success-soft text-content',
|
||||
removed: 'border-transparent text-content-faint line-through',
|
||||
kept: 'px-0.5 text-content-muted',
|
||||
new: 'rounded-full bg-accent px-2 py-0.5 font-medium text-accent-text shadow-sm',
|
||||
removed: 'rounded-full px-1.5 py-0.5 text-content-faint line-through',
|
||||
};
|
||||
|
||||
/** One stop of the day, named; the change it belongs to lights up with it. */
|
||||
function StopChip({ stop }: { stop: TimelineStop }) {
|
||||
const { tripId } = useAssistantView();
|
||||
const { lit, handlers } = useChangeHover(tripId, stop.toolCallId);
|
||||
const clash = stop.lead?.overlapsWith ? 'border-danger' : stopIssue(stop) ? 'border-warning' : '';
|
||||
const issue = stop.lead?.overlapsWith ? 'ring-2 ring-danger' : stopIssue(stop) ? 'ring-2 ring-warning' : '';
|
||||
const Mark = stop.status === 'new' ? Plus : stop.status === 'removed' ? Minus : null;
|
||||
return (
|
||||
<span
|
||||
{...(stop.toolCallId ? handlers : {})}
|
||||
className={`inline-flex max-w-[11rem] items-center rounded-full border px-2 py-0.5 text-caption transition-colors ${CHIP[stop.status]} ${clash} ${lit ? 'bg-surface-hover' : ''}`}
|
||||
className={`inline-flex max-w-[12rem] items-center gap-1 text-caption transition-all ${CHIP[stop.status]} ${issue} ${lit ? 'scale-[1.04]' : ''}`}
|
||||
>
|
||||
{Mark && <Mark size={11} strokeWidth={2.6} aria-hidden="true" className="flex-shrink-0" />}
|
||||
<bdi className="truncate">{stop.name}</bdi>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** The thin rule between two stops, read as "then". */
|
||||
function Then() {
|
||||
return <span aria-hidden="true" className="h-px w-2 flex-shrink-0 bg-edge" />;
|
||||
}
|
||||
|
||||
function Lead({ stop, timed }: { stop: TimelineStop; timed: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const lead = stop.lead;
|
||||
@@ -111,11 +119,16 @@ function DayRow({ day, label, open }: { day: DayAfter; label: string; open: bool
|
||||
const chips = day.stops.slice(0, MAX_CHIPS);
|
||||
return (
|
||||
<div>
|
||||
<bdi className="block truncate text-caption font-medium text-content-muted">{label}</bdi>
|
||||
<bdi className="block truncate text-caption font-semibold uppercase tracking-wide text-content-faint">
|
||||
{label}
|
||||
</bdi>
|
||||
{!open && (
|
||||
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-1">
|
||||
{chips.map((stop) => (
|
||||
<StopChip key={stop.key} stop={stop} />
|
||||
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1 gap-y-1.5">
|
||||
{chips.map((stop, i) => (
|
||||
<span key={stop.key} className="contents">
|
||||
{i > 0 && <Then />}
|
||||
<StopChip stop={stop} />
|
||||
</span>
|
||||
))}
|
||||
{day.stops.length > MAX_CHIPS && (
|
||||
<span className="text-caption tabular-nums text-content-faint">+{day.stops.length - MAX_CHIPS}</span>
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('AssistantSurface', () => {
|
||||
it('FE-AI-SURF-003: Enter sends what was typed, with the trip in the placeholder', async () => {
|
||||
seed([]);
|
||||
renderChat();
|
||||
const input = await screen.findByPlaceholderText('Ask anything about Kyoto');
|
||||
const input = await screen.findByRole('textbox', { name: 'Ask anything about Kyoto' });
|
||||
fireEvent.change(input, { target: { value: 'Where should we eat?' } });
|
||||
expect(chatOf(useAssistantStore.getState(), TRIP).draft).toBe('Where should we eat?');
|
||||
fireEvent.keyDown(input, { key: 'Enter' });
|
||||
@@ -105,7 +105,7 @@ describe('AssistantSurface', () => {
|
||||
},
|
||||
]);
|
||||
renderChat();
|
||||
const input = await screen.findByPlaceholderText('Ask anything about Kyoto');
|
||||
const input = await screen.findByRole('textbox', { name: 'Ask anything about Kyoto' });
|
||||
fireEvent.change(input, { target: { value: 'Something else' } });
|
||||
expect(screen.getByRole('button', { name: 'Send' })).toBeDisabled();
|
||||
expect(screen.getByRole('button', { name: 'Apply' })).toBeInTheDocument();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Check, Minus } from 'lucide-react';
|
||||
|
||||
import { useTranslation } from '../../i18n';
|
||||
import type { WeekDay } from './useWeekDays';
|
||||
|
||||
/**
|
||||
* A plan over several days as one grid: a tile per day with how many changes
|
||||
* it gets, taken in or left out as a whole with one tap. The single changes
|
||||
* A plan over several days as one row of small tiles: a day per tile, its
|
||||
* number of changes in the corner, taken in or left out as a whole with one
|
||||
* tap. The single changes
|
||||
* stay below it, folded away until asked for.
|
||||
*/
|
||||
export default function AssistantWeekOverview({
|
||||
@@ -24,38 +23,43 @@ export default function AssistantWeekOverview({
|
||||
<div
|
||||
role="group"
|
||||
aria-label={t('assistant.week.title')}
|
||||
className="mb-2 grid gap-1.5"
|
||||
className="mb-2 grid gap-2 pt-1"
|
||||
style={{ gridTemplateColumns: `repeat(${Math.min(days.length, 7)}, minmax(0, 1fr))` }}
|
||||
>
|
||||
{days.map((day, i) => {
|
||||
const on = day.ids.filter((id) => !excluded.has(id)).length;
|
||||
const taken = on > 0;
|
||||
const count = taken ? on : day.ids.length;
|
||||
const name = `${day.weekday ?? t('assistant.week.day')} ${day.n}`;
|
||||
return (
|
||||
<button
|
||||
key={day.id}
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
aria-pressed={taken}
|
||||
aria-label={`${name}, ${t('assistant.week.changes', { count })}`}
|
||||
title={t('assistant.week.changes', { count })}
|
||||
onClick={() => onToggleDay(day.ids, !taken)}
|
||||
className={`trek-assistant-enter group/day relative flex min-w-0 flex-col items-center gap-0.5 rounded-xl border px-1 py-2 transition-all disabled:cursor-default ${
|
||||
className={`trek-assistant-enter relative flex min-w-0 flex-col items-center rounded-lg py-1.5 outline-none transition-all focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default ${
|
||||
taken
|
||||
? 'border-accent bg-accent-subtle text-content shadow-sm hover:-translate-y-px hover:shadow-md'
|
||||
: 'border-dashed border-edge text-content-faint hover:border-edge-secondary'
|
||||
? 'bg-accent text-accent-text shadow-sm hover:-translate-y-px hover:shadow-md'
|
||||
: 'bg-surface-secondary text-content-faint hover:text-content-muted'
|
||||
}`}
|
||||
style={{ animationDelay: `${i * 40}ms` }}
|
||||
>
|
||||
<span className={`text-caption leading-tight ${taken ? 'opacity-75' : ''}`}>
|
||||
{day.weekday ?? t('assistant.week.day')}
|
||||
</span>
|
||||
<span className={`text-body font-semibold tabular-nums leading-tight ${taken ? '' : 'line-through'}`}>
|
||||
{day.n}
|
||||
</span>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`absolute end-1 top-1 grid h-3.5 w-3.5 place-items-center rounded-full ${
|
||||
taken ? 'bg-accent text-accent-text' : 'bg-surface-tertiary text-content-faint'
|
||||
className={`absolute -end-1 -top-1 grid h-4 min-w-4 place-items-center rounded-full px-1 text-caption font-semibold tabular-nums leading-none ring-2 ring-surface-card ${
|
||||
taken ? 'bg-surface-card text-content' : 'bg-surface-tertiary text-content-faint'
|
||||
}`}
|
||||
>
|
||||
{taken ? <Check size={9} strokeWidth={3} /> : <Minus size={9} strokeWidth={3} />}
|
||||
</span>
|
||||
<span className="text-caption text-content-muted">{day.weekday ?? t('assistant.week.day')}</span>
|
||||
<span className="text-subtitle font-bold tabular-nums leading-none">{day.n}</span>
|
||||
<span className={`text-caption tabular-nums ${taken ? 'text-content-secondary' : ''}`}>
|
||||
{t('assistant.week.changes', { count: taken ? on : day.ids.length })}
|
||||
{count}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import type { AiStatusResponse } from '@trek/shared';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
|
||||
import { act, fireEvent, render, screen, waitFor } from '../../../tests/helpers/render';
|
||||
import { tripRepo } from '../../repo/tripRepo';
|
||||
import { chatOf, useAssistantStore } from '../../store/assistantStore';
|
||||
import type { Trip } from '../../types';
|
||||
@@ -62,6 +62,8 @@ const resume = vi.fn(async () => {});
|
||||
const cancel = vi.fn();
|
||||
|
||||
function seed(window: { open: boolean; minimized: boolean }, isRunning = false) {
|
||||
// A chat the test before unmounted stops itself on the way out; that call is not this test's.
|
||||
cancel.mockClear();
|
||||
useAssistantStore.setState({
|
||||
status: STATUS,
|
||||
window,
|
||||
@@ -135,9 +137,11 @@ describe('AssistantWindow', () => {
|
||||
expect(cancel).toHaveBeenCalledWith(TRIP.id);
|
||||
expect(useAssistantStore.getState().window.open).toBe(true);
|
||||
|
||||
useAssistantStore.setState({
|
||||
byTrip: { [TRIP.id]: { ...chatOf(useAssistantStore.getState(), TRIP.id), isRunning: false } },
|
||||
});
|
||||
act(() =>
|
||||
useAssistantStore.setState({
|
||||
byTrip: { [TRIP.id]: { ...chatOf(useAssistantStore.getState(), TRIP.id), isRunning: false } },
|
||||
})
|
||||
);
|
||||
fireEvent.keyDown(dialog, { key: 'Escape' });
|
||||
expect(useAssistantStore.getState().window.open).toBe(false);
|
||||
});
|
||||
|
||||
@@ -18,6 +18,10 @@ const STATUS: Partial<Record<AssistantMessage['status'], ThreadMessageLike['stat
|
||||
|
||||
function toPart(part: AssistantMessagePart): LikePart | null {
|
||||
if (part.type === 'text') return part.text ? { type: 'text', text: part.text } : null;
|
||||
// An attached file is drawn from the stored message; the runtime takes it as one more data part.
|
||||
if (part.type === 'attachment') {
|
||||
return { type: 'data-trek-attachment', data: { name: part.name, mime: part.mime, size: part.size } };
|
||||
}
|
||||
if (part.type !== 'tool-call') return part;
|
||||
return {
|
||||
type: 'tool-call',
|
||||
|
||||
@@ -47,7 +47,7 @@ function seed(tripInPlanner = TRIP) {
|
||||
|
||||
async function input(): Promise<HTMLTextAreaElement> {
|
||||
render(<AssistantSurface tripId={TRIP} tripTitle="Paris" variant="window" />);
|
||||
return (await screen.findByPlaceholderText('Ask anything about Paris')) as HTMLTextAreaElement;
|
||||
return (await screen.findByRole('textbox', { name: 'Ask anything about Paris' })) as HTMLTextAreaElement;
|
||||
}
|
||||
|
||||
/** A drag as startPlaceDrag starts it; jsdom keeps the type's case, browsers lower it. */
|
||||
|
||||
@@ -47,6 +47,8 @@ const glMap = vi.hoisted(() => ({
|
||||
getStyle: vi.fn().mockReturnValue({ layers: [] }),
|
||||
isStyleLoaded: vi.fn().mockReturnValue(true),
|
||||
getCanvasContainer: vi.fn(() => glCanvasContainer),
|
||||
// The assistant's camera listens on the map's container for the user's own moves.
|
||||
getContainer: vi.fn(() => glCanvasContainer),
|
||||
getLayer: vi.fn().mockReturnValue(null),
|
||||
queryRenderedFeatures: vi.fn().mockReturnValue([]),
|
||||
querySourceFeatures: vi.fn().mockReturnValue([]),
|
||||
|
||||
@@ -16,22 +16,26 @@ function setup(hoveredId: string | null = null) {
|
||||
const attached: { el: HTMLElement; lng: number; lat: number; remove: ReturnType<typeof vi.fn> }[] = [];
|
||||
const pinsRef = { current: [] as { remove: () => void }[] };
|
||||
const onHover = vi.fn();
|
||||
const onClick = vi.fn();
|
||||
// Stable across renders, as the map view hands them over: only `hovered` changes.
|
||||
const mapRef = { current: map };
|
||||
const attachPin = (el: HTMLElement, lng: number, lat: number) => {
|
||||
container.appendChild(el);
|
||||
const pin = { el, lng, lat, remove: vi.fn(() => el.remove()) };
|
||||
attached.push(pin);
|
||||
return pin;
|
||||
};
|
||||
const hook = renderHook(
|
||||
({ hovered }) =>
|
||||
useAssistantGhostMarkersGL({
|
||||
mapRef: { current: map },
|
||||
mapRef,
|
||||
mapReady: true,
|
||||
pinsRef,
|
||||
attachPin: (el, lng, lat) => {
|
||||
container.appendChild(el);
|
||||
const pin = { el, lng, lat, remove: vi.fn(() => el.remove()) };
|
||||
attached.push(pin);
|
||||
return pin;
|
||||
},
|
||||
attachPin,
|
||||
ghosts: GHOSTS,
|
||||
hoveredId: hovered,
|
||||
onHover,
|
||||
onClick: vi.fn(),
|
||||
onClick,
|
||||
}),
|
||||
{ initialProps: { hovered: hoveredId } }
|
||||
);
|
||||
|
||||
@@ -1013,8 +1013,9 @@ describe('IntegrationsTab – failure toasts', () => {
|
||||
}),
|
||||
),
|
||||
);
|
||||
render(<IntegrationsTab />);
|
||||
const off = render(<IntegrationsTab />);
|
||||
expect(screen.queryByText('AI assistant')).not.toBeInTheDocument();
|
||||
off.unmount();
|
||||
|
||||
enableAddons(['ai_assistant']);
|
||||
const { unmount } = render(<IntegrationsTab />);
|
||||
|
||||
@@ -31,7 +31,8 @@ describe('ClaudeConnectorCard', () => {
|
||||
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
const qr = screen.getByAltText('QR code to add TREK in Claude');
|
||||
expect(qr.getAttribute('src')).toMatch(/^data:image\/svg\+xml;charset=utf-8,/);
|
||||
expect(container.querySelector('rect')).toBeNull();
|
||||
// The QR code's own markup never lands in the page; icons may draw rects of their own.
|
||||
expect(container.querySelector('rect[width="1"][height="1"]')).toBeNull();
|
||||
expect(document.getElementById('claude-connector')).not.toBeNull();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user