Enhance status display and entry details in HostsManagerApp

- Updated header title to "/etc/hosts Manager" and modified subtitle format.
- Implemented a dedicated overlay status bar for error messages, ensuring no layout shifts.
- Refactored entry details display to use DataTable with labeled rows for improved consistency.
- Added CSS styles for the new status bar and DataTable.
- Created tests for status bar visibility and DataTable functionality, ensuring all tests pass.
This commit is contained in:
Philip Henning 2025-07-31 09:47:09 +02:00
parent 999b949f32
commit 25001042e5
11 changed files with 524 additions and 98 deletions

60
test_status.py Normal file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""
Quick test script to verify the new status display functionality.
"""
import sys
from unittest.mock import patch, Mock
from src.hosts.tui.app import HostsManagerApp
from src.hosts.core.models import HostsFile, HostEntry
def test_status_display():
"""Test the new status display functionality."""
print("Testing new status display...")
with patch('hosts.tui.app.HostsParser') as mock_parser_cls, \
patch('hosts.tui.app.Config') as mock_config_cls:
# Set up mocks
mock_parser = Mock()
mock_config = Mock()
mock_parser_cls.return_value = mock_parser
mock_config_cls.return_value = mock_config
# Create app
app = HostsManagerApp()
# Test title
print(f"✓ Title: '{app.title}' (should be '/etc/hosts Manager')")
assert app.title == "/etc/hosts Manager"
# Add some test entries
app.hosts_file = HostsFile()
app.hosts_file.add_entry(HostEntry(ip_address="127.0.0.1", hostnames=["localhost"]))
app.hosts_file.add_entry(HostEntry(ip_address="192.168.1.1", hostnames=["router"]))
app.hosts_file.add_entry(HostEntry(ip_address="10.0.0.1", hostnames=["server"], is_active=False))
# Test normal status update
app.update_status()
expected_subtitle = "3 entries (2 active) | Read-only mode"
print(f"✓ Subtitle: '{app.sub_title}' (should be '{expected_subtitle}')")
assert app.sub_title == expected_subtitle
# Test edit mode
app.edit_mode = True
app.update_status()
expected_subtitle = "3 entries (2 active) | Edit mode"
print(f"✓ Edit mode subtitle: '{app.sub_title}' (should be '{expected_subtitle}')")
assert app.sub_title == expected_subtitle
print("\n✅ All status display tests passed!")
# Test error message handling (would go to status bar)
print("\n📋 Status bar functionality:")
print(" - Error messages now appear in a status bar below the header")
print(" - Status bar is hidden by default and only shows when there are messages")
print(" - Messages auto-clear after 3-5 seconds")
print(" - Header subtitle always shows: 'X entries (Y active) | Mode'")
if __name__ == "__main__":
test_status_display()