"""A price refresh finishing, in a real browser, with a trade half typed. The page reloads once a refresh it watched has finished, so every figure comes from one render. The live-price watcher asks first whether somebody is in the middle of something; the refresh watcher did not, and a refresh that was running when the page loaded (a scheduled one included) took the Record trade dialog and whatever was typed into it. """ from __future__ import annotations import json import re import subprocess import pytest from test_trade_dialog_in_the_browser import CHROME, HTML, STATIC import factories as fac from test_routes import bind_to_only_portfolio, make_login pytestmark = pytest.mark.visual # The tab's own memory across a reload: how many times the page has loaded, # and what the walk saw before it did. MEMORY = """ """ WALK = """ """ def test_a_finished_refresh_waits_for_the_trade_being_typed(client, session_factory, tmp_path): make_login(client, session_factory) with session_factory() as s: bind_to_only_portfolio(s) fac.hold(s, fac.make_instrument(s, "ACME")) s.commit() page = client.get("/", headers=HTML) assert page.status_code == 200 def script(match: re.Match) -> str: path = STATIC / match.group(1) if match.group(1) == "idle.js" or not path.is_file(): return "" return "" text = re.sub(r'', script, page.text) text = text.replace("", "" + MEMORY, 1) .replace("", WALK + ""), encoding="utf-8") dom = subprocess.run( [CHROME, "--headless", "--disable-gpu", "--dump-dom", "--no-sandbox", "--allow-file-access-from-files", "--window-size=1400,1000", "--virtual-time-budget=40000", target.as_uri()], capture_output=True, text=True, timeout=120).stdout found = re.search(r'
(.*?)
', dom, re.S) assert found, "the walk did not finish" out = json.loads(found.group(1).replace(""", '"')) # Kept while the dialog was open with a figure in it; reloaded once free. assert out == {"loads": 2, "keptWhileTyping": "7"}