Skip to content

Commit f75d812

Browse files
committed
add tests
1 parent 9c2be65 commit f75d812

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tests/test_app/offline/components.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
@component
55
def online():
66
return html.div(
7+
{"id": "online"},
78
"This is the ONLINE component. "
8-
"Try shutting down your webserver and checking if the offline component appears."
9+
"Shut down your webserver and check if the offline component appears.",
910
)
1011

1112

1213
@component
1314
def offline():
14-
return html.div({"id": "offline-success"}, "Offline")
15+
return html.div({"id": "offline"}, "Offline")

tests/test_app/tests/test_components.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ def setUpClass(cls):
4646
cls._server_process.ready.wait()
4747
cls._port = cls._server_process.port.value
4848

49-
# Open the second server process
49+
# Open the second server process, used for testing custom hosts
5050
cls._server_process2 = cls.ProtocolServerProcess(cls.host, get_application)
5151
cls._server_process2.start()
5252
cls._server_process2.ready.wait()
5353
cls._port2 = cls._server_process2.port.value
5454

55+
# Open the third server process, used for testing offline fallback
56+
cls._server_process3 = cls.ProtocolServerProcess(cls.host, get_application)
57+
cls._server_process3.start()
58+
cls._server_process3.ready.wait()
59+
cls._port3 = cls._server_process3.port.value
60+
5561
# Open a Playwright browser window
5662
if sys.platform == "win32":
5763
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
@@ -67,9 +73,11 @@ def tearDownClass(cls):
6773
# Close the Playwright browser
6874
cls.playwright.stop()
6975

70-
# Close the second server process
76+
# Close the other server processes
7177
cls._server_process2.terminate()
7278
cls._server_process2.join()
79+
cls._server_process3.terminate()
80+
cls._server_process3.join()
7381

7482
# Repurposed from ChannelsLiveServerTestCase._post_teardown
7583
cls._server_process.terminate()
@@ -600,3 +608,20 @@ def test_url_router(self):
600608

601609
finally:
602610
new_page.close()
611+
612+
def test_offline_components(self):
613+
new_page = self.browser.new_page()
614+
try:
615+
server3_url = self.live_server_url.replace(
616+
str(self._port), str(self._port3)
617+
)
618+
new_page.goto(f"{server3_url}/offline/")
619+
new_page.wait_for_selector("div:not([hidden]) > #online")
620+
self.assertIsNotNone(new_page.query_selector("div[hidden] > #offline"))
621+
self._server_process3.terminate()
622+
self._server_process3.join()
623+
new_page.wait_for_selector("div:not([hidden]) > #offline")
624+
self.assertIsNotNone(new_page.query_selector("div[hidden] > #online"))
625+
626+
finally:
627+
new_page.close()

0 commit comments

Comments
 (0)