Skip to content

Commit

Permalink
use_user test
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Sep 26, 2023
1 parent a5b2a18 commit b0bdbfc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_app/prerender/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ def inner(value):
return inner("prerender_component: Prerendered")

return inner("prerender_component: Fully Rendered")


@component
def use_user():
user = reactpy_django.hooks.use_user()
scope = reactpy_django.hooks.use_scope()
success = bool(user)

if scope.get("type") == "http":
return html.div(
{"id": "use-user-http", "data-success": success}, f"use_user: {user} (HTTP)"
)

return html.div(
{"id": "use-user-ws", "data-success": success}, f"use_user: {user} (WebSocket)"
)
2 changes: 2 additions & 0 deletions tests/test_app/templates/prerender.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ <h1>ReactPy Prerender Test Page</h1>
{% component "test_app.prerender.components.prerender_component" class="prerender-component" prerender="true" %}
</div>
<hr>
{% component "test_app.prerender.components.use_user" prerender="true" %}
<hr>
</body>

</html>
4 changes: 4 additions & 0 deletions tests/test_app/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,13 @@ def test_prerender(self):
string = new_page.locator("#prerender_string")
vdom = new_page.locator("#prerender_vdom")
component = new_page.locator("#prerender_component")
use_user_http = new_page.locator("#use-user-http[data-success=True]")
use_user_ws = new_page.locator("#use-user-ws[data-success=true]")

string.wait_for()
vdom.wait_for()
component.wait_for()
use_user_http.wait_for()

# Check if the prerender occurred
self.assertEqual(
Expand All @@ -390,6 +393,7 @@ def test_prerender(self):
self.assertEqual(
component.all_inner_texts(), ["prerender_component: Fully Rendered"]
)
use_user_ws.wait_for()
finally:
new_page.close()

Expand Down

0 comments on commit b0bdbfc

Please sign in to comment.