Phases 6-8 of docs/website/THEMING_AND_NAV.md. The public header, the admin sidebar and the player portal now read their override row, and /admin/navigation writes them: rename, reorder by drag, hide, and — on the admin sidebar — move a row into another existing section. The merge always runs BEFORE the role and shard-feature filters in the layouts, which are unchanged and remain the boundary. An override is presentation: it cannot introduce a route, cannot touch a `roles` or `feature` gate, and a stored `hidden: false` on a gated item shows nobody anything. The design scoped these phases as client work, but the server had no way to store a nav row: updateSettings validates and stringifies theme_visual and brand_assets and lets everything else through, so a nav object would have been written as "[object Object]" and read as absent for ever. utils/navOverrides.js mirrors utils/brandAssets.js — strict on write with the offending key named, forgiving on read. It validates shape only; whether a `to` exists is settled client-side at merge time, because the base NAV arrays are client constants and a server-side copy would be a second source of truth that drifts. The nav editor cannot be hidden — its own toggle is disabled, the write path drops `hidden` on that one `to`, and AdminLayout strips it again before merging, which also covers a row edited straight in the database. Orders are written only when the sequence actually differs from the code's, and the comparison is restricted to the rows the editing admin can see, so renaming one item does not pin the position of every other one and a role- or feature-gated item missing from their palette is not mistaken for a reorder. Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
import { parseJsonSetting } from '../src/lib/settingsJson.js'
|
|
|
|
// The client counterpart to the server's parseJsonSetting. The property that
|
|
// matters is the fail-safe one: anything unusable reads as **absent**, so the
|
|
// consumer falls back to its coded default rather than rendering an error or a
|
|
// half-applied object (THEMING_AND_NAV.md §4.4).
|
|
|
|
test('absent, empty and malformed values read as absent', () => {
|
|
for (const bad of [undefined, null, '', '{', 'not json', 4, {}, []]) {
|
|
assert.equal(parseJsonSetting(bad), null, `${JSON.stringify(bad)} should read as absent`)
|
|
}
|
|
})
|
|
|
|
test('valid JSON that is not a plain object reads as absent', () => {
|
|
// A stored `null`, number, string or array is as unusable to every consumer of
|
|
// these keys as a syntax error is.
|
|
for (const bad of ['null', '4', '"x"', '[]', '[{"to":"/"}]', 'true']) {
|
|
assert.equal(parseJsonSetting(bad), null, `${bad} should read as absent`)
|
|
}
|
|
})
|
|
|
|
test('a well-formed object is returned as parsed', () => {
|
|
assert.deepEqual(parseJsonSetting('{"/site/news":{"order":2}}'), { '/site/news': { order: 2 } })
|
|
assert.deepEqual(parseJsonSetting('{}'), {})
|
|
})
|