feat(map): add persisted ghost pin sandbox
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let ghostPins;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({
|
||||
appType: "custom",
|
||||
logLevel: "silent",
|
||||
server: { middlewareMode: true },
|
||||
});
|
||||
ghostPins = await server.ssrLoadModule("/src/core/map/ghostPins.ts");
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
test("ghost pins are generated inside the requested current-view radius", () => {
|
||||
const samples = [0, 0.25, 0.5, 0.75, 0.1, 0.9];
|
||||
let index = 0;
|
||||
const pins = ghostPins.generateGhostPins({
|
||||
anchor: { longitude: 37.618423, latitude: 55.751244 },
|
||||
count: 3,
|
||||
radiusMeters: 1_000,
|
||||
random: () => samples[index++ % samples.length],
|
||||
timestamp: 42,
|
||||
});
|
||||
|
||||
assert.equal(pins.length, 3);
|
||||
assert.equal(new Set(pins.map((pin) => pin.label)).size, 3);
|
||||
assert.ok(pins.every((pin) => /^\d{6}$/.test(pin.label)));
|
||||
assert.ok(pins.every((pin) => pin.id.startsWith("ghost-16-")));
|
||||
assert.ok(pins.every((pin) => pin.speedMetersPerSecond >= 3));
|
||||
});
|
||||
|
||||
test("numeric pin names remain unique with a degenerate random source", () => {
|
||||
const pins = ghostPins.generateGhostPins({
|
||||
anchor: { longitude: 37.618423, latitude: 55.751244 },
|
||||
count: 4,
|
||||
radiusMeters: 1_000,
|
||||
random: () => 0,
|
||||
timestamp: 42,
|
||||
});
|
||||
|
||||
assert.equal(new Set(pins.map((pin) => pin.label)).size, 4);
|
||||
});
|
||||
Reference in New Issue
Block a user