Enhance save confirmation modal: adjust button focus behavior and update tests for new functionality
This commit is contained in:
parent
f7671db43e
commit
77d8e647f2
2 changed files with 83 additions and 2 deletions
|
@ -6,7 +6,7 @@ This module tests the save confirmation functionality when exiting edit entry mo
|
|||
|
||||
import pytest
|
||||
from unittest.mock import Mock, patch
|
||||
from textual.widgets import Input, Checkbox
|
||||
from textual.widgets import Input, Checkbox, Button
|
||||
|
||||
from hosts.main import HostsManagerApp
|
||||
from hosts.core.models import HostsFile, HostEntry
|
||||
|
@ -56,6 +56,29 @@ class TestSaveConfirmationModal:
|
|||
|
||||
modal.dismiss.assert_called_once_with("cancel")
|
||||
|
||||
@patch.object(SaveConfirmationModal, "call_after_refresh")
|
||||
@patch.object(SaveConfirmationModal, "focus")
|
||||
def test_on_mount_sets_focus(self, mock_focus, mock_call_after_refresh):
|
||||
"""Test that on_mount sets focus to the modal and schedules button focus."""
|
||||
modal = SaveConfirmationModal()
|
||||
|
||||
modal.on_mount()
|
||||
|
||||
mock_focus.assert_called_once()
|
||||
mock_call_after_refresh.assert_called_once()
|
||||
|
||||
@patch.object(SaveConfirmationModal, "query_one")
|
||||
def test_focus_save_button(self, mock_query_one):
|
||||
"""Test that _focus_save_button focuses the save button."""
|
||||
modal = SaveConfirmationModal()
|
||||
mock_save_button = Mock()
|
||||
mock_query_one.return_value = mock_save_button
|
||||
|
||||
modal._focus_save_button()
|
||||
|
||||
mock_query_one.assert_called_once_with("#save-button", Button)
|
||||
mock_save_button.focus.assert_called_once()
|
||||
|
||||
|
||||
class TestSaveConfirmationIntegration:
|
||||
"""Test cases for save confirmation integration with the main app."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue