test: cover schedule prompt modal validation
This commit is contained in:
@@ -50,15 +50,19 @@ class SchedulePromptScreen(ModalScreen[tuple[str, timedelta] | None]):
|
||||
self._submit()
|
||||
|
||||
def _submit(self) -> None:
|
||||
prompt = self.query_one("#prompt-input", Input).value.strip()
|
||||
prompt_input = self.query_one("#prompt-input", Input)
|
||||
prompt = prompt_input.value.strip()
|
||||
if not prompt:
|
||||
self._set_error("Prompt cannot be empty")
|
||||
prompt_input.focus()
|
||||
return
|
||||
|
||||
delay_input = self.query_one("#delay-input", Input)
|
||||
try:
|
||||
delay = parse_delay(self.query_one("#delay-input", Input).value.strip())
|
||||
delay = parse_delay(delay_input.value.strip())
|
||||
except ValueError:
|
||||
self._set_error("Use a delay like 90s, 30m, 2h, or 1h30m")
|
||||
delay_input.focus()
|
||||
return
|
||||
|
||||
self.dismiss((prompt, delay))
|
||||
|
||||
@@ -1122,6 +1122,47 @@ async def test_schedule_prompt_screen_invalid_delay_stays_open_with_error():
|
||||
assert results == []
|
||||
error = app.screen.query_one("#schedule-error", Label)
|
||||
assert "Use a delay like" in str(error.render())
|
||||
assert app.screen.focused == app.screen.query_one("#delay-input", Input)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_schedule_prompt_screen_empty_prompt_stays_open_with_error():
|
||||
from hqt.tui.screens.schedule_prompt import SchedulePromptScreen
|
||||
from textual.widgets import Button, Input, Label
|
||||
|
||||
app = HqtApp()
|
||||
async with app.run_test(size=(120, 40)) as pilot:
|
||||
results = []
|
||||
app.push_screen(SchedulePromptScreen(), results.append)
|
||||
await pilot.pause()
|
||||
|
||||
app.screen.query_one("#prompt-input", Input).value = " "
|
||||
app.screen.query_one("#delay-input", Input).value = "30m"
|
||||
app.screen.query_one("#ok-btn", Button).press()
|
||||
await pilot.pause()
|
||||
|
||||
assert isinstance(app.screen, SchedulePromptScreen)
|
||||
assert results == []
|
||||
error = app.screen.query_one("#schedule-error", Label)
|
||||
assert "Prompt cannot be empty" in str(error.render())
|
||||
assert app.screen.focused == app.screen.query_one("#prompt-input", Input)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_schedule_prompt_screen_cancel_returns_none():
|
||||
from hqt.tui.screens.schedule_prompt import SchedulePromptScreen
|
||||
from textual.widgets import Button
|
||||
|
||||
app = HqtApp()
|
||||
async with app.run_test(size=(120, 40)) as pilot:
|
||||
results = []
|
||||
app.push_screen(SchedulePromptScreen(), results.append)
|
||||
await pilot.pause()
|
||||
|
||||
app.screen.query_one("#cancel-btn", Button).press()
|
||||
await pilot.pause()
|
||||
|
||||
assert results == [None]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user