// deck-it - check for static/dashboard.js: `node tests/test_dashboard.mjs` // Copyright (C) 2026 Danilo M. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import assert from "node:assert/strict"; import { area, push, spendParts, batteryGlyph, HISTORY } from "../static/dashboard.js"; import { busy as printing } from "../static/modules/k1c.js"; import { busy as building } from "../static/modules/sbbuilder.js"; import { busy as live } from "../static/modules/obs.js"; // push keeps the last HISTORY samples const h = []; for (let i = 0; i < HISTORY + 5; i++) push(h, i); assert.equal(h.length, HISTORY); assert.equal(h[0], 5); // area: empty without samples; closed path from the bottom edge to the right edge assert.equal(area([], 10), ""); const d = area([0, 10], 10); assert.match(d, /^M[\d.]+,100 /); assert.match(d, / L120,100 Z$/); assert.ok(d.includes(",12"), "the max sample sits at 12% from the top"); // spendParts: top 3 paid models, then "other" with the rest const models = [5, 4, 3, 2, 1, 0].map((c, i) => ({ model: `m${i}`, cost: c })); assert.deepEqual(spendParts(models).map((m) => [m.model, m.cost]), [["m0", 5], ["m1", 4], ["m2", 3], ["other", 3]]); assert.deepEqual(spendParts([{ model: "free", cost: 0 }]), []); // batteryGlyph: level steps, bolt while charging or full assert.equal(batteryGlyph({ level: 3, status: "discharging" }), ""); assert.equal(batteryGlyph({ level: 50, status: "discharging" }), ""); assert.equal(batteryGlyph({ level: 100, status: "discharging" }), ""); assert.equal(batteryGlyph({ level: 40, status: "charging" }), "\u{f0084}"); // busy checks assert.equal(printing({ state: "printing" }), true); assert.equal(printing({ state: "standby" }), false); assert.equal(printing({ offline: true }), false); assert.equal(building({ jobs: [{ status: "running" }] }), true); assert.equal(building({ jobs: [{ status: "done" }] }), false); assert.equal(live({ connected: true, recording: true }), true); assert.equal(live({ connected: true, recording: false, streaming: false }), false);