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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# deck-it - tests for frontend
# 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 sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import http.client
import json
import os
import socket
import tempfile
import threading
import unittest
import deckit.module as mod
import deckit.server as srv
class UnixConnection(http.client.HTTPConnection):
def __init__(self, path):
super().__init__("localhost")
self.path = path
def connect(self):
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(self.path)
class Frontend(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.dir = tempfile.TemporaryDirectory()
cls.sock = os.path.join(cls.dir.name, "http.sock")
srv.TOKEN = "t"
srv.REGISTRY = mod.Registry([])
cls.server = srv.UnixHTTPServer(cls.sock, srv.Handler)
threading.Thread(target=cls.server.serve_forever, daemon=True).start()
@classmethod
def tearDownClass(cls):
cls.server.shutdown()
cls.server.server_close()
cls.dir.cleanup()
def get(self, path):
conn = UnixConnection(self.sock)
conn.request("GET", path, headers={"Host": "127.0.0.1:8765"})
r = conn.getresponse()
data = r.read()
conn.close()
return r.status, data
def test_page_references_assets(self):
status, body = self.get("/")
self.assertEqual(status, 200)
text = body.decode()
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])
manifest = json.loads(self.get("/manifest.json")[1])
self.assertEqual(manifest["display"], "fullscreen")
self.assertEqual(manifest["start_url"], "./")
for size in (192, 512):
self.assertEqual(self.get(f"/icon-{size}.png")[0], 200)
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")
self.assertEqual(status, 200)
self.assertIn(b"--udt-", body)
def assert_panel(self, name):
status, body = self.get(f"/modules/{name}.js")
self.assertEqual(status, 200, name)
text = body.decode()
for part in ("export default", "mount", "update"):
self.assertIn(part, text, name)
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])
def test_tabbed_shell(self):
self.assertIn(b'id="tabs"', self.get("/")[1])
self.assertIn(b'id="tab-body"', self.get("/")[1])
self.assertIn(b"stepTab", self.get("/app.js")[1])
app = self.get("/app.js")[1]
for part in (b"deckit.tab", b"ensureTab", b"showTab"):
self.assertIn(part, app)
self.assertIn(b'tab: "OBS"', self.get("/modules/obs.js")[1])
self.assertIn(b'tab: "Windows"', self.get("/modules/windows.js")[1])
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__":
unittest.main()
|