Refactor entry details display: replace DataTable with disabled input widgets for improved clarity and user experience.

This commit is contained in:
Philip Henning 2025-08-17 18:45:54 +02:00
parent 9a9161f28c
commit de5acd4dad
5 changed files with 120 additions and 68 deletions

View file

@ -156,16 +156,27 @@ class TestHostsManagerApp:
):
app = HostsManagerApp()
# Mock the query_one method to return DataTable mock
mock_details_table = Mock()
mock_details_table.columns = [] # Mock empty columns list
# Mock the query_one method to return disabled input widgets
mock_details_display = Mock()
mock_edit_form = Mock()
mock_ip_input = Mock()
mock_hostname_input = Mock()
mock_comment_input = Mock()
mock_active_checkbox = Mock()
def mock_query_one(selector, widget_type=None):
if selector == "#entry-details-table":
return mock_details_table
if selector == "#entry-details-display":
return mock_details_display
elif selector == "#entry-edit-form":
return mock_edit_form
elif selector == "#details-ip-input":
return mock_ip_input
elif selector == "#details-hostname-input":
return mock_hostname_input
elif selector == "#details-comment-input":
return mock_comment_input
elif selector == "#details-active-checkbox":
return mock_active_checkbox
return Mock()
app.query_one = mock_query_one
@ -182,12 +193,13 @@ class TestHostsManagerApp:
app.update_entry_details()
# Verify DataTable operations were called
mock_details_table.remove_class.assert_called_with("hidden")
# Verify input widgets were updated with entry data
mock_details_display.remove_class.assert_called_with("hidden")
mock_edit_form.add_class.assert_called_with("hidden")
mock_details_table.clear.assert_called_once()
mock_details_table.add_column.assert_called()
mock_details_table.add_row.assert_called()
assert mock_ip_input.value == "127.0.0.1"
assert mock_hostname_input.value == "localhost, local"
assert mock_comment_input.value == "Test comment"
assert mock_active_checkbox.value
def test_update_entry_details_no_entries(self):
"""Test updating entry details with no entries."""
@ -200,16 +212,27 @@ class TestHostsManagerApp:
):
app = HostsManagerApp()
# Mock the query_one method to return DataTable mock
mock_details_table = Mock()
mock_details_table.columns = [] # Mock empty columns list
# Mock the query_one method to return disabled input widgets
mock_details_display = Mock()
mock_edit_form = Mock()
mock_ip_input = Mock()
mock_hostname_input = Mock()
mock_comment_input = Mock()
mock_active_checkbox = Mock()
def mock_query_one(selector, widget_type=None):
if selector == "#entry-details-table":
return mock_details_table
if selector == "#entry-details-display":
return mock_details_display
elif selector == "#entry-edit-form":
return mock_edit_form
elif selector == "#details-ip-input":
return mock_ip_input
elif selector == "#details-hostname-input":
return mock_hostname_input
elif selector == "#details-comment-input":
return mock_comment_input
elif selector == "#details-active-checkbox":
return mock_active_checkbox
return Mock()
app.query_one = mock_query_one
@ -217,12 +240,16 @@ class TestHostsManagerApp:
app.update_entry_details()
# Verify DataTable operations were called for empty state
mock_details_table.remove_class.assert_called_with("hidden")
# Verify widgets show empty state placeholders
mock_details_display.remove_class.assert_called_with("hidden")
mock_edit_form.add_class.assert_called_with("hidden")
mock_details_table.clear.assert_called_once()
mock_details_table.add_column.assert_called_with("Field", key="field")
mock_details_table.add_row.assert_called_with("No entries loaded")
assert mock_ip_input.value == ""
assert mock_ip_input.placeholder == "No entries loaded"
assert mock_hostname_input.value == ""
assert mock_hostname_input.placeholder == "No entries loaded"
assert mock_comment_input.value == ""
assert mock_comment_input.placeholder == "No entries loaded"
assert not mock_active_checkbox.value
def test_update_status_default(self):
"""Test status bar update with default information."""