Files
Module-Rust/client/test/mapMarkers.test.js
wtclaude 0da8f44b55 feat(rust): the live map draws monuments by label, minor labels hidden (PLAN_REDESIGNS §4, D196)
A switch per monument label, a fleet default and a per-server override, on
Admin -> Rust visibility's live map card. Substations, caves, train tunnels,
wells and the other minor labels start hidden; every other label is drawn,
so a monument a game update adds appears. GET /map leaves hidden labels out
of the answer, so the website and the app both lose them.

No schema change: rows are map.marker.<label key> in rust_settings and
rust_map_overrides. No wire change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
2026-09-29 12:10:47 -05:00

66 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ── Which monument labels a map draws (PLAN_REDESIGNS §4, D196) ───────────
//
// The admin card must agree with the server about what a switch means, or the
// page says a label is drawn while the map leaves it out. These are the ways it
// could disagree: case, the built-in list, the fleet under a server, and a
// switch set back to its default.
import test from 'node:test'
import assert from 'node:assert/strict'
import { builtIn, fleetLabels, fleetShows, markerDiff, markerKey, serverShows, setFleet, setServer } from '../src/lib/mapMarkers.js'
const MINOR = ['Substation', 'Jungle Swamp', 'Ranch']
test('a label becomes the same key the server stores', () => {
assert.equal(markerKey(' jungle Swamp '), 'jungle swamp')
assert.equal(markerKey(null), '')
})
test('the minor labels start hidden and every other label drawn', () => {
assert.equal(builtIn(MINOR, 'substation'), false)
assert.equal(builtIn(MINOR, 'something facepunch added'), true)
})
test('a server switch wins over the fleet, and the fleet over the built-in list', () => {
assert.equal(fleetShows(MINOR, {}, 'substation'), false)
assert.equal(fleetShows(MINOR, { substation: true }, 'substation'), true)
assert.equal(serverShows(MINOR, { substation: true }, {}, 'substation'), true)
assert.equal(serverShows(MINOR, { substation: true }, { substation: false }, 'substation'), false)
assert.equal(serverShows(MINOR, {}, { 'power plant': false }, 'power plant'), false)
})
test('the fleet list is every server’s labels and the minor list, each once', () => {
const labels = fleetLabels(MINOR, [
{ markerLabels: [{ key: 'substation', label: 'Substation', count: 31 }, { key: 'harbor', label: 'Harbor', count: 2 }] },
{ markerLabels: [{ key: 'substation', label: 'Substation', count: 12 }] },
{},
])
assert.deepEqual(
labels.map((l) => [l.key, l.count]),
[
['harbor', 2],
['jungle swamp', 0],
['ranch', 0],
['substation', 43],
],
)
})
test('setting the fleet back to the built-in answer clears the row instead of copying it', () => {
assert.deepEqual(setFleet(MINOR, {}, 'substation', true), { substation: true })
assert.deepEqual(setFleet(MINOR, { substation: true }, 'substation', false), {})
assert.deepEqual(setFleet(MINOR, {}, 'harbor', false), { harbor: false })
})
test('a server set to follow the fleet loses its own switch', () => {
assert.deepEqual(setServer({ substation: true }, 'substation', null), {})
assert.deepEqual(setServer({}, 'substation', false), { substation: false })
})
test('the diff sends a changed switch as its value and a removed one as null', () => {
assert.equal(markerDiff({ a: true }, { a: true }), null)
assert.deepEqual(markerDiff({ a: true, b: false }, { a: false, c: true }), { a: false, b: null, c: true })
assert.equal(markerDiff(undefined, {}), null)
})