mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
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.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user