Skip to content

Commit 91b9bdb

Browse files
committed
add mathjax tests
1 parent 10fa649 commit 91b9bdb

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ def findAsyncPlotlyJs(scripts):
2121
return script
2222

2323

24+
def findAsyncMathJax(scripts):
25+
for script in scripts:
26+
if "dash_core_components/async-mathjax" in script.get_attribute("src"):
27+
return script
28+
29+
30+
def findSyncMathJax(scripts):
31+
for script in scripts:
32+
if "dash_core_components/mathjax" in script.get_attribute("src"):
33+
return script
34+
35+
2436
@pytest.mark.parametrize("is_eager", [True, False])
2537
def test_grva001_candlestick(dash_dcc, is_eager):
2638
app = Dash(__name__, eager_loading=is_eager)
@@ -847,3 +859,77 @@ def graph_dims():
847859
assert graph_dims() == responsive_size
848860

849861
assert dash_dcc.get_logs() == []
862+
863+
864+
def test_grva010_external_mathjax_prevents_lazy(dash_dcc):
865+
app = Dash(
866+
__name__,
867+
eager_loading=False,
868+
external_scripts=["https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js"],
869+
)
870+
871+
app.layout = html.Div(id="div", children=[html.Button(id="btn")])
872+
873+
@app.callback(Output("div", "children"), [Input("btn", "n_clicks")])
874+
def load_chart(n_clicks):
875+
if n_clicks is None:
876+
raise PreventUpdate
877+
878+
return dcc.Graph(mathjax=True, id="output", figure={"data": [{"y": [3, 1, 2]}]})
879+
880+
dash_dcc.start_server(
881+
app,
882+
debug=True,
883+
use_reloader=False,
884+
use_debugger=True,
885+
dev_tools_hot_reload=False,
886+
)
887+
888+
# Give time for the async dependency to be requested (if any)
889+
time.sleep(2)
890+
891+
scripts = dash_dcc.driver.find_elements(By.CSS_SELECTOR, "script")
892+
assert findSyncMathJax(scripts) is None
893+
assert findAsyncMathJax(scripts) is None
894+
895+
dash_dcc.find_element("#btn").click()
896+
897+
# Give time for the async dependency to be requested (if any)
898+
time.sleep(2)
899+
900+
scripts = dash_dcc.driver.find_elements(By.CSS_SELECTOR, "script")
901+
assert findSyncMathJax(scripts) is None
902+
assert findAsyncMathJax(scripts) is None
903+
904+
assert dash_dcc.get_logs() == []
905+
906+
907+
def test_grva011_without_mathjax(dash_dcc):
908+
app = Dash(__name__, eager_loading=False, assets_folder="../../assets")
909+
910+
app.layout = html.Div([dcc.Graph(id="output", figure={"data": [{"y": [3, 1, 2]}]})])
911+
912+
dash_dcc.start_server(app)
913+
dash_dcc.percy_snapshot("grva011 - graph without mathjax")
914+
assert dash_dcc.get_logs() == []
915+
916+
917+
def test_grva012_with_mathjax(dash_dcc):
918+
app = Dash(__name__, eager_loading=False, assets_folder="../../assets")
919+
920+
app.layout = html.Div(
921+
[
922+
dcc.Graph(
923+
mathjax=True,
924+
id="output",
925+
figure={
926+
"data": [{"y": [3, 1, 2]}],
927+
"layout": {"title": {"text": "Equation: $E=mc^2$"}},
928+
},
929+
)
930+
]
931+
)
932+
933+
dash_dcc.start_server(app)
934+
dash_dcc.percy_snapshot("grva012 - graph with mathjax")
935+
assert dash_dcc.get_logs() == []

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,56 @@ def test_mkdw002_dcclink(dash_dcc):
9393
dash_dcc.percy_snapshot("mkdw002 - markdowns display")
9494

9595
assert dash_dcc.get_logs() == []
96+
97+
98+
def test_mkdw003_without_mathjax(dash_dcc):
99+
app = Dash(__name__, eager_loading=False, assets_folder="../../assets")
100+
101+
app.layout = html.Div(
102+
[
103+
dcc.Markdown("# No MathJax: Apple: $2, Orange: $3"),
104+
]
105+
)
106+
107+
dash_dcc.start_server(app)
108+
dash_dcc.percy_snapshot("mkdw003 - markdown without mathjax")
109+
assert dash_dcc.get_logs() == []
110+
111+
112+
def test_mkdw004_inline_mathjax(dash_dcc):
113+
app = Dash(__name__, eager_loading=False, assets_folder="../../assets")
114+
115+
app.layout = html.Div(
116+
[
117+
dcc.Markdown("# h1 tag with inline MathJax: $E=mc^2$", mathjax=True),
118+
]
119+
)
120+
121+
dash_dcc.start_server(app)
122+
dash_dcc.percy_snapshot("mkdw004 - markdown inline mathjax")
123+
assert dash_dcc.get_logs() == []
124+
125+
126+
def test_mkdw005_block_mathjax(dash_dcc):
127+
app = Dash(__name__, eager_loading=False, assets_folder="../../assets")
128+
129+
app.layout = html.Div(
130+
[
131+
dcc.Markdown(
132+
"""
133+
## h2 tag with MathJax block:
134+
$$
135+
\\frac{1}{(\\sqrt{\\phi \\sqrt{5}}-\\phi) e^{\\frac25 \\pi}} =
136+
1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}
137+
{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } }
138+
$$
139+
## Next line.
140+
""",
141+
mathjax=True,
142+
),
143+
]
144+
)
145+
146+
dash_dcc.start_server(app)
147+
dash_dcc.percy_snapshot("mkdw005 - markdown block mathjax")
148+
assert dash_dcc.get_logs() == []

0 commit comments

Comments
 (0)