diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_dashboard.mjs | 55 | ||||
| -rw-r--r-- | tests/test_frontend.py | 34 |
2 files changed, 73 insertions, 16 deletions
diff --git a/tests/test_dashboard.mjs b/tests/test_dashboard.mjs new file mode 100644 index 0000000..2fc19eb --- /dev/null +++ b/tests/test_dashboard.mjs @@ -0,0 +1,55 @@ +// 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, 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); diff --git a/tests/test_frontend.py b/tests/test_frontend.py index 635b57a..42126b8 100644 --- a/tests/test_frontend.py +++ b/tests/test_frontend.py @@ -69,8 +69,9 @@ class Frontend(unittest.TestCase): status, body = self.get("/") self.assertEqual(status, 200) text = body.decode() - for asset in ("app.js", "deck.css", "vendor/gridstack/gridstack-all.js"): + for asset in ("app.js", "deck.css"): self.assertIn(asset, text) + self.assertNotIn("gridstack", text) def test_pwa_manifest(self): self.assertIn(b'rel="manifest"', self.get("/")[1]) @@ -80,9 +81,8 @@ class Frontend(unittest.TestCase): for size in (192, 512): self.assertEqual(self.get(f"/icon-{size}.png")[0], 200) - def test_vendor_assets_served(self): - for path in ("/vendor/gridstack/gridstack-all.js", "/vendor/gridstack/gridstack.min.css"): - self.assertEqual(self.get(path)[0], 200, path) + def test_vendor_gridstack_is_gone(self): + self.assertEqual(self.get("/vendor/gridstack/gridstack-all.js")[0], 404) def test_css_uses_udt_vars(self): status, body = self.get("/deck.css") @@ -96,16 +96,19 @@ class Frontend(unittest.TestCase): for part in ("export default", "mount", "update"): self.assertIn(part, text, name) - def test_panel_for_every_module(self): - from deckit.modules import build - names = [m["name"] for m in build({}).names()] - self.assertIn("stats", names) - for name in names: + def test_panels(self): + # Tabs and the music card have panels; stats, tablet, llm and actions + # are drawn by dashboard.js; k1c, sbbuilder and obs give it a slot. + for name in ("music", "k1c", "obs", "windows", "assistant"): self.assert_panel(name) + for name in ("k1c", "sbbuilder", "obs"): + text = self.get(f"/modules/{name}.js")[1].decode() + self.assertIn("export const busy", text, name) + self.assertIn("export function slot", text, name) + self.assertEqual(self.get("/dashboard.js")[0], 200) def test_panels_have_their_scoped_wrapper(self): self.assertIn(b'class="music"', self.get("/modules/music.js")[1]) - self.assertIn(b'class="sbb"', self.get("/modules/sbbuilder.js")[1]) def test_tabbed_shell(self): self.assertIn(b'id="tabs"', self.get("/")[1]) @@ -117,12 +120,11 @@ class Frontend(unittest.TestCase): self.assertIn(b'tab: "OBS"', self.get("/modules/obs.js")[1]) self.assertIn(b'tab: "Windows"', self.get("/modules/windows.js")[1]) - def test_layout_is_browser_local(self): - status, body = self.get("/app.js") - self.assertEqual(status, 200) - text = body.decode() - for part in ("GridStack", "localStorage", "deckit.layout", "gs-id"): - self.assertIn(part, text) + def test_dashboard_is_one_fixed_screen(self): + text = self.get("/app.js")[1].decode() + self.assertIn("dashboard.js", text) + for gone in ("GridStack", "deckit.layout", "deckit.folded"): + self.assertNotIn(gone, text) if __name__ == "__main__": |
