Feat #2: add Host Entry from selected
This commit is contained in:
parent
6ce1d7da2f
commit
f2e2d45480
9 changed files with 213 additions and 11 deletions
|
|
@ -8,7 +8,7 @@ DNS name entries, validation, and mutual exclusion logic.
|
|||
import pytest
|
||||
from typing import cast
|
||||
from unittest.mock import Mock
|
||||
from textual.widgets import Input, Checkbox, RadioSet, Static
|
||||
from textual.widgets import Input, Checkbox, RadioSet, RadioButton, Static
|
||||
|
||||
from src.hosts.tui.add_entry_modal import AddEntryModal
|
||||
from src.hosts.core.models import HostEntry
|
||||
|
|
@ -267,6 +267,50 @@ class TestAddEntryModalRadioButtonLogic:
|
|||
mock_hostname_input.focus.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_prefilled_dns_modal_keeps_separate_address_drafts_when_switching_type():
|
||||
"""A copied DNS Entry retains both address drafts while its type is changed."""
|
||||
from src.hosts.tui.app import HostsManagerApp
|
||||
|
||||
source = HostEntry(
|
||||
ip_address="192.0.2.45",
|
||||
hostnames=["source.test", "alias.test"],
|
||||
comment="Copied",
|
||||
is_active=True,
|
||||
dns_name="origin.example",
|
||||
resolved_ip="192.0.2.45",
|
||||
dns_resolution_status="resolved",
|
||||
)
|
||||
app = HostsManagerApp()
|
||||
app.hosts_file.entries = [source]
|
||||
app.load_hosts_file = Mock()
|
||||
|
||||
async with app.run_test() as pilot:
|
||||
app.push_screen(AddEntryModal(source))
|
||||
await pilot.pause()
|
||||
modal = app.screen
|
||||
assert modal.query_one("#dns-entry-radio", RadioButton).value
|
||||
assert modal.query_one("#dns-name-input", Input).value == "origin.example"
|
||||
assert modal.query_one("#ip-address-input", Input).value == ""
|
||||
assert not modal.query_one("#active-checkbox", Checkbox).value
|
||||
assert modal.query_one("#active-checkbox", Checkbox).disabled
|
||||
|
||||
await pilot.click("#ip-entry-radio")
|
||||
await pilot.pause()
|
||||
assert modal.query_one("#ip-address-input", Input).value == ""
|
||||
assert modal.query_one("#active-checkbox", Checkbox).value
|
||||
assert not modal.query_one("#active-checkbox", Checkbox).disabled
|
||||
|
||||
modal.query_one("#ip-address-input", Input).value = "198.51.100.8"
|
||||
await pilot.click("#dns-entry-radio")
|
||||
await pilot.pause()
|
||||
assert modal.query_one("#dns-name-input", Input).value == "origin.example"
|
||||
|
||||
await pilot.click("#ip-entry-radio")
|
||||
await pilot.pause()
|
||||
assert modal.query_one("#ip-address-input", Input).value == "198.51.100.8"
|
||||
|
||||
|
||||
class TestAddEntryModalSaveLogic:
|
||||
"""Test cases for save logic in AddEntryModal."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue