|
| 1 | +"""Unit tests for integration test utilities.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from collections.abc import Callable |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from tests.integration import utils |
| 10 | + |
| 11 | + |
| 12 | +class _FakePage: |
| 13 | + """Minimal page stub for testing poll_for_navigation.""" |
| 14 | + |
| 15 | + def __init__(self) -> None: |
| 16 | + """Initialize fake page state.""" |
| 17 | + self.url = "http://localhost:3000/" |
| 18 | + self.wait_calls: list[tuple[Callable[[str], bool], float]] = [] |
| 19 | + |
| 20 | + def wait_for_url(self, predicate: Callable[[str], bool], timeout: float) -> None: |
| 21 | + """Record wait_for_url calls and validate the URL-change predicate. |
| 22 | +
|
| 23 | + Args: |
| 24 | + predicate: URL-matcher callback passed by poll_for_navigation. |
| 25 | + timeout: Timeout in milliseconds. |
| 26 | + """ |
| 27 | + self.wait_calls.append((predicate, timeout)) |
| 28 | + assert not predicate("http://localhost:3000/") |
| 29 | + assert predicate("http://localhost:3000/next") |
| 30 | + |
| 31 | + |
| 32 | +def test_poll_for_navigation_uses_playwright_wait_for_url( |
| 33 | + monkeypatch: pytest.MonkeyPatch, |
| 34 | +) -> None: |
| 35 | + """poll_for_navigation should delegate URL waiting to Playwright.""" |
| 36 | + |
| 37 | + def _unexpected_expect(*_args: object, **_kwargs: object) -> None: |
| 38 | + msg = "poll_for_navigation should not call AppHarness.expect" |
| 39 | + raise AssertionError(msg) |
| 40 | + |
| 41 | + monkeypatch.setattr(utils.AppHarness, "expect", _unexpected_expect) |
| 42 | + |
| 43 | + page = _FakePage() |
| 44 | + with utils.poll_for_navigation(page, timeout=2.5): |
| 45 | + # The helper snapshots the current URL before yielding. |
| 46 | + pass |
| 47 | + |
| 48 | + assert len(page.wait_calls) == 1 |
| 49 | + _, timeout_ms = page.wait_calls[0] |
| 50 | + assert timeout_ms == pytest.approx(2500.0) |
0 commit comments