Skip to content

Commit fc509a9

Browse files
committed
test: cover hiding the visualizer when visualizer@v1 is inactive
1 parent e48ef26 commit fc509a9

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

‎tests/tui/test_role_negotiation.py‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
from types import SimpleNamespace
5+
6+
from aiosendspin.models.core import ServerHelloPayload
7+
from aiosendspin.models.types import ConnectionReason, Roles
8+
9+
from sendspin.settings import ClientSettings
10+
from sendspin.tui.app import AppArgs, SendspinApp
11+
12+
13+
class _FakeUI:
14+
def __init__(self) -> None:
15+
self.visualizer_enabled_calls: list[bool] = []
16+
17+
def set_visualizer_enabled(self, enabled: bool) -> None:
18+
self.visualizer_enabled_calls.append(enabled)
19+
20+
21+
def _make_app(tmp_path: Path) -> SendspinApp:
22+
args = AppArgs(
23+
audio_device=SimpleNamespace(index=0, name="Fake Device"),
24+
client_id="test-client",
25+
client_name="Test Client",
26+
settings=ClientSettings(_settings_file=tmp_path / "settings.json"),
27+
use_mpris=False,
28+
)
29+
return SendspinApp(args)
30+
31+
32+
def _payload(active_roles: list[str]) -> ServerHelloPayload:
33+
return ServerHelloPayload(
34+
server_id="srv",
35+
name="srv",
36+
version=1,
37+
active_roles=active_roles,
38+
connection_reason=ConnectionReason.DISCOVERY,
39+
)
40+
41+
42+
def test_server_hello_without_visualizer_role_hides_panel(tmp_path: Path) -> None:
43+
app = _make_app(tmp_path)
44+
app._visualizer_enabled = True
45+
app._ui = _FakeUI()
46+
47+
app._handle_server_hello(_payload(active_roles=["player@v1", "controller@v1"]))
48+
49+
assert app._ui.visualizer_enabled_calls == [False]
50+
51+
52+
def test_server_hello_with_visualizer_role_leaves_panel(tmp_path: Path) -> None:
53+
app = _make_app(tmp_path)
54+
app._visualizer_enabled = True
55+
app._ui = _FakeUI()
56+
57+
app._handle_server_hello(_payload(active_roles=[Roles.VISUALIZER.value, "player@v1"]))
58+
59+
assert app._ui.visualizer_enabled_calls == []
60+
61+
62+
def test_server_hello_ignored_when_visualizer_disabled(tmp_path: Path) -> None:
63+
app = _make_app(tmp_path)
64+
app._visualizer_enabled = False
65+
app._ui = _FakeUI()
66+
67+
app._handle_server_hello(_payload(active_roles=["player@v1"]))
68+
69+
assert app._ui.visualizer_enabled_calls == []

0 commit comments

Comments
 (0)