Skip to content

Commit becaa66

Browse files
committed
Tests if dcc.Markdown is re-highlighted after being updated
1 parent d703e10 commit becaa66

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

components/dash-core-components/tests/integration/misc/test_markdown_highlight.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55

66
md_text = """```python
7+
print('hello, world!')
8+
```"""
9+
10+
new_md_text = """```python
711
import dash
812
print('hello, world!')
913
```"""
@@ -46,3 +50,32 @@ def trigger_md_rerender(nclicks):
4650
dash_dcc.wait_for_text_to_equal("#md-container code", "hljs override")
4751

4852
assert dash_dcc.get_logs() == []
53+
54+
55+
def test_msmh003_update_md(dash_dcc):
56+
app = Dash(__name__)
57+
app.layout = html.Div(
58+
[
59+
html.Button("Click", id="md-trigger"),
60+
dcc.Markdown(md_text, id="md"),
61+
]
62+
)
63+
64+
@app.callback(Output("md", "children"), [Input("md-trigger", "n_clicks")])
65+
def update_md(nclicks):
66+
if nclicks is not None and nclicks > 0:
67+
return new_md_text
68+
return md_text
69+
70+
dash_dcc.start_server(app)
71+
72+
# a highlighted node will have <span> children which are what color the text
73+
code = dash_dcc.wait_for_element("code[data-highlighted='yes']")
74+
assert len(code.find_elements_by_tag_name("span")) == 2
75+
76+
dash_dcc.find_element("#md-trigger").click()
77+
78+
code = dash_dcc.wait_for_element("code[data-highlighted='yes']")
79+
assert len(code.find_elements_by_tag_name("span")) == 3
80+
81+
assert dash_dcc.get_logs() == []

0 commit comments

Comments
 (0)