-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ui_state.py
More file actions
165 lines (127 loc) · 5.54 KB
/
test_ui_state.py
File metadata and controls
165 lines (127 loc) · 5.54 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from textual.widgets import TextArea
from agent_chat_cli.app import AgentChatCLIApp
from agent_chat_cli.components.thinking_indicator import ThinkingIndicator
from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt
from agent_chat_cli.components.user_input import UserInput
@pytest.fixture
def mock_agent_loop():
with patch("agent_chat_cli.app.AgentLoop") as mock:
instance = MagicMock()
instance.start = AsyncMock()
instance.query_queue = MagicMock()
mock.return_value = instance
yield instance
@pytest.fixture
def mock_config():
with patch("agent_chat_cli.components.header.load_config") as mock:
mock.return_value = MagicMock(mcp_servers={}, agents={})
yield mock
class TestUIStateInterrupting:
async def test_initially_false(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
assert app.ui_state.interrupting is False
async def test_set_interrupting(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.set_interrupting(True)
assert app.ui_state.interrupting is True
app.ui_state.set_interrupting(False)
assert app.ui_state.interrupting is False
class TestUIStateThinking:
async def test_start_thinking_shows_indicator(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
indicator = app.query_one(ThinkingIndicator)
assert indicator.is_thinking is True
async def test_start_thinking_disables_cursor_blink(
self, mock_agent_loop, mock_config
):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
text_area = app.query_one(TextArea)
assert text_area.cursor_blink is False
async def test_stop_thinking_hides_indicator(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
app.ui_state.stop_thinking()
indicator = app.query_one(ThinkingIndicator)
assert indicator.is_thinking is False
async def test_stop_thinking_restores_cursor_blink(
self, mock_agent_loop, mock_config
):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
app.ui_state.stop_thinking(show_cursor=True)
text_area = app.query_one(TextArea)
assert text_area.cursor_blink is True
async def test_stop_thinking_can_skip_cursor_restore(
self, mock_agent_loop, mock_config
):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
app.ui_state.stop_thinking(show_cursor=False)
text_area = app.query_one(TextArea)
assert text_area.cursor_blink is False
class TestUIStatePermissionPrompt:
async def test_show_permission_prompt(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.show_permission_prompt(
tool_name="test_tool",
tool_input={"key": "value"},
)
prompt = app.query_one(ToolPermissionPrompt)
assert prompt.is_visible is True
assert prompt.tool_name == "test_tool"
assert prompt.tool_input == {"key": "value"}
async def test_show_permission_prompt_hides_user_input(
self, mock_agent_loop, mock_config
):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.show_permission_prompt(tool_name="test", tool_input={})
user_input = app.query_one(UserInput)
assert user_input.display is False
async def test_show_permission_prompt_stops_thinking(
self, mock_agent_loop, mock_config
):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.start_thinking()
app.ui_state.show_permission_prompt(tool_name="test", tool_input={})
indicator = app.query_one(ThinkingIndicator)
assert indicator.is_thinking is False
async def test_hide_permission_prompt(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
app.ui_state.show_permission_prompt(tool_name="test", tool_input={})
app.ui_state.hide_permission_prompt()
prompt = app.query_one(ToolPermissionPrompt)
user_input = app.query_one(UserInput)
assert prompt.is_visible is False
assert user_input.display is True
class TestUIStateInput:
async def test_focus_input(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
user_input = app.query_one(UserInput)
text_area = user_input.query_one(TextArea)
text_area.blur()
app.ui_state.focus_input()
assert text_area.has_focus is True
async def test_clear_input(self, mock_agent_loop, mock_config):
app = AgentChatCLIApp()
async with app.run_test():
user_input = app.query_one(UserInput)
text_area = user_input.query_one(TextArea)
text_area.insert("some text")
app.ui_state.clear_input()
assert text_area.text == ""