mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-10 13:31:38 +00:00
54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
/**
|
|
* Unit tests for the pure zoom helpers: clamping garbage input, the
|
|
* percent <-> zoom-level conversion the settings UI relies on, and the
|
|
* roundtrip stability of the preset percentages.
|
|
*/
|
|
|
|
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const { ZOOM_STORAGE_KEY, clampZoomLevel, percentToZoomLevel, zoomLevelToPercent } = require('./zoom.cjs')
|
|
|
|
test('storage key stays stable so persisted zoom survives upgrades', () => {
|
|
assert.equal(ZOOM_STORAGE_KEY, 'hermes:desktop:zoomLevel')
|
|
})
|
|
|
|
test('clampZoomLevel rejects garbage and enforces bounds', () => {
|
|
assert.equal(clampZoomLevel(NaN), 0)
|
|
assert.equal(clampZoomLevel(Infinity), 0)
|
|
assert.equal(clampZoomLevel(undefined), 0)
|
|
assert.equal(clampZoomLevel('2'), 0)
|
|
assert.equal(clampZoomLevel(0.3), 0.3)
|
|
assert.equal(clampZoomLevel(-42), -9)
|
|
assert.equal(clampZoomLevel(42), 9)
|
|
})
|
|
|
|
test('level 0 is exactly 100 percent', () => {
|
|
assert.equal(zoomLevelToPercent(0), 100)
|
|
assert.equal(percentToZoomLevel(100), 0)
|
|
})
|
|
|
|
test('percentToZoomLevel rejects garbage', () => {
|
|
assert.equal(percentToZoomLevel(NaN), 0)
|
|
assert.equal(percentToZoomLevel(0), 0)
|
|
assert.equal(percentToZoomLevel(-50), 0)
|
|
assert.equal(percentToZoomLevel(undefined), 0)
|
|
})
|
|
|
|
test('preset percentages roundtrip within rounding', () => {
|
|
for (const percent of [90, 100, 110, 125, 150, 175]) {
|
|
assert.equal(zoomLevelToPercent(percentToZoomLevel(percent)), percent)
|
|
}
|
|
})
|
|
|
|
test('conversion is monotonic across the preset range', () => {
|
|
const levels = [90, 100, 110, 125, 150, 175].map(percentToZoomLevel)
|
|
for (let i = 1; i < levels.length; i++) {
|
|
assert.ok(levels[i] > levels[i - 1])
|
|
}
|
|
})
|
|
|
|
test('extreme percentages clamp to the level bounds', () => {
|
|
assert.equal(percentToZoomLevel(1), -9)
|
|
assert.equal(percentToZoomLevel(1_000_000), 9)
|
|
})
|