Files
TREK/client/src/components/Collections/PlaceEditForm.test.tsx
T
Maurice 20e3d2d9ae test(places): cover the place view, the rating row and the rating filter
Tests for the vote by entry key in the api and the repository, the rating
row and its voters, the rating filter and sort on both views, the edit form
without a choice of copy, and the place view's sections, aligned with the
renamed tag strings.
2026-11-29 23:36:43 +00:00

70 lines
3.3 KiB
TypeScript

// 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<typeof placeEditState>[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(<PlaceEditForm edit={placeEditState()} categories={[]} t={t} />);
expect(container).toBeEmptyDOMElement();
});
it('FE-COMP-PLACEEDITFORM-002: shows the draft, and each field writes its own part of it', () => {
const edit = editing();
render(<PlaceEditForm edit={edit} categories={[]} t={t} />);
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(<PlaceEditForm edit={editing()} categories={[]} t={t} />);
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(<PlaceEditForm edit={edit} categories={CATEGORIES} t={t} />);
fireEvent.click(screen.getByRole('button', { name: 'collections.category: collections.noCategory' }));
fireEvent.click(screen.getByRole('option', { name: 'Food' }));
expect(edit.set).toHaveBeenLastCalledWith('categoryId', 3);
});
});