okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0213-qafix into f-0213-int64b48c0d0

main
3.8 KiB91 linesraw
1"""F13 (QATUI 0213): `?` in the monitor shows the key list on the Overview as on the other views, and it stays up past the next poll."""
2
3from __future__ import annotations
4
5import asyncio
6import sys
7import unittest
8from pathlib import Path
9
10sys.path.insert(0, str(Path(__file__).resolve().parent))
11
12from test_overview import Source, metrics  # noqa: E402
13from strata_cli.monitor import MonitorApp  # noqa: E402
14
15KEYS = "Space freeze  r refresh  t theme  q detach"
16
17
18def last_line(app) -> str:
19    return [s.text for s in app.screen._compositor.render_strips()][-1]
20
21
22class Help(unittest.TestCase):
23    def _run(self, view_key: str):
24        async def go():
25            # a one-second poll in real use; 0.2 s here so several polls pass while the help is up
26            app = MonitorApp(Source(metrics("generating")), None, interval=0.2)
27            async with app.run_test(size=(140, 36)) as pilot:
28                await pilot.pause(0.5)
29                await pilot.press(view_key)
30                await pilot.pause(0.3)
31                self.assertNotIn("Space freeze  r refresh", last_line(app))
32                await pilot.press("question_mark")
33                await pilot.pause(1.0)               # several polls later
34                self.assertIn(KEYS, last_line(app))
35                await pilot.press("question_mark")   # again: closes it
36                await pilot.pause(0.3)
37                self.assertNotIn("Space freeze  r refresh", last_line(app))
38                await pilot.press("question_mark")
39                await pilot.pause(0.3)
40                self.assertIn(KEYS, last_line(app))
41                await pilot.press("escape")
42                await pilot.pause(0.3)
43                self.assertNotIn("Space freeze  r refresh", last_line(app))
44        asyncio.run(go())
45
46    def test_overview(self):
47        self._run("1")
48
49    def test_serving_view(self):
50        self._run("2")
51
52    def test_changing_view_closes_it(self):
53        async def go():
54            app = MonitorApp(Source(metrics("generating")), None, interval=0.2)
55            async with app.run_test(size=(140, 36)) as pilot:
56                await pilot.pause(0.5)
57                await pilot.press("question_mark")
58                await pilot.pause(0.3)
59                self.assertIn(KEYS, last_line(app))
60                await pilot.press("3")
61                await pilot.pause(0.3)
62                self.assertNotIn("Space freeze  r refresh", last_line(app))
63        asyncio.run(go())
64
65    def test_narrow_terminals_wrap_the_list_at_the_keys_and_show_every_key(self):
66        async def go(width, height):
67            app = MonitorApp(Source(metrics("generating")), None, interval=0.2)
68            async with app.run_test(size=(width, height)) as pilot:
69                await pilot.pause(0.5)
70                for key in ("1", "2"):
71                    await pilot.press(key)
72                    await pilot.pause(0.3)
73                    await pilot.press("question_mark")
74                    await pilot.pause(0.8)               # polls pass; it stays
75                    rows = [s.text.rstrip() for s in app.screen._compositor.render_strips()]
76                    shown = "\n".join(rows)
77                    items = app._help_line().split("  ")
78                    self.assertGreater(len(items), 5)
79                    for item in items:
80                        self.assertIn(item, shown, f"{width}x{height} view {key}: {item!r} cut off")
81                    self.assertTrue(all(len(r) <= width for r in rows))
82                    self.assertGreater(len(app._help_wrapped(width)), 1, "narrower than the line: it wraps")
83                    await pilot.press("question_mark")
84                    await pilot.pause(0.3)
85                    self.assertIn("Read only", last_line(app))   # back to the one-line message
86        for size in ((80, 24), (60, 16)):
87            asyncio.run(go(*size))
88
89
90if __name__ == "__main__":
91    unittest.main()