From 911884d38c6eb864881cdf596ba98761d747cca8 Mon Sep 17 00:00:00 2001 From: Benjamin Barrera-Altuna Date: Fri, 24 Apr 2026 22:30:20 -0400 Subject: [PATCH] test(integration): use Playwright wait_for_url in navigation helper --- tests/integration/utils.py | 2 +- tests/units/integration/test_utils.py | 50 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/units/integration/test_utils.py diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 072514811ff..692caddf4eb 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -46,7 +46,7 @@ def poll_for_navigation( """ prev_url = page.url yield - AppHarness.expect(lambda: prev_url != page.url, timeout=timeout) + page.wait_for_url(lambda url: url != prev_url, timeout=timeout * 1000) def n_expected_events(exp_event_order: Sequence[str | set[str]]) -> int: diff --git a/tests/units/integration/test_utils.py b/tests/units/integration/test_utils.py new file mode 100644 index 00000000000..df98ec08ae9 --- /dev/null +++ b/tests/units/integration/test_utils.py @@ -0,0 +1,50 @@ +"""Unit tests for integration test utilities.""" + +from __future__ import annotations + +from collections.abc import Callable + +import pytest + +from tests.integration import utils + + +class _FakePage: + """Minimal page stub for testing poll_for_navigation.""" + + def __init__(self) -> None: + """Initialize fake page state.""" + self.url = "http://localhost:3000/" + self.wait_calls: list[tuple[Callable[[str], bool], float]] = [] + + def wait_for_url(self, predicate: Callable[[str], bool], timeout: float) -> None: + """Record wait_for_url calls and validate the URL-change predicate. + + Args: + predicate: URL-matcher callback passed by poll_for_navigation. + timeout: Timeout in milliseconds. + """ + self.wait_calls.append((predicate, timeout)) + assert not predicate("http://localhost:3000/") + assert predicate("http://localhost:3000/next") + + +def test_poll_for_navigation_uses_playwright_wait_for_url( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """poll_for_navigation should delegate URL waiting to Playwright.""" + + def _unexpected_expect(*_args: object, **_kwargs: object) -> None: + msg = "poll_for_navigation should not call AppHarness.expect" + raise AssertionError(msg) + + monkeypatch.setattr(utils.AppHarness, "expect", _unexpected_expect) + + page = _FakePage() + with utils.poll_for_navigation(page, timeout=2.5): + # The helper snapshots the current URL before yielding. + pass + + assert len(page.wait_calls) == 1 + _, timeout_ms = page.wait_calls[0] + assert timeout_ms == pytest.approx(2500.0)