Fix #5: compact file workflow forms

This commit is contained in:
Philip Henning 2026-09-08 17:34:25 +02:00
parent 41a96b8156
commit 2c7840426d
2 changed files with 128 additions and 69 deletions

View file

@ -3,7 +3,8 @@
from unittest.mock import Mock
import pytest
from textual.widgets import Button, DirectoryTree, Input, RadioButton, Static
from textual.containers import Vertical
from textual.widgets import Button, DirectoryTree, Input, RadioButton, RadioSet, Static
from hosts.core.import_export import (
ExportFormat,
@ -58,6 +59,31 @@ async def test_export_modal_is_centered_in_the_terminal_viewport():
assert container.region.y == (app.size.height - container.region.height) // 2
@pytest.mark.asyncio
async def test_format_modal_uses_compact_consistent_form_sections():
"""Location and format fields use matching borders without excess rows."""
app = HostsManagerApp()
app.load_hosts_file = Mock()
async with app.run_test(size=(120, 40)) as pilot:
await pilot.press("ctrl+x")
await pilot.pause()
location = app.screen.query_one(".path-section", Vertical)
formats = app.screen.query_one(".format-section", Vertical)
path_input = app.screen.query_one("#path-input", Input)
browse = app.screen.query_one("#browse-button", Button)
format_select = app.screen.query_one("#format-select", RadioSet)
container = app.screen.query_one("#format-container")
assert location.border_title == "Export file path"
assert path_input.region.height == 1
assert browse.region.height == 1
assert format_select.region.height == 3
assert formats.region.height == 5
assert container.region.height <= 22
@pytest.mark.asyncio
async def test_export_browser_lets_the_user_choose_a_destination_directory():
"""Browse opens a centered directory tree rather than requiring a typed path."""
@ -71,6 +97,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 path_input.region.height == 1
assert browse.region.height == 1
assert browse.region.x >= path_input.region.right
assert browse.region.y == path_input.region.y
assert browse.region.right <= container.region.right
@ -85,7 +113,6 @@ 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")
@ -98,8 +125,8 @@ 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."""
async def test_file_browser_presents_parent_directory_as_dot_dot(tmp_path):
"""The chooser exposes its parent as the first conventional tree entry."""
child = tmp_path / "child"
child.mkdir()
app = HostsManagerApp()
@ -110,11 +137,17 @@ async def test_file_browser_can_move_to_its_parent_directory(tmp_path):
await pilot.pause()
browser = app.screen
assert isinstance(browser, FileBrowserModal)
browser.action_go_up()
tree = browser.query_one("#file-browser-tree", DirectoryTree)
await pilot.pause()
assert browser.query_one("#file-browser-tree", DirectoryTree).path == tmp_path
assert str(tree.root.children[0].label) == ".."
assert len(browser.query("#up-button")) == 0
tree.focus()
tree.select_node(tree.root.children[0])
await pilot.pause()
assert tree.path == tmp_path
@pytest.mark.asyncio