Files
TREK/client/src/components/Collections/addPlaceModel.test.ts
T
Maurice b2fd0ae5aa refactor(collections): share the add place to list logic between desktop and phone
useAddPlaceToCollection holds the maps search, the pick and the save
that AddPlaceToCollectionModal and MCollAddSheet each carried, with the
pure helpers in addPlaceModel.

The differences stay as variants. The desktop resets and stays open
after an add, sends links and typed coordinates and shows the error's
own text. The phone closes, takes coordinates only from the picked hit,
ignores a second search or save while one is running and shows the
fallback text.
2026-10-09 15:19:41 +02:00

26 lines
949 B
TypeScript

// FE-COMP-ADDPLACEMODEL-001 to FE-COMP-ADDPLACEMODEL-002: reading the loosely typed
// fields of a maps search hit.
import { describe, expect, it } from 'vitest';
import { num, str } from './addPlaceModel';
describe('addPlaceModel', () => {
it('FE-COMP-ADDPLACEMODEL-001: str keeps a non-empty string and drops everything else', () => {
expect(str('Elbphilharmonie')).toBe('Elbphilharmonie');
expect(str('')).toBeUndefined();
expect(str(42)).toBeUndefined();
expect(str(null)).toBeUndefined();
expect(str(undefined)).toBeUndefined();
});
it('FE-COMP-ADDPLACEMODEL-002: num reads a number or numeric text, and nothing else', () => {
expect(num(9.9841)).toBe(9.9841);
expect(num(0)).toBe(0);
expect(num('53.5413')).toBe(53.5413);
expect(num('')).toBeUndefined();
expect(num(null)).toBeUndefined();
expect(num(undefined)).toBeUndefined();
expect(Number.isNaN(num('abc'))).toBe(true);
});
});