Skip to content

view_to_iframe component #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7938867
`view_to_iframe` component
Archmonger Sep 19, 2023
0ab5822
add changelog
Archmonger Sep 19, 2023
40b846f
Merge remote-tracking branch 'upstream/main' into view-to-iframe
Archmonger Sep 21, 2023
79462f9
functional view_to_iframe
Archmonger Sep 22, 2023
68e15a0
ViewToIframeConstructor type
Archmonger Sep 22, 2023
46dc39e
temporarily remove section index plugin
Archmonger Sep 22, 2023
b508589
better API
Archmonger Sep 23, 2023
afe31ac
update docs
Archmonger Sep 23, 2023
1b46664
Auto height and width
Archmonger Sep 23, 2023
38799ce
interface docs
Archmonger Sep 23, 2023
b45f7a9
register_iframe function
Archmonger Sep 24, 2023
8ac3415
move error tests to their own URL
Archmonger Sep 24, 2023
89af32d
reorganize and fix type hints
Archmonger Sep 24, 2023
b296774
update component docs
Archmonger Sep 24, 2023
e8e8455
misc docs tweaks
Archmonger Sep 24, 2023
614b863
add test for ComponentNotRegisteredError
Archmonger Sep 24, 2023
b3f2548
misc doc tweaks
Archmonger Sep 24, 2023
9bb8dda
Register Iframe docs
Archmonger Sep 24, 2023
c55ee3b
add interface utils.md
Archmonger Sep 24, 2023
63e6c98
more obvious error
Archmonger Sep 24, 2023
39171d0
ViewNotRegisteredError and ViewDoesNotExistError
Archmonger Sep 24, 2023
2b66156
clean up register component example
Archmonger Sep 24, 2023
376f7b7
remove dead types
Archmonger Sep 24, 2023
0eb6e90
misc docs tweaks
Archmonger Sep 24, 2023
b52a400
remove thread sensitive
Archmonger Sep 24, 2023
ea067e0
Use .as_view() for CBVs
Archmonger Sep 24, 2023
cad5720
update changelog
Archmonger Sep 24, 2023
b702eea
fix broken example
Archmonger Sep 25, 2023
bf768e0
revert proper docs tests while `reactpy.html` type hints suck
Archmonger Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move error tests to their own URL
  • Loading branch information
Archmonger committed Sep 24, 2023
commit 8ac34157cf3d60abaa125c58a5b415945c870bfb
18 changes: 4 additions & 14 deletions tests/test_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ <h1>ReactPy Test Page</h1>
<hr>
{% component "test_app.components.view_to_component_kwargs" %}
<hr>
{% component "test_app.components.view_to_component_decorator" %}
<hr>
{% component "test_app.components.view_to_component_decorator_args" %}
<hr>
{% component "test_app.components.view_to_component_sync_func_compatibility" %}
<hr>
{% component "test_app.components.view_to_component_async_func_compatibility" %}
Expand All @@ -83,20 +87,6 @@ <h1>ReactPy Test Page</h1>
<hr>
{% component "test_app.components.view_to_iframe_args" %}
<hr>
{% component "test_app.components.view_to_component_decorator" %}
<hr>
{% component "test_app.components.view_to_component_decorator_args" %}
<hr>
<div id="component_does_not_exist_error">{% component "test_app.components.does_not_exist" %}</div>
<hr>
<div id="component_param_error">{% component "test_app.components.hello_world" invalid_param="random_value" %}</div>
<hr>
<div id="invalid_host_error">{% component "test_app.components.hello_world" host="https://example.com/" %}</div>
<hr>
<div id="broken_postprocessor_query">
{% component "test_app.components.broken_postprocessor_query" %}
</div>
<hr>
</body>

</html>
28 changes: 28 additions & 0 deletions tests/test_app/templates/errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% load static %} {% load reactpy %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}" />
<title>ReactPy</title>
</head>

<body>
<h1>ReactPy Errors Test Page</h1>
<hr>
<div id="component_does_not_exist_error">{% component "test_app.components.does_not_exist" %}</div>
<hr>
<div id="component_param_error">{% component "test_app.components.hello_world" invalid_param="random_value" %}</div>
<hr>
<div id="invalid_host_error">{% component "test_app.components.hello_world" host="https://example.com/" %}</div>
<hr>
<div id="broken_postprocessor_query">
{% component "test_app.components.broken_postprocessor_query" %}
</div>
<hr>
</body>

