|
5 | 5 | from textual.widgets import TextArea |
6 | 6 |
|
7 | 7 | from agent_chat_cli.app import AgentChatCLIApp |
| 8 | +from agent_chat_cli.components.slash_command_menu import SlashCommandMenu |
8 | 9 | from agent_chat_cli.components.thinking_indicator import ThinkingIndicator |
9 | 10 | from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt |
10 | 11 | from agent_chat_cli.components.user_input import UserInput |
@@ -161,3 +162,69 @@ async def test_escape_triggers_interrupt_when_menu_not_visible( |
161 | 162 | await pilot.press("escape") |
162 | 163 |
|
163 | 164 | assert app.ui_state.interrupting is True |
| 165 | + |
| 166 | + |
| 167 | +class TestSlashCommandMenuBehavior: |
| 168 | + async def test_slash_opens_menu(self, mock_agent_loop, mock_config): |
| 169 | + app = AgentChatCLIApp() |
| 170 | + async with app.run_test() as pilot: |
| 171 | + await pilot.press("/") |
| 172 | + |
| 173 | + menu = app.query_one(SlashCommandMenu) |
| 174 | + assert menu.is_visible is True |
| 175 | + |
| 176 | + async def test_escape_closes_menu_and_clears_input( |
| 177 | + self, mock_agent_loop, mock_config |
| 178 | + ): |
| 179 | + app = AgentChatCLIApp() |
| 180 | + async with app.run_test() as pilot: |
| 181 | + await pilot.press("/") |
| 182 | + await pilot.press("c") |
| 183 | + await pilot.press("escape") |
| 184 | + |
| 185 | + menu = app.query_one(SlashCommandMenu) |
| 186 | + text_area = app.query_one(UserInput).query_one(TextArea) |
| 187 | + |
| 188 | + assert menu.is_visible is False |
| 189 | + assert text_area.text == "" |
| 190 | + |
| 191 | + async def test_typing_filters_menu_and_shows_in_textarea( |
| 192 | + self, mock_agent_loop, mock_config |
| 193 | + ): |
| 194 | + app = AgentChatCLIApp() |
| 195 | + async with app.run_test() as pilot: |
| 196 | + await pilot.press("/") |
| 197 | + await pilot.press("c", "l") |
| 198 | + |
| 199 | + menu = app.query_one(SlashCommandMenu) |
| 200 | + text_area = app.query_one(UserInput).query_one(TextArea) |
| 201 | + |
| 202 | + assert menu.filter_text == "cl" |
| 203 | + assert text_area.text == "cl" |
| 204 | + |
| 205 | + async def test_backspace_removes_filter_character( |
| 206 | + self, mock_agent_loop, mock_config |
| 207 | + ): |
| 208 | + app = AgentChatCLIApp() |
| 209 | + async with app.run_test() as pilot: |
| 210 | + await pilot.press("/") |
| 211 | + await pilot.press("c", "l") |
| 212 | + await pilot.press("backspace") |
| 213 | + |
| 214 | + menu = app.query_one(SlashCommandMenu) |
| 215 | + text_area = app.query_one(UserInput).query_one(TextArea) |
| 216 | + |
| 217 | + assert menu.filter_text == "c" |
| 218 | + assert text_area.text == "c" |
| 219 | + assert menu.is_visible is True |
| 220 | + |
| 221 | + async def test_backspace_on_empty_filter_closes_menu( |
| 222 | + self, mock_agent_loop, mock_config |
| 223 | + ): |
| 224 | + app = AgentChatCLIApp() |
| 225 | + async with app.run_test() as pilot: |
| 226 | + await pilot.press("/") |
| 227 | + await pilot.press("backspace") |
| 228 | + |
| 229 | + menu = app.query_one(SlashCommandMenu) |
| 230 | + assert menu.is_visible is False |
0 commit comments