// brightness.test.js — node test for the pure brightness module. Prints ALL PASS. var assert = require('assert'); var B = require('./brightness.js'); // clampLevel: range + null/NaN safety assert.strictEqual(B.clampLevel(-1), 0); assert.strictEqual(B.clampLevel(2), 1); assert.strictEqual(B.clampLevel(0.5), 0.5); assert.strictEqual(B.clampLevel(null), 0); assert.strictEqual(B.clampLevel(undefined), 0); assert.strictEqual(B.clampLevel("0.3"), 0.3); // levelPercent: rounded integer percent assert.strictEqual(B.levelPercent(0), 0); assert.strictEqual(B.levelPercent(0.5), 50); assert.strictEqual(B.levelPercent(1), 100); assert.strictEqual(B.levelPercent(2), 100); assert.strictEqual(B.levelPercent(0.014), 1); // levelRole: band boundaries (<=0.15 minor, >=0.85 warning, else accent) assert.strictEqual(B.levelRole(0.10), "ui.minor"); assert.strictEqual(B.levelRole(0.15), "ui.minor"); // inclusive low boundary assert.strictEqual(B.levelRole(0.16), "ui.accent"); assert.strictEqual(B.levelRole(0.5), "ui.accent"); assert.strictEqual(B.levelRole(0.84), "ui.accent"); assert.strictEqual(B.levelRole(0.85), "warning"); // inclusive high boundary assert.strictEqual(B.levelRole(1), "warning"); assert.strictEqual(B.levelRole(null), "ui.minor"); // 0 -> dim // displayRows: no fake built-in; unresolved external outputs get issue badges assert.deepStrictEqual(B.displayRows({ present: false, level: 0.55 }, { "DP-1": { model: "27E6QC" }, "DP-2": { model: "27E6QC" } }, {}), [ { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" }, { id: "ddc:DP-2", name: "DP-2 · 27E6QC", kind: "ddc", level: 0, controllable: false, issue: "DDC?" } ]); assert.deepStrictEqual(B.displayRows({ present: true, level: 0.55 }, {}, {}), [ { id: "backlight", name: "built-in", kind: "backlight", level: 0.55, controllable: true, issue: "" } ]); assert.deepStrictEqual(B.displayRows({ present: true, level: 0.75 }, [ { name: "DP-1", model: "27E6QC" } ], { "DP-1": { level: 0.25, controllable: true } }), [ { id: "backlight", name: "built-in", kind: "backlight", level: 0.75, controllable: true, issue: "" }, { id: "ddc:DP-1", name: "DP-1 · 27E6QC", kind: "ddc", level: 0.25, controllable: true, issue: "" } ]); // Internal panels never become DDC candidates, even without an available backlight. for (const connector of ['LVDS-1', 'eDP-1', 'DSI-1', 'eDP-2']) { const outputs = [{ name: connector, model: 'internal panel' }]; const ddc = { [connector]: { controllable: true, level: 0.25 } }; assert.deepStrictEqual(B.displayRows({ present: true, level: 0.5 }, outputs, ddc), [ { id: 'backlight', name: 'built-in', kind: 'backlight', level: 0.5, controllable: true, issue: '' } ]); assert.deepStrictEqual(B.displayRows({ present: false }, outputs, ddc), []); } // Docked laptops retain external DDC candidates in either output representation. const dockedOutputs = { 'LVDS-1': { model: 'internal' }, 'HDMI-A-1': { model: 'external' } }; const dockedRows = B.displayRows({ present: true, level: 0.5 }, dockedOutputs, {}); assert.deepStrictEqual(dockedRows.map(row => row.id), ['backlight', 'ddc:HDMI-A-1']); assert.strictEqual(dockedRows[1].issue, 'DDC?'); // globalState: none/synced/mixed from controllable displays only assert.deepStrictEqual(B.globalState([]), { mode: "none", level: 0, levels: [] }); assert.deepStrictEqual(B.globalState([{ controllable: false, level: 0.2 }]), { mode: "none", level: 0, levels: [] }); assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.5 }, { controllable: true, level: 0.5 }]), { mode: "synced", level: 0.5, levels: [0.5, 0.5] }); assert.deepStrictEqual(B.globalState([{ controllable: true, level: 0.75 }, { controllable: true, level: 0.25 }]), { mode: "mixed", level: 0.5, levels: [0.75, 0.25] }); console.log('brightness.test.js: ALL PASS');