-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_header.py
More file actions
60 lines (46 loc) · 1.76 KB
/
test_header.py
File metadata and controls
60 lines (46 loc) · 1.76 KB
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
import pytest
from unittest.mock import MagicMock, patch
from textual.app import App, ComposeResult
from textual.widgets import Label
from agent_chat_cli.components.header import Header
from agent_chat_cli.utils.mcp_server_status import MCPServerStatus
@pytest.fixture(autouse=True)
def reset_mcp_status():
MCPServerStatus._mcp_servers = []
MCPServerStatus._callbacks = []
yield
MCPServerStatus._mcp_servers = []
MCPServerStatus._callbacks = []
@pytest.fixture
def mock_config():
with patch("agent_chat_cli.components.header.load_config") as mock:
mock.return_value = MagicMock(
mcp_servers={"filesystem": MagicMock(), "github": MagicMock()},
agents={"researcher": MagicMock()},
)
yield mock
class HeaderApp(App):
def compose(self) -> ComposeResult:
yield Header()
class TestHeaderMCPServerStatus:
async def test_subscribes_on_mount(self, mock_config):
app = HeaderApp()
async with app.run_test():
assert len(MCPServerStatus._callbacks) == 1
async def test_updates_label_on_status_change(self, mock_config):
app = HeaderApp()
async with app.run_test():
MCPServerStatus.update(
[
{"name": "filesystem", "status": "connected"},
{"name": "github", "status": "error"},
]
)
header = app.query_one(Header)
header._handle_mcp_server_status()
label = app.query_one("#header-mcp-servers", Label)
# Label stores markup in _content or we can check via render
content = label.render()
rendered = str(content)
assert "filesystem" in rendered
assert "github" in rendered