// FE-COMP-PLACEEDITFORM-001 to FE-COMP-PLACEEDITFORM-004: the edit form of a place of All // places in the desktop dialog. import { libraryInfo, placeEditState } from '../../../tests/helpers/placesLibrary'; import { fireEvent, render, screen } from '../../../tests/helpers/render'; import type { Category } from '../../types'; import PlaceEditForm from './PlaceEditForm'; import type { EditTarget } from './usePlaceEdit'; const t = (k: string) => k; const LIST: EditTarget = { key: 'list:900', kind: 'list', source: 'Favourites', ref: { kind: 'list', collection_place_id: 900 }, info: libraryInfo(), }; const DRAFT = { name: 'Colosseum', categoryId: null, address: 'Piazza', lat: '41.89', lng: '12.49', description: 'Arena', }; const CATEGORIES = [{ id: 3, name: 'Food', color: '#f00', icon: 'utensils' }] as unknown as Category[]; const editing = (over: Parameters[0] = {}) => placeEditState({ canEdit: true, editing: true, target: LIST, draft: DRAFT, ...over }); describe('PlaceEditForm', () => { it('FE-COMP-PLACEEDITFORM-001: draws nothing without a draft', () => { const { container } = render(); expect(container).toBeEmptyDOMElement(); }); it('FE-COMP-PLACEEDITFORM-002: shows the draft, and each field writes its own part of it', () => { const edit = editing(); render(); const name = screen.getByRole('textbox', { name: 'common.name' }); expect(name).toHaveValue('Colosseum'); fireEvent.change(name, { target: { value: 'Arena' } }); expect(edit.set).toHaveBeenLastCalledWith('name', 'Arena'); fireEvent.change(screen.getByPlaceholderText('places.formAddressPlaceholder'), { target: { value: 'Via 1' } }); expect(edit.set).toHaveBeenLastCalledWith('address', 'Via 1'); fireEvent.change(screen.getByPlaceholderText('places.formLat'), { target: { value: '40.5' } }); expect(edit.set).toHaveBeenLastCalledWith('lat', '40.5'); fireEvent.change(screen.getByPlaceholderText('places.formLng'), { target: { value: '-3.25' } }); expect(edit.set).toHaveBeenLastCalledWith('lng', '-3.25'); fireEvent.change(screen.getByPlaceholderText('collections.descriptionPlaceholder'), { target: { value: 'New' } }); expect(edit.set).toHaveBeenLastCalledWith('description', 'New'); // No categories to pick from. expect(screen.queryByRole('button', { name: /collections\.category/ })).toBeNull(); }); it('FE-COMP-PLACEEDITFORM-003: offers no choice of copy, the edit reaches every copy the reader may edit', () => { render(); expect(screen.queryByRole('button', { name: 'Favourites' })).toBeNull(); expect(screen.queryByRole('button', { name: 'Rome 2026' })).toBeNull(); }); it('FE-COMP-PLACEEDITFORM-004: the category tile beside the name picks the category of the draft', () => { const edit = editing(); render(); fireEvent.click(screen.getByRole('button', { name: 'collections.category: collections.noCategory' })); fireEvent.click(screen.getByRole('option', { name: 'Food' })); expect(edit.set).toHaveBeenLastCalledWith('categoryId', 3); }); });