1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// deck-it - check for static/dashboard.js: `node tests/test_dashboard.mjs`
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// 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, line, push, spendParts, batteryGlyph, HISTORY } from "../static/dashboard.js";
import { busy as printing } from "../static/modules/k1c.js";
import { busy as building, planRows } 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");
// line: the same samples, open, so no bottom or side edge is stroked
assert.equal(line([], 10), "");
const l = line([0, 10], 10);
assert.match(l, /^M[\d.]+,100 L120,12$/);
assert.ok(d.includes(l.slice(1)), "area follows line");
// 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);
// planRows: results first, then the package building, the rest waiting
assert.deepEqual(planRows({ plan: ["a/x", "b/y", "c/z"],
progress: { results: { "a/x": "failed" }, current: "b/y" } }).map((r) => r.status),
["failed", "building", "waiting"]);
assert.deepEqual(planRows(undefined), []);
|