clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

feat/atlas-next-horizon
atlas / render / test / demand.test.ts
demand.test.ts 3.8K
1import { strict as assert } from "node:assert";2import test from "node:test";34import { DataPlane } from "../data/plane.ts";5import { demandWindowKey, replaceDemandWindow } from "../data/window.ts";67test("page zero is outline-only and features arrive through bounded pages", async () => {8 const requested: string[] = [];9 const original = globalThis.fetch;10 globalThis.fetch = (async (input: string | URL | Request) => {11 const url = String(input);12 requested.push(url);13 if (url.endsWith("/outline.json")) return Response.json(outline());14 if (url.includes("/features/roads.json")) {15 const continued = url.includes("after=more-is-demanded-later");16 return Response.json({17 features: continued ? [] : [feature()], next: continued ? "" : "more-is-demanded-later",18 });19 }20 return new Response(null, { status: 404 });21 }) as typeof fetch;22 try {23 const opened = await new DataPlane().world("/data/v/sample/abc123abc123", "sample-region");24 assert.equal(opened.world.featureSets[0]?.features.length, 1);25 assert.equal(opened.world.claims[0]?.value, 9223372036854775807n);26 assert.equal(opened.world.claims[1]?.value, -9223372036854775808n);27 assert.equal(opened.world.featureSets[0]?.features[0]?.properties[0]?.value, 9223372036854775807n);28 assert.equal(opened.world.featureSets[0]?.features[0]?.properties[1]?.value, -9223372036854775808n);29 assert.deepEqual(requested, [30 "/data/v/sample/abc123abc123/outline.json",31 "/data/v/sample/abc123abc123/features/roads.json?limit=1000&minX=0&minY=0&maxX=100&maxY=100",32 "/data/v/sample/abc123abc123/features/roads.json?limit=1000&minX=0&minY=0&maxX=100&maxY=100&after=more-is-demanded-later",33 ]);34 assert.ok(requested.every((url) => !url.endsWith("/data/features.pack")));35 } finally {36 globalThis.fetch = original;37 }38});3940test("settled pans replace one world window and zoom changes keep distinct bounds", () => {41 const cache = new Map<string, number>();42 const prefix = "/data/v/sample/build/sample-region/";43 for (let pan = 0; pan < 100; pan++) {44 const key = `${prefix}${demandWindowKey({ x: pan, y: -pan, zoom: 3.1 + pan / 100, rotation: 0 })}`;45 replaceDemandWindow(cache, prefix, key, pan);46 }47 assert.equal(cache.size, 1);48 assert.notEqual(49 demandWindowKey({ x: 10, y: -10, zoom: 3.1, rotation: 0 }),50 demandWindowKey({ x: 10, y: -10, zoom: 3.9, rotation: 0 }),51 );52});5354function outline(): Record<string, unknown> {55 return {56 version: 1, id: "sample", title: "Sample", assets: [],57 worlds: [{58 id: "sample-region", title: "Sample Region", claims: [{59 id: "33333333-3333-5333-8333-333333333333", name: "sample.maximum", kind: 2,60 value: "9223372036854775807",61 }, {62 id: "44444444-4444-5444-8444-444444444444", name: "sample.minimum", kind: 2,63 value: "-9223372036854775808",64 }],65 coordinateSpace: {66 id: "sample-space", kind: "projected", unit: "metre", definition: "sample",67 extent: [0, 0, 100, 100], sourceZoom: "0", originX: "0", originY: "0", tileSize: "256", size: "100",68 },69 featureSets: [{ id: "roads", title: "Roads", semanticType: "transport.road", properties: [], claims: [] }],70 rasterPyramids: [],71 presentation: { id: "default", title: "Default", styles: [], layers: [], legend: [] },72 }],73 };74}7576function feature(): Record<string, unknown> {77 return {78 id: "road-1", title: "Sample Road", subtitle: "", description: "", center: null, shard: "0",79 geometry: { kind: 2, parts: [{ rings: [[[0, 0], [10, 10]]] }] },80 properties: [{81 id: "11111111-1111-5111-8111-111111111111", name: "sample.extreme", kind: 2,82 value: "9223372036854775807",83 }, {84 id: "22222222-2222-5222-8222-222222222222", name: "sample.minimum", kind: 2,85 value: "-9223372036854775808",86 }],87 relationships: [], provenance: [],88 };89}