Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import base64

import pytest

from dash import Dash, dcc


@pytest.mark.parametrize("point_count", [1000, 1001])
def test_grpr001_graph_survives_print(point_count, dash_dcc):
app = Dash(__name__)
points = list(range(point_count))
app.layout = dcc.Graph(
id="graph",
figure={
"data": [{"type": "scatter", "mode": "lines", "x": points, "y": points}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: "scatter" never goes down the path that breaks. 1000 and 1001 points both render as SVG, so the parametrize doesn't test the threshold at all. The switch at 1001 happens because px picks scattergl. Can you use scattergl (or build the figure with px.line) so the test hits the WebGL path?

"layout": {"width": 600, "height": 400},
},
)

dash_dcc.start_server(app)
dash_dcc.wait_for_element("#graph .main-svg")

driver = dash_dcc.driver
if not hasattr(driver, "execute_cdp_cmd"):
pytest.skip("print-to-PDF regression requires Chrome DevTools Protocol")

driver.execute_cdp_cmd("Emulation.setEmulatedMedia", {"media": "print"})
pdf = driver.execute_cdp_cmd(
"Page.printToPDF", {"printBackground": True, "preferCSSPageSize": True}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue says Chrome's native print works fine at 2000 points. The failing cases are Firefox print and html2pdf/html2canvas. A Chrome Page.printToPDF check passes whether the bug is there or not. What case is this meant to fail on?

)

pdf_bytes = base64.b64decode(pdf["data"])
assert pdf_bytes.startswith(b"%PDF")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions don't look at what got printed. Any page makes a PDF with a %PDF header that's over 1000 bytes, and the is_displayed() check reads the live DOM, not the PDF. An empty plot in the PDF (the reported symptom) passes all three. If you want to test print output, can you render the PDF, or a canvas snapshot of the graph, and check that the trace pixels are there?

assert len(pdf_bytes) > 1000
assert dash_dcc.find_element("#graph .scatterlayer .trace path").is_displayed()
assert dash_dcc.get_logs() == []
Loading