// Theme engine v3, step 9: the bar's label mode is measured, with hysteresis. import { test } from 'node:test'; import assert from 'node:assert/strict'; import { barMode } from '../src/themeBar.ts'; const twelve = Array.from({ length: 12 }, (_, i) => ({ labelWidth: [36, 50, 84, 34, 30, 54, 48, 92, 54, 44, 64, 34][i]!, fixed: 16 + 24 })); const need = twelve.reduce((s, it) => s + it.labelWidth + it.fixed, 0) + 2 * 11; test('whole labels when they fit, icons when they do not; never a cut label', () => { assert.equal(barMode(twelve, need, 2, null), 'labels'); assert.equal(barMode(twelve, need - 1, 2, null), 'icons'); }); test('hysteresis: icons mode needs 16px more room to switch back, so the bar does not flap', () => { assert.equal(barMode(twelve, need + 10, 2, 'icons'), 'icons'); assert.equal(barMode(twelve, need + 16, 2, 'icons'), 'labels'); assert.equal(barMode(twelve, need + 10, 2, 'labels'), 'labels'); }); test('items without labels (X drew icons only) are always "labels" mode: nothing to hide', () => { assert.equal(barMode(twelve.map(it => ({ ...it, labelWidth: 0 })), 100, 2, null), 'labels'); });