Fix #5: make file chooser navigable

This commit is contained in:
Philip Henning 2026-09-08 17:19:41 +02:00
parent 1b19d5eca2
commit 41a96b8156
2 changed files with 83 additions and 31 deletions

View file

@ -3,7 +3,7 @@
from unittest.mock import Mock
import pytest
from textual.widgets import Button, Input, RadioButton, Static
from textual.widgets import Button, DirectoryTree, Input, RadioButton, Static
from hosts.core.import_export import (
ExportFormat,
@ -71,8 +71,8 @@ async def test_export_browser_lets_the_user_choose_a_destination_directory():
path_input = app.screen.query_one("#path-input", Input)
container = app.screen.query_one("#format-container")
assert browse.region.width > 0
assert browse.region.x >= path_input.region.x
assert browse.region.y >= path_input.region.bottom
assert browse.region.x >= path_input.region.right
assert browse.region.y == path_input.region.y
assert browse.region.right <= container.region.right
assert browse.region.bottom <= container.region.bottom
await pilot.press("tab")
@ -85,6 +85,7 @@ async def test_export_browser_lets_the_user_choose_a_destination_directory():
container = app.screen.query_one("#file-browser-container")
assert container.region.x == (app.size.width - container.region.width) // 2
await pilot.press("tab")
await pilot.press("tab")
await pilot.press("tab")
await pilot.press("enter")
@ -96,6 +97,26 @@ async def test_export_browser_lets_the_user_choose_a_destination_directory():
)
@pytest.mark.asyncio
async def test_file_browser_can_move_to_its_parent_directory(tmp_path):
"""The chooser exposes an explicit route back up the directory tree."""
child = tmp_path / "child"
child.mkdir()
app = HostsManagerApp()
app.load_hosts_file = Mock()
async with app.run_test(size=(120, 40)) as pilot:
app.push_screen(FileBrowserModal(child, choose_directory=True))
await pilot.pause()
browser = app.screen
assert isinstance(browser, FileBrowserModal)
browser.action_go_up()
await pilot.pause()
assert browser.query_one("#file-browser-tree", DirectoryTree).path == tmp_path
@pytest.mark.asyncio
async def test_export_requires_overwrite_confirmation_before_calling_service(tmp_path):
"""An existing output file is not replaced until the user confirms it."""