MCPcopy Index your code
hub / github.com/reactive-python/reactpy / test_automatic_reconnect

Function test_automatic_reconnect

src/py/reactpy/tests/test_client.py:16–70  ·  view source on GitHub ↗
(browser: Browser)

Source from the content-addressed store, hash-verified

14
15
16async def test_automatic_reconnect(browser: Browser):
17 port = find_available_port("localhost")
18 page = await browser.new_page()
19
20 # we need to wait longer here because the automatic reconnect is not instant
21 page.set_default_timeout(10000)
22
23 @reactpy.component
24 def SomeComponent():
25 count, incr_count = use_counter(0)
26 return reactpy.html._(
27 reactpy.html.p({"data_count": count, "id": "count"}, "count", count),
28 reactpy.html.button(
29 {"on_click": lambda e: incr_count(), "id": "incr"}, "incr"
30 ),
31 )
32
33 async def get_count():
34 # need to refetch element because may unmount on reconnect
35 count = await page.wait_for_selector("#count")
36 return await count.get_attribute("data-count")
37
38 async with AsyncExitStack() as exit_stack:
39 server = await exit_stack.enter_async_context(BackendFixture(port=port))
40 display = await exit_stack.enter_async_context(
41 DisplayFixture(server, driver=page)
42 )
43
44 await display.show(SomeComponent)
45
46 incr = await page.wait_for_selector("#incr")
47
48 for i in range(3):
49 await poll(get_count).until_equals(str(i))
50 await incr.click()
51
52 # the server is disconnected but the last view state is still shown
53 await page.wait_for_selector("#count")
54
55 async with AsyncExitStack() as exit_stack:
56 server = await exit_stack.enter_async_context(BackendFixture(port=port))
57 display = await exit_stack.enter_async_context(
58 DisplayFixture(server, driver=page)
59 )
60
61 # use mount instead of show to avoid a page refresh
62 display.backend.mount(SomeComponent)
63
64 for i in range(3):
65 await poll(get_count).until_equals(str(i))
66
67 # need to refetch element because may unmount on reconnect
68 incr = await page.wait_for_selector("#incr")
69
70 await incr.click()
71
72
73async def test_style_can_be_changed(display: DisplayFixture):

Callers

nothing calls this directly

Calls 6

find_available_portFunction · 0.90
BackendFixtureClass · 0.90
DisplayFixtureClass · 0.90
pollClass · 0.90
showMethod · 0.80
until_equalsMethod · 0.80

Tested by

no test coverage detected