Skip to content

Commit eca3d52

Browse files
committed
additional test similar to markdown for graph
1 parent f86985a commit eca3d52

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

components/dash-core-components/tests/integration/graph/test_graph_varia.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,54 @@ def toggle(n):
10071007
dash_dcc.wait_for_contains_text(".gtitle", gravity)
10081008
dash_dcc.wait_for_no_elements(".gtitle-math")
10091009
assert dash_dcc.driver.execute_script("return !!window.MathJax")
1010+
1011+
1012+
@pytest.mark.parametrize("is_eager", [True, False])
1013+
def test_grva014_load_mathjax(dash_dcc, is_eager):
1014+
app = Dash(__name__, eager_loading=is_eager)
1015+
1016+
gravity = "$F=\\frac{Gm_1m_2}{r^2}$"
1017+
1018+
app.layout = html.Div(
1019+
[
1020+
html.Button("Add Second MathJax", id="btn"),
1021+
dcc.Graph(
1022+
mathjax=False,
1023+
id="gd",
1024+
figure={
1025+
"data": [{"y": [3, 1, 2]}],
1026+
"layout": {"title": {"text": gravity}},
1027+
},
1028+
),
1029+
html.Div("initial", id="out"),
1030+
]
1031+
)
1032+
1033+
@app.callback(
1034+
Output("out", "children"), Input("btn", "n_clicks"), prevent_initial_call=True
1035+
)
1036+
def add_math(n):
1037+
return dcc.Graph(
1038+
mathjax=True,
1039+
id="gd2",
1040+
figure={
1041+
"data": [{"y": [3, 1, 2]}],
1042+
"layout": {"title": {"text": gravity}},
1043+
},
1044+
)
1045+
1046+
dash_dcc.start_server(app)
1047+
1048+
# Initial state: no MathJax loaded or rendered, unformatted text is shown
1049+
dash_dcc.wait_for_contains_text("#gd .gtitle", gravity)
1050+
dash_dcc.wait_for_no_elements("#gd .gtitle-math")
1051+
assert not dash_dcc.driver.execute_script("return !!window.MathJax")
1052+
1053+
btn = dash_dcc.find_element("#btn")
1054+
btn.click()
1055+
1056+
# One click: MathJax is loaded and rendered on the second, unformatted text is gone
1057+
1058+
dash_dcc.wait_for_element("#gd2 .gtitle-math")
1059+
assert gravity not in dash_dcc._get_element("#gd2 .gtitle").text
1060+
assert dash_dcc.driver.execute_script("return !!window.MathJax")

components/dash-core-components/tests/integration/markdown/test_markdown.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ def test_mkdw007_load_mathjax(dash_dcc, is_eager):
211211
html.Button("Add Second MathJax", id="btn"),
212212
dcc.Markdown(
213213
f"""
214-
# No Math Rendering Here! {gravity}
215-
""",
214+
# No Math Rendering Here! {gravity}
215+
""",
216216
id="md",
217+
mathjax=False,
217218
),
218219
html.Div("initial", id="out"),
219220
]

0 commit comments

Comments
 (0)