-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_slash_command_menu.py
More file actions
101 lines (72 loc) · 2.9 KB
/
test_slash_command_menu.py
File metadata and controls
101 lines (72 loc) · 2.9 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
import pytest
from unittest.mock import AsyncMock, MagicMock
from textual.app import App, ComposeResult
from textual.widgets import OptionList
from agent_chat_cli.components.slash_command_menu import SlashCommandMenu
class SlashCommandMenuApp(App):
def __init__(self):
super().__init__()
self.mock_actions = MagicMock()
self.mock_actions.quit = MagicMock()
self.mock_actions.clear = AsyncMock()
self.mock_actions.new = AsyncMock()
self.mock_actions.save = AsyncMock()
def compose(self) -> ComposeResult:
yield SlashCommandMenu(actions=self.mock_actions)
class TestSlashCommandMenuVisibility:
@pytest.fixture
def app(self):
return SlashCommandMenuApp()
async def test_hidden_by_default(self, app):
async with app.run_test():
menu = app.query_one(SlashCommandMenu)
assert menu.is_visible is False
async def test_show_makes_visible(self, app):
async with app.run_test():
menu = app.query_one(SlashCommandMenu)
menu.show()
assert menu.is_visible is True
async def test_hide_makes_invisible(self, app):
async with app.run_test():
menu = app.query_one(SlashCommandMenu)
menu.show()
menu.hide()
assert menu.is_visible is False
async def test_show_highlights_first_option(self, app):
async with app.run_test():
menu = app.query_one(SlashCommandMenu)
menu.show()
option_list = menu.query_one(OptionList)
assert option_list.highlighted == 0
class TestSlashCommandMenuSelection:
@pytest.fixture
def app(self):
return SlashCommandMenuApp()
async def test_new_command_calls_new(self, app):
async with app.run_test() as pilot:
menu = app.query_one(SlashCommandMenu)
menu.show()
await pilot.press("enter")
app.mock_actions.new.assert_called_once()
async def test_clear_command_calls_clear(self, app):
async with app.run_test() as pilot:
menu = app.query_one(SlashCommandMenu)
menu.show()
await pilot.press("down")
await pilot.press("enter")
app.mock_actions.clear.assert_called_once()
async def test_exit_command_calls_quit(self, app):
async with app.run_test() as pilot:
menu = app.query_one(SlashCommandMenu)
menu.show()
await pilot.press("down")
await pilot.press("down")
await pilot.press("down")
await pilot.press("enter")
app.mock_actions.quit.assert_called_once()
async def test_selection_hides_menu(self, app):
async with app.run_test() as pilot:
menu = app.query_one(SlashCommandMenu)
menu.show()
await pilot.press("enter")
assert menu.is_visible is False