clone

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

archive/golden-reference
atlas / frontend / test / semconv.test.mjs
semconv.test.mjs 3.3K
1// The label-policy ladder, pure and DOM-free: the reader's override2// outranks the collection's declared word, which outranks the kind's own3// default -- areas speak unasked, paths wait -- and a zone answers through4// the collection the wire stamped it with.5import assert from "node:assert/strict";6import test from "node:test";78import { featureAttributeRows, labelPolicy, labelSilenced, renderAs } from "../src/semconv.js";9import { state } from "../src/state.js";1011test("labelPolicy climbs override, collection, kind default", () => {12 state.labelOverrides.clear();13 const districts = { id: 41, kind: "area", attrs: {} };14 const hydro = { id: 42, kind: "area", attrs: { "atlas.label.policy": "quiet" } };15 const creeks = { id: 43, kind: "path", attrs: { "atlas.stroke.width_px": "10" } };1617 assert.equal(labelPolicy(null, districts), "always", "silence means always for areas");18 assert.equal(labelPolicy(null, hydro), "quiet", "the collection's curated word");19 assert.equal(labelPolicy(null, creeks), "quiet", "paths wait by default");2021 state.labelOverrides.set(42, "always");22 assert.equal(labelPolicy(null, hydro), "always", "the reader outranks the producer");23 state.labelOverrides.clear();24});2526test("a point collection's labels wait unless its curation asked for text", () => {27 state.labelOverrides.clear();28 const garages = { id: 51, kind: "point", attrs: { "atlas.render.as": "pin" } };29 const cities = { id: 52, kind: "point", attrs: { "atlas.render.as": "text" } };3031 assert.equal(labelPolicy(null, garages), "quiet", "markers wait for Z");32 assert.equal(labelPolicy(null, cities), "always", "curated text means names speak");3334 state.labelOverrides.set(52, "quiet");35 assert.equal(labelPolicy(null, cities), "quiet", "the reader can quiet the names");36 assert.ok(labelSilenced(cities), "and that silence is theirs, so Z respects it");37 assert.ok(!labelSilenced(garages), "curated quiet is merely optional, so Z reveals it");38 state.labelOverrides.clear();39});4041test("a zone answers through the collection the wire stamped it with", () => {42 state.labelOverrides.clear();43 const hydro = { id: 42, kind: "area", attrs: { "atlas.label.policy": "quiet" } };44 state.world = { collectionsById: new Map([[42, hydro]]) };45 const zone = { id: 7, collectionId: 42 };46 assert.equal(labelPolicy(zone), "quiet", "the collection speaks for its zone");47 state.labelOverrides.set(42, "always");48 assert.equal(labelPolicy(zone), "always", "the override lands by collection id");49 state.labelOverrides.clear();50 state.world = null;51});5253test("renderAs reads the declared attribute alone", () => {54 assert.equal(renderAs({ attrs: { "atlas.render.as": "text" } }), "text");55 assert.equal(renderAs({ attrs: {} }), "pin", "silence means markers");56 assert.equal(renderAs({}), "pin", "no attrs at all still means markers");57});5859test("featureAttributeRows curates, labels, and skips machinery", () => {60 const rows = featureAttributeRows({61 "atlas.hydro.huc12": "170703010101",62 "atlas.geo.lat": "44.05",63 "atlas.geo.lon": "-121.3",64 "atlas.stroke.width_px": "12",65 "atlas.label.policy": "quiet",66 });67 assert.deepEqual(rows, [{ label: "HUC-12", value: "170703010101" }],68 "only material survives: geo has rows of its own, rendering is machinery");69 assert.deepEqual(featureAttributeRows(undefined), [], "no attrs, no rows");70});