</html>
56 changes: 31 additions & 25 deletions tests/test_app/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,6 @@ def test_view_to_component_decorator_args(self):
"#view_to_component_decorator_args[data-success=true]"
).wait_for()

def test_component_does_not_exist_error(self):
broken_component = self.page.locator("#component_does_not_exist_error")
broken_component.wait_for()
self.assertIn("ComponentDoesNotExistError:", broken_component.text_content())

def test_component_param_error(self):
broken_component = self.page.locator("#component_param_error")
broken_component.wait_for()
self.assertIn("ComponentParamError:", broken_component.text_content())

def test_component_session_exists(self):
"""Session should exist for components with args/kwargs."""
component = self.page.locator("#parametrized-component")
Expand Down Expand Up @@ -314,8 +304,8 @@ def test_component_session_missing(self):
def test_custom_host(self):
"""Make sure that the component is rendered by a separate server."""
new_page = self.browser.new_page()
new_page.goto(f"{self.live_server_url}/port/{self._port2}/")
try:
new_page.goto(f"{self.live_server_url}/port/{self._port2}/")
elem = new_page.locator(".custom_host-0")
elem.wait_for()
self.assertIn(
Expand All @@ -341,10 +331,8 @@ def test_custom_host_wrong_port(self):
def test_host_roundrobin(self):
"""Verify if round-robin host selection is working."""
new_page = self.browser.new_page()
new_page.goto(f"{self.live_server_url}/roundrobin/{self._port}/{self._port2}/8")
try:
new_page.goto(
f"{self.live_server_url}/roundrobin/{self._port}/{self._port2}/8"
)
elem0 = new_page.locator(".custom_host-0")
elem1 = new_page.locator(".custom_host-1")
elem2 = new_page.locator(".custom_host-2")
Expand Down Expand Up @@ -372,21 +360,11 @@ def test_host_roundrobin(self):
finally:
new_page.close()

def test_invalid_host_error(self):
broken_component = self.page.locator("#invalid_host_error")
broken_component.wait_for()
self.assertIn("InvalidHostError:", broken_component.text_content())

def test_broken_postprocessor_query(self):
broken_component = self.page.locator("#broken_postprocessor_query pre")
broken_component.wait_for()
self.assertIn("SynchronousOnlyOperation:", broken_component.text_content())

def test_prerender(self):
"""Verify if round-robin host selection is working."""
new_page = self.browser.new_page()
new_page.goto(f"{self.live_server_url}/prerender/")
try:
new_page.goto(f"{self.live_server_url}/prerender/")
string = new_page.locator("#prerender_string")
vdom = new_page.locator("#prerender_vdom")
component = new_page.locator("#prerender_component")
Expand Down Expand Up @@ -414,3 +392,31 @@ def test_prerender(self):
)
finally:
new_page.close()

def test_component_errors(self):
new_page = self.browser.new_page()
new_page.goto(f"{self.live_server_url}/errors/")
try:
# ComponentDoesNotExistError
broken_component = new_page.locator("#component_does_not_exist_error")
broken_component.wait_for()
self.assertIn(
"ComponentDoesNotExistError:", broken_component.text_content()
)

# ComponentParamError
broken_component = new_page.locator("#component_param_error")
broken_component.wait_for()
self.assertIn("ComponentParamError:", broken_component.text_content())

# InvalidHostError
broken_component = new_page.locator("#invalid_host_error")
broken_component.wait_for()
self.assertIn("InvalidHostError:", broken_component.text_content())

# SynchronousOnlyOperation
broken_component = new_page.locator("#broken_postprocessor_query pre")
broken_component.wait_for()
self.assertIn("SynchronousOnlyOperation:", broken_component.text_content())
finally:
new_page.close()
1 change: 1 addition & 0 deletions tests/test_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AccessUser:
"roundrobin/<int:port1>/<int:port2>/<int:count>/",
views.host_port_roundrobin_template,
),
path("errors/", views.errors_template),
path("", include("test_app.prerender.urls")),
path("", include("test_app.performance.urls")),
path("reactpy/", include("reactpy_django.http.urls")),
Expand Down
4 changes: 4 additions & 0 deletions tests/test_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def base_template(request):
return render(request, "base.html", {"my_object": TestObject(1)})


def errors_template(request):
return render(request, "errors.html", {})


def host_port_template(request: HttpRequest, port: int):
host = request.get_host().replace(str(request.get_port()), str(port))
return render(request, "host_port.html", {"new_host": host})
Expand Down