// ── 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) })