Skip to content

Commit 16ff9dd

Browse files
authored
test(integration): use Playwright wait_for_url in navigation helper (#6385)
1 parent 3011ffc commit 16ff9dd

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

tests/integration/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def poll_for_navigation(
4646
"""
4747
prev_url = page.url
4848
yield
49-
AppHarness.expect(lambda: prev_url != page.url, timeout=timeout)
49+
page.wait_for_url(lambda url: url != prev_url, timeout=timeout * 1000)
5050

5151

5252
def n_expected_events(exp_event_order: Sequence[str | set[str]]) -> int:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)