hosts/test_overlay.py
phg 25001042e5 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.
2025-07-31 09:47:09 +02:00

56 lines
2 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify the status bar overlay behavior.
"""
import asyncio
from unittest.mock import patch, Mock
from src.hosts.tui.app import HostsManagerApp
from src.hosts.core.models import HostsFile, HostEntry
async def test_status_overlay():
"""Test that the status bar appears as an overlay without affecting layout."""
print("Testing status bar overlay behavior...")
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_config.should_show_default_entries.return_value = True
mock_parser_cls.return_value = mock_parser
mock_config_cls.return_value = mock_config
# Create app
app = HostsManagerApp()
# Add test entries
app.hosts_file = HostsFile()
app.hosts_file.add_entry(HostEntry(
ip_address="127.0.0.1",
hostnames=["localhost"],
is_active=True
))
# Test status update with error message
app.update_status("❌ Test error message")
print("✓ Error message should appear as overlay")
print("✓ Panes should not shift down when message appears")
print("✓ Status bar positioned with dock: top, layer: overlay, offset: 3 0")
# Test clearing message
app._clear_status_message()
print("✓ Message clears and status bar becomes hidden")
print("\n✅ Status bar overlay test completed!")
print("\n📋 CSS Implementation:")
print(" - dock: top - positions at top of screen")
print(" - layer: overlay - renders above other content")
print(" - offset: 3 0 - positioned 3 lines down from top (below header)")
print(" - No layout flow impact - content stays in same position")
if __name__ == "__main__":
asyncio.run(test_status_overlay())