Handle negative cursor rows with hidden entries
- Guard against negative display indexes when no entries are visible - Add regression coverage for Textual's -1 cursor row
This commit is contained in:
parent
1a686bd0ff
commit
2c5a8d969c
2 changed files with 29 additions and 1 deletions
|
|
@ -593,6 +593,34 @@ class TestHostsManagerApp:
|
|||
app.details_handler.update_entry_details.assert_called_once()
|
||||
app.table_handler.display_index_to_actual_index.assert_called_once_with(2)
|
||||
|
||||
def test_data_table_row_highlighted_with_no_visible_entries(self):
|
||||
"""Handle Textual's negative cursor row when all entries are hidden."""
|
||||
mock_parser = Mock(spec=HostsParser)
|
||||
mock_config = Mock(spec=Config)
|
||||
mock_config.should_show_default_entries.return_value = False
|
||||
mock_config.is_default_entry.return_value = True
|
||||
|
||||
with (
|
||||
patch("hosts.tui.app.HostsParser", return_value=mock_parser),
|
||||
patch("hosts.tui.app.Config", return_value=mock_config),
|
||||
):
|
||||
app = HostsManagerApp()
|
||||
app.hosts_file = HostsFile(
|
||||
entries=[HostEntry(ip_address="127.0.0.1", hostnames=["localhost"])]
|
||||
)
|
||||
app.details_handler.update_entry_details = Mock()
|
||||
|
||||
mock_table = Mock()
|
||||
mock_table.id = "entries-table"
|
||||
event = Mock()
|
||||
event.data_table = mock_table
|
||||
event.cursor_row = -1
|
||||
|
||||
app.on_data_table_row_highlighted(event)
|
||||
|
||||
assert app.selected_entry_index == 0
|
||||
app.details_handler.update_entry_details.assert_called_once()
|
||||
|
||||
def test_data_table_header_selected_ip_column(self):
|
||||
"""Test DataTable header selection for IP column."""
|
||||
mock_parser = Mock(spec=HostsParser)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue