Refactor tests for HostsManagerApp: update status verification to use footer instead of subtitle for improved accuracy and clarity.
This commit is contained in:
parent
bc0f8b99e8
commit
e6f3e9f3d4
2 changed files with 27 additions and 10 deletions
|
@ -267,6 +267,10 @@ class TestHostsManagerApp:
|
|||
):
|
||||
app = HostsManagerApp()
|
||||
|
||||
# Mock the query_one method to avoid UI dependencies
|
||||
mock_footer = Mock()
|
||||
app.query_one = Mock(return_value=mock_footer)
|
||||
|
||||
# Add test entries
|
||||
app.hosts_file = HostsFile()
|
||||
app.hosts_file.add_entry(
|
||||
|
@ -280,10 +284,12 @@ class TestHostsManagerApp:
|
|||
|
||||
app.update_status()
|
||||
|
||||
# Verify sub_title was set correctly
|
||||
assert "Read-only mode" in app.sub_title
|
||||
assert "2 entries" in app.sub_title
|
||||
assert "1 active" in app.sub_title
|
||||
# Verify footer status was updated
|
||||
mock_footer.set_status.assert_called_once()
|
||||
status_call = mock_footer.set_status.call_args[0][0]
|
||||
assert "Read-only" in status_call
|
||||
assert "2 entries" in status_call
|
||||
assert "1 active" in status_call
|
||||
|
||||
def test_update_status_custom_message(self):
|
||||
"""Test status bar update with custom message."""
|
||||
|
@ -299,9 +305,18 @@ class TestHostsManagerApp:
|
|||
# Mock set_timer and query_one to avoid event loop and UI issues
|
||||
app.set_timer = Mock()
|
||||
mock_status_bar = Mock()
|
||||
app.query_one = Mock(return_value=mock_status_bar)
|
||||
mock_footer = Mock()
|
||||
|
||||
# Add test hosts_file for subtitle generation
|
||||
def mock_query_one(selector, widget_type=None):
|
||||
if selector == "#status-bar":
|
||||
return mock_status_bar
|
||||
elif selector == "#custom-footer":
|
||||
return mock_footer
|
||||
return Mock()
|
||||
|
||||
app.query_one = mock_query_one
|
||||
|
||||
# Add test hosts_file for footer status generation
|
||||
app.hosts_file = HostsFile()
|
||||
app.hosts_file.add_entry(
|
||||
HostEntry(ip_address="127.0.0.1", hostnames=["localhost"])
|
||||
|
@ -317,9 +332,11 @@ class TestHostsManagerApp:
|
|||
# Verify status bar was updated with custom message
|
||||
mock_status_bar.update.assert_called_with("Custom status message")
|
||||
mock_status_bar.remove_class.assert_called_with("hidden")
|
||||
# Verify subtitle shows current status (not the custom message)
|
||||
assert "2 entries" in app.sub_title
|
||||
assert "Read-only mode" in app.sub_title
|
||||
# Verify footer status was updated with current status (not the custom message)
|
||||
mock_footer.set_status.assert_called_once()
|
||||
footer_status = mock_footer.set_status.call_args[0][0]
|
||||
assert "2 entries" in footer_status
|
||||
assert "Read-only" in footer_status
|
||||
# Verify timer was set for auto-clearing
|
||||
app.set_timer.assert_called_once()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue