Skip to content

Include panel scripts in content when RENDER_PANELS=True #1689

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion debug_toolbar/static/debug_toolbar/js/timer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { $$ } from "./utils.js";

function insertBrowserTiming() {
console.log(["inserted"]);
const timingOffset = performance.timing.navigationStart,
timingEnd = performance.timing.loadEventEnd,
totalTime = timingEnd - timingOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h3>{{ panel.title }}</h3>
</div>
<div class="djDebugPanelContent">
{% if toolbar.should_render_panels %}
{% for script in panel.scripts %}<script type="module" src="{{ script }}" async></script>{% endfor %}
<div class="djdt-scroll">{{ panel.content }}</div>
{% else %}
<div class="djdt-loader"></div>
Expand Down
27 changes: 20 additions & 7 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
rf = RequestFactory()


def toolbar_store_id():
def get_response(request):
return HttpResponse()

toolbar = DebugToolbar(rf.get("/"), get_response)
toolbar.store()
return toolbar.store_id


class BuggyPanel(Panel):
def title(self):
return "BuggyPanel"
Expand Down Expand Up @@ -213,13 +222,8 @@ def test_html5_validation(self):
raise self.failureException(msg)

def test_render_panel_checks_show_toolbar(self):
def get_response(request):
return HttpResponse()

toolbar = DebugToolbar(rf.get("/"), get_response)
toolbar.store()
url = "/__debug__/render_panel/"
data = {"store_id": toolbar.store_id, "panel_id": "VersionsPanel"}
data = {"store_id": toolbar_store_id(), "panel_id": "VersionsPanel"}

response = self.client.get(url, data)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -444,7 +448,7 @@ def test_view_returns_template_response(self):
self.assertEqual(response.status_code, 200)

@override_settings(DEBUG_TOOLBAR_CONFIG={"DISABLE_PANELS": set()})
def test_intcercept_redirects(self):
def test_intercept_redirects(self):
response = self.client.get("/redirect/")
self.assertEqual(response.status_code, 200)
# Link to LOCATION header.
Expand All @@ -464,6 +468,15 @@ def test_server_timing_headers(self):
for expected in expected_partials:
self.assertTrue(re.compile(expected).search(server_timing))

@override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True})
def test_timer_panel(self):
response = self.client.get("/regular/basic/")
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'<script type="module" src="/static/debug_toolbar/js/timer.js" async>',
)

def test_auth_login_view_without_redirect(self):
response = self.client.get("/login_without_redirect/")
self.assertEqual(response.status_code, 200)
Expand Down