|
| 1 | +import pytest |
| 2 | +from unittest.mock import AsyncMock, MagicMock |
| 3 | + |
| 4 | +from textual.app import App, ComposeResult |
| 5 | +from textual.widgets import OptionList |
| 6 | + |
| 7 | +from agent_chat_cli.components.model_selection_menu import ModelSelectionMenu |
| 8 | + |
| 9 | + |
| 10 | +class ModelSelectionMenuApp(App): |
| 11 | + def __init__(self): |
| 12 | + super().__init__() |
| 13 | + self.mock_actions = MagicMock() |
| 14 | + self.mock_actions.change_model = AsyncMock() |
| 15 | + |
| 16 | + def compose(self) -> ComposeResult: |
| 17 | + yield ModelSelectionMenu(actions=self.mock_actions) |
| 18 | + |
| 19 | + |
| 20 | +class TestModelSelectionMenuVisibility: |
| 21 | + @pytest.fixture |
| 22 | + def app(self): |
| 23 | + return ModelSelectionMenuApp() |
| 24 | + |
| 25 | + async def test_hidden_by_default(self, app): |
| 26 | + async with app.run_test(): |
| 27 | + menu = app.query_one(ModelSelectionMenu) |
| 28 | + |
| 29 | + assert menu.is_visible is False |
| 30 | + |
| 31 | + async def test_show_makes_visible(self, app): |
| 32 | + async with app.run_test(): |
| 33 | + menu = app.query_one(ModelSelectionMenu) |
| 34 | + menu.show() |
| 35 | + |
| 36 | + assert menu.is_visible is True |
| 37 | + |
| 38 | + async def test_hide_makes_invisible(self, app): |
| 39 | + async with app.run_test(): |
| 40 | + menu = app.query_one(ModelSelectionMenu) |
| 41 | + menu.show() |
| 42 | + menu.hide() |
| 43 | + |
| 44 | + assert menu.is_visible is False |
| 45 | + |
| 46 | + async def test_show_highlights_first_option(self, app): |
| 47 | + async with app.run_test(): |
| 48 | + menu = app.query_one(ModelSelectionMenu) |
| 49 | + menu.show() |
| 50 | + |
| 51 | + option_list = menu.query_one(OptionList) |
| 52 | + assert option_list.highlighted == 0 |
| 53 | + |
| 54 | + |
| 55 | +class TestModelSelectionMenuSelection: |
| 56 | + @pytest.fixture |
| 57 | + def app(self): |
| 58 | + return ModelSelectionMenuApp() |
| 59 | + |
| 60 | + async def test_sonnet_command_calls_change_model(self, app): |
| 61 | + async with app.run_test() as pilot: |
| 62 | + menu = app.query_one(ModelSelectionMenu) |
| 63 | + menu.show() |
| 64 | + |
| 65 | + await pilot.press("enter") |
| 66 | + |
| 67 | + app.mock_actions.change_model.assert_called_once_with("sonnet") |
| 68 | + |
| 69 | + async def test_haiku_command_calls_change_model(self, app): |
| 70 | + async with app.run_test() as pilot: |
| 71 | + menu = app.query_one(ModelSelectionMenu) |
| 72 | + menu.show() |
| 73 | + |
| 74 | + await pilot.press("down") |
| 75 | + await pilot.press("enter") |
| 76 | + |
| 77 | + app.mock_actions.change_model.assert_called_once_with("haiku") |
| 78 | + |
| 79 | + async def test_opus_command_calls_change_model(self, app): |
| 80 | + async with app.run_test() as pilot: |
| 81 | + menu = app.query_one(ModelSelectionMenu) |
| 82 | + menu.show() |
| 83 | + |
| 84 | + await pilot.press("down") |
| 85 | + await pilot.press("down") |
| 86 | + await pilot.press("enter") |
| 87 | + |
| 88 | + app.mock_actions.change_model.assert_called_once_with("opus") |
| 89 | + |
| 90 | + async def test_selection_hides_menu(self, app): |
| 91 | + async with app.run_test() as pilot: |
| 92 | + menu = app.query_one(ModelSelectionMenu) |
| 93 | + menu.show() |
| 94 | + |
| 95 | + await pilot.press("enter") |
| 96 | + |
| 97 | + assert menu.is_visible is False |
0 commit comments