diff --git a/client/scripts/format-baseline.json b/client/scripts/format-baseline.json index 106c4dc2b..b30d918ff 100644 --- a/client/scripts/format-baseline.json +++ b/client/scripts/format-baseline.json @@ -640,7 +640,6 @@ "src/components/Planner/PlaceFormModal.helpers.test.ts", "src/components/Planner/PlaceFormModal.helpers.ts", "src/components/Planner/PlaceFormModal.test.tsx", - "src/components/Planner/PlaceFormModal.tsx", "src/components/Planner/PlaceInspector.test.tsx", "src/components/Planner/PlaceInspector.tsx", "src/components/Planner/PlacesBulkCategoryModal.test.tsx", diff --git a/client/src/components/Assistant/AssistantChangeCard.test.tsx b/client/src/components/Assistant/AssistantChangeCard.test.tsx index fb262ce4c..5e4993dc6 100644 --- a/client/src/components/Assistant/AssistantChangeCard.test.tsx +++ b/client/src/components/Assistant/AssistantChangeCard.test.tsx @@ -11,12 +11,13 @@ import type { AssistantApplied, AssistantChangeEffect, AssistantChangePreview } from '@trek/shared'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { buildAssignment, buildDay, buildPlace, buildTrip } from '../../../tests/helpers/factories'; -import { act, fireEvent, render, screen } from '../../../tests/helpers/render'; +import { buildAssignment, buildCategory, buildDay, buildPlace, buildTrip } from '../../../tests/helpers/factories'; +import { act, fireEvent, render, screen, within } from '../../../tests/helpers/render'; import { chatOf, useAssistantStore } from '../../store/assistantStore'; import { useTripStore } from '../../store/tripStore'; import AssistantChangeCard from './AssistantChangeCard'; import AssistantCompareSwitch from './AssistantCompareSwitch'; +import AssistantDayPreview from './AssistantDayPreview'; import type { ChangeItem } from './assistantParts'; import { type AssistantView, AssistantViewContext } from './assistantViewContext'; @@ -168,6 +169,106 @@ describe('AssistantChangeCard: deciding', () => { expect(screen.getByRole('button', { name: 'Apply' })).toBeDisabled(); expect(screen.getByRole('button', { name: 'Discard' })).toBeDisabled(); }); + + it('edits a place proposal in the full place form and previews edits before applying', async () => { + plannerHere(); + const change = { + ...preview('c1', 'Kinkaku-ji'), + verbKey: 'addPlaceToDay' as const, + effect: { ...PANTHEON, place: { name: 'Kinkaku-ji', lat: 48, lng: 2, categoryId: 31 } }, + }; + const other = { ...change, toolCallId: 'c2', subject: 'Tea house', effect: null }; + useTripStore.setState({ + categories: [ + buildCategory({ id: 31, name: 'Temple', color: '#334455' }), + buildCategory({ id: 32, name: 'Garden', color: '#667788' }), + ], + }); + patchChat({ + messages: [ + { + id: 'm1', + role: 'assistant', + status: 'complete', + createdAt: new Date().toISOString(), + parts: [ + { + type: 'tool-call', + toolCallId: 'c1', + toolName: 'create_and_assign_place', + args: {}, + approval: { id: 'c1' }, + }, + { type: 'data-trek-change', data: change }, + { + type: 'tool-call', + toolCallId: 'c2', + toolName: 'create_and_assign_place', + args: {}, + approval: { id: 'c2' }, + }, + { type: 'data-trek-change', data: other }, + ], + }, + ], + }); + render(); + renderCard([ + { ...pending('c1', 'Kinkaku-ji'), preview: change }, + { ...pending('c2', 'Tea house'), preview: other }, + ]); + const day = screen.getByRole('list', { name: 'Suggested by the assistant' }); + + const [edit] = screen.getAllByRole('button', { name: 'Edit' }); + fireEvent.click(edit); + const dialog = within(await screen.findByRole('dialog', { name: 'Edit Place' })); + expect(dialog.getByRole('textbox', { name: /^Name/ })).toHaveValue('Kinkaku-ji'); + expect(dialog.getByRole('textbox', { name: 'Address' })).toBeVisible(); + fireEvent.change(dialog.getByRole('textbox', { name: 'Start' }), { target: { value: '12:30' } }); + fireEvent.change(dialog.getByRole('textbox', { name: 'Notes for this day' }), { + target: { value: 'Use the side entrance' }, + }); + fireEvent.click(dialog.getByRole('button', { name: /^Category:/ })); + fireEvent.click(screen.getByRole('button', { name: /^Garden$/ })); + expect(day).toHaveTextContent('12:30'); + expect(day).toHaveTextContent('Use the side entrance'); + expect(within(day).getByText('Garden').parentElement).toHaveStyle({ backgroundColor: '#667788' }); + expect(decide).not.toHaveBeenCalled(); + fireEvent.click(dialog.getByRole('button', { name: 'Cancel' })); + expect(day).toHaveTextContent('10:30'); + expect(day).toHaveTextContent('Temple'); + expect(day).not.toHaveTextContent('Use the side entrance'); + + fireEvent.click(edit); + const reopened = within(await screen.findByRole('dialog', { name: 'Edit Place' })); + const time = reopened.getByRole('textbox', { name: 'Start' }); + expect(time).toHaveValue('10:30'); + fireEvent.change(time, { target: { value: '11:45' } }); + fireEvent.change(reopened.getByRole('textbox', { name: /^Name/ }), { target: { value: 'Golden Pavilion' } }); + fireEvent.change(reopened.getByRole('textbox', { name: 'Address' }), { target: { value: 'Kyoto, Japan' } }); + expect(day).toHaveTextContent('Golden Pavilion'); + fireEvent.click(reopened.getByRole('button', { name: 'Save' })); + expect(day).toHaveTextContent('11:45'); + expect(decide).not.toHaveBeenCalled(); + + const [include] = screen.getAllByRole('button', { name: 'Include this change' }); + fireEvent.click(include); + expect(day).not.toHaveTextContent('Golden Pavilion'); + expect(day).toHaveTextContent('Tea house'); + fireEvent.click(include); + expect(day).toHaveTextContent('Golden Pavilion'); + expect(day).toHaveTextContent('11:45'); + + fireEvent.click(screen.getByRole('button', { name: 'Apply 2' })); + expect(decide).toHaveBeenCalledWith(TRIP, [ + { + toolCallId: 'c1', + approved: true, + planEdits: { startTime: '11:45', place: { name: 'Golden Pavilion', address: 'Kyoto, Japan' } }, + }, + { toolCallId: 'c2', approved: true }, + ]); + }); }); describe('AssistantChangeCard: the receipt', () => { diff --git a/client/src/components/Assistant/AssistantChangeCard.tsx b/client/src/components/Assistant/AssistantChangeCard.tsx index 319c4373a..63dd7c618 100644 --- a/client/src/components/Assistant/AssistantChangeCard.tsx +++ b/client/src/components/Assistant/AssistantChangeCard.tsx @@ -1,4 +1,4 @@ -import { Check, CheckCheck, ListChecks, LoaderCircle, MapPin, Undo2 } from 'lucide-react'; +import { Check, CheckCheck, ChevronDown, ListChecks, LoaderCircle, MapPin, Undo2 } from 'lucide-react'; import { type ReactNode, useEffect, useMemo, useState } from 'react'; import { useTranslation } from '../../i18n'; @@ -78,13 +78,21 @@ function dayChangesOf(items: readonly ChangeItem[], excluded: ReadonlySet +