worldmap-viewer

git clone https://git.godosa.eu/worldmap-viewer

master

raw ยท 2517 bytes

import './_planet.mjs';
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { filterPins, loreWarning, pinPayload, epochIds } from '../js/pins.js';

const pins = [
  { id: 'pin-1', name: 'Zeta ford', lat: 1, lon: 2, lore: null, note: 'shallow crossing' },
  { id: 'pin-2', name: 'alpha peak', lat: 3, lon: 4, lore: 'physical-world', note: '' },
  { id: 'pin-3', name: 'Mid Lake', lat: 5, lon: 6, lore: null, note: '' },
];

test('search: name, lore id and note, case-insensitive; sorted by name', () => {
  assert.deepEqual(filterPins(pins, '').map(p => p.id), ['pin-2', 'pin-3', 'pin-1']);
  assert.deepEqual(filterPins(pins, 'PEAK').map(p => p.id), ['pin-2']);
  assert.deepEqual(filterPins(pins, 'physical').map(p => p.id), ['pin-2']);
  assert.deepEqual(filterPins(pins, 'crossing').map(p => p.id), ['pin-1']);
  assert.deepEqual(filterPins(pins, 'nothing'), []);
  assert.equal(pins[0].id, 'pin-1', 'input not reordered');
});

test('lore warning only for unknown ids', () => {
  assert.equal(loreWarning('', ['a']), null);
  assert.equal(loreWarning('a', ['a']), null);
  assert.match(loreWarning('b-c', ['a']), /not a known lore id/);
});

test('payload trims and turns an empty lore id into null', () => {
  assert.deepEqual(pinPayload({ name: '  Ford ', lat: 1, lon: 2, lore: ' ', note: ' x ', id: 'pin-9', cell: 'c' }),
    { name: 'Ford', lat: 1, lon: 2, lore: null, note: 'x', epoch: null });
});

test('a draft marker shows while the new-pin form is open', async () => {
  const { FakeEl, installFakeDom } = await import('./fakedom.mjs');
  installFakeDom();
  const { PinsPanel } = await import('../js/pins.js');
  const drafts = [];
  const p = new PinsPanel(new FakeEl('section'), [], { onPins() {}, onFly() {}, onPlacing() {}, onDraft: d => drafts.push(d) });
  p.placeAt({ lat: 1, lon: 2 });
  assert.deepEqual(drafts.at(-1), { lat: 1, lon: 2 });
  p.box.find(e => e.tag === 'button' && e.textContent === 'Cancel').fire('click');
  assert.equal(drafts.at(-1), null);
});

test('payload carries the epoch and numeric coordinates', () => {
  assert.deepEqual(pinPayload({ name: 'X', lat: '-15.5', lon: '-34.2', lore: 'cell-am-zee', note: '', epoch: 'epoch-high-fantasy' }),
    { name: 'X', lat: -15.5, lon: -34.2, lore: 'cell-am-zee', note: '', epoch: 'epoch-high-fantasy' });
});

test('epoch choices come from the lore ids', () => {
  assert.deepEqual(epochIds(['a', 'epoch-high-fantasy', 'epochs', 'epoch-space-age']), ['epoch-high-fantasy', 'epoch-space-age']);
});