@@ -21,6 +21,18 @@ def findAsyncPlotlyJs(scripts):
21
21
return script
22
22
23
23
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
+
24
36
@pytest .mark .parametrize ("is_eager" , [True , False ])
25
37
def test_grva001_candlestick (dash_dcc , is_eager ):
26
38
app = Dash (__name__ , eager_loading = is_eager )
@@ -847,3 +859,77 @@ def graph_dims():
847
859
assert graph_dims () == responsive_size
848
860
849
861
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 () == []
0 commit comments