- @xenia/ui theme.js: a look = mode (light | dark | system) + palette (data-palette) + style (data-style); applyLook / getStoredLook (per device), 'system' resolved with matchMedia and followed live, so a palette is just a light and a dark token block; applyTheme kept for older callers (keeps palette and style) - tokens.css: 'Palettes' (first: Nord, light + dark, every colour and the nav rail) and 'Styles' (first: sharp: small corners, 1.5px borders, flat cards); --x-border-width used by every component and Tailwind's 'border' - contrast test: every palette in both modes (+ the nav rail); it caught the default rail's active item at 3.7:1 -> 5.5:1 - manager: the saved look applied at start (was light only); profile menu -> Look: Light / Dark / Device, Colours (Xenia, Nord), Shapes (Rounded, Sharp), applied at once and kept on this device - e2e: manager_look.mjs (every page in light and dark, no large near-white area in dark, contact sheets; 'nord-sharp' adds that look; in run-all), manager.mjs 'look:' (dark at once, kept after a reload, Device follows the device) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
2.5 KiB
JavaScript
48 lines
2.5 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { applyLook, applyTheme, getStoredLook, getStoredTheme, resolveMode, THEME_STORAGE_KEY } from '../src/theme.js'
|
|
|
|
const memory = () => { const m = new Map(); return { getItem: k => m.get(k) ?? null, setItem: (k, v) => m.set(k, v) } }
|
|
const element = () => { const a = {}; return { setAttribute: (k, v) => { a[k] = v }, getAttribute: k => a[k] ?? null, attrs: a } }
|
|
|
|
test('stored theme: light unless a known one is saved', () => {
|
|
const s = memory()
|
|
assert.equal(getStoredTheme(s), 'light')
|
|
s.setItem(THEME_STORAGE_KEY, 'neon')
|
|
assert.equal(getStoredTheme(s), 'light')
|
|
s.setItem(THEME_STORAGE_KEY, 'system')
|
|
assert.equal(getStoredTheme(s), 'system')
|
|
assert.equal(getStoredTheme({ getItem: () => { throw new Error('blocked') } }), 'light')
|
|
})
|
|
|
|
test('applyTheme sets data-theme and saves only when asked', () => {
|
|
const s = memory()
|
|
const root = element()
|
|
assert.equal(applyTheme('dark', { root, storage: s }), 'dark')
|
|
assert.equal(root.attrs['data-theme'], 'dark')
|
|
assert.equal(getStoredTheme(s), 'light')
|
|
applyTheme('dark', { root, storage: s, save: true })
|
|
assert.equal(getStoredTheme(s), 'dark')
|
|
assert.equal(applyTheme('bogus', { root, storage: s }), 'light')
|
|
})
|
|
|
|
test('a look: mode, palette and style; "system" resolves to light or dark', () => {
|
|
const s = memory()
|
|
const root = element()
|
|
assert.deepEqual(getStoredLook(s), { mode: 'light', palette: 'default', style: 'rounded' })
|
|
const got = applyLook({ mode: 'system', palette: 'nord', style: 'sharp' }, { root, storage: s, save: true, dark: () => true })
|
|
assert.deepEqual(got, { mode: 'system', palette: 'nord', style: 'sharp' })
|
|
assert.deepEqual([root.attrs['data-theme'], root.attrs['data-theme-choice'], root.attrs['data-palette'], root.attrs['data-style']], ['dark', 'system', 'nord', 'sharp'])
|
|
assert.deepEqual(getStoredLook(s), { mode: 'system', palette: 'nord', style: 'sharp' })
|
|
assert.deepEqual(applyLook({ palette: 'neon', style: 'wobbly' }, { root, storage: s }), { mode: 'light', palette: 'default', style: 'rounded' })
|
|
assert.equal(resolveMode('system', () => false), 'light')
|
|
assert.equal(resolveMode('dark'), 'dark')
|
|
})
|
|
|
|
test('applyTheme keeps the palette and the style on the page', () => {
|
|
const root = element()
|
|
applyLook({ mode: 'light', palette: 'nord', style: 'sharp' }, { root, storage: memory() })
|
|
applyTheme('dark', { root, storage: memory() })
|
|
assert.deepEqual([root.attrs['data-theme'], root.attrs['data-palette'], root.attrs['data-style']], ['dark', 'nord', 'sharp'])
|
|
})
|