Skip to content

Commit 03b969e

Browse files
committed
modernize some flaky tests
1 parent 9186fb7 commit 03b969e

File tree

5 files changed

+153
-204
lines changed

5 files changed

+153
-204
lines changed

package-lock.json

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/input/test_input_types.py renamed to tests/integration/input/test_input_basics.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import dash_core_components as dcc
66
import dash_html_components as html
77

8-
ALLOWING_TYPES = (
8+
ALLOWED_TYPES = (
99
"text",
1010
"number",
1111
"password",
@@ -18,22 +18,22 @@
1818
)
1919

2020

21-
def test_intp001_all_types(dash_dcc):
21+
def test_inbs001_all_types(dash_dcc):
2222
def input_id(type_):
2323
return "input_{}".format(type_)
2424

2525
app = dash.Dash(__name__)
2626
app.layout = html.Div(
2727
[
2828
dcc.Input(id=input_id(_), type=_, placeholder="input type {}".format(_))
29-
for _ in ALLOWING_TYPES
29+
for _ in ALLOWED_TYPES
3030
]
3131
+ [html.Div(id="output")]
3232
)
3333

3434
@app.callback(
3535
Output("output", "children"),
36-
[Input(input_id(_), "value") for _ in ALLOWING_TYPES],
36+
[Input(input_id(_), "value") for _ in ALLOWED_TYPES],
3737
)
3838
def cb_render(*vals):
3939
return " | ".join((val for val in vals if val))
@@ -46,12 +46,23 @@ def cb_render(*vals):
4646

4747
dash_dcc.percy_snapshot("intp001 - init state")
4848

49-
for atype in ALLOWING_TYPES[:-1]:
49+
for atype in ALLOWED_TYPES[:-1]:
5050
dash_dcc.find_element("#input_{}".format(atype)).send_keys(
5151
"test intp001 - input[{}]".format(atype)
5252
)
5353

5454
with pytest.raises(WebDriverException):
5555
dash_dcc.find_element("#input_hidden").send_keys("no interaction")
5656

57-
dash_dcc.percy_snapshot("intp001 - callback output rendering")
57+
dash_dcc.percy_snapshot("inbs001 - callback output rendering")
58+
59+
60+
def test_inbs002_user_class(dash_dcc):
61+
app = dash.Dash(__name__, assets_folder="../../assets")
62+
63+
app.layout = html.Div(className="test-input-css", children=[dcc.Input()])
64+
65+
dash_dcc.start_server(app)
66+
67+
dash_dcc.find_element(".test-input-css")
68+
dash_dcc.percy_snapshot("styled input - width: 100%, border-color: hotpink")

tests/integration/location/test_location_callback.py

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22
import dash
3-
from dash.dependencies import Input, Output
3+
from dash.dependencies import Input, Output, State
44
import dash_core_components as dcc
55
import dash_html_components as html
66

7+
from dash.testing.wait import until
8+
79

810
@pytest.mark.DCC774
911
def test_loca001_callbacks(dash_dcc):
@@ -23,3 +25,116 @@ def update_path(path):
2325
dash_dcc.start_server(app)
2426

2527
dash_dcc.wait_for_text_to_equal("#div", "/")
28+
29+
30+
def test_loca002_location_link(dash_dcc):
31+
app = dash.Dash(__name__)
32+
33+
app.layout = html.Div(
34+
[
35+
html.Div(id="waitfor"),
36+
dcc.Location(id="test-location", refresh=False),
37+
dcc.Link(
38+
html.Button("I am a clickable button"),
39+
id="test-link",
40+
href="/test/pathname",
41+
),
42+
dcc.Link(
43+
html.Button("I am a clickable hash button"),
44+
id="test-link-hash",
45+
href="#test",
46+
),
47+
dcc.Link(
48+
html.Button("I am a clickable search button"),
49+
id="test-link-search",
50+
href="?testQuery=testValue",
51+
refresh=False,
52+
),
53+
html.Button("I am a magic button that updates pathname", id="test-button"),
54+
html.A("link to click", href="/test/pathname/a", id="test-a"),
55+
html.A("link to click", href="#test-hash", id="test-a-hash"),
56+
html.A("link to click", href="?queryA=valueA", id="test-a-query"),
57+
html.Div(id="test-pathname", children=[]),
58+
html.Div(id="test-hash", children=[]),
59+
html.Div(id="test-search", children=[]),
60+
]
61+
)
62+
63+
@app.callback(
64+
Output("test-pathname", "children"), Input("test-location", "pathname")
65+
)
66+
def update_test_pathname(pathname):
67+
return pathname
68+
69+
@app.callback(Output("test-hash", "children"), Input("test-location", "hash"))
70+
def update_test_hash(hash_val):
71+
return hash_val or ""
72+
73+
@app.callback(Output("test-search", "children"), Input("test-location", "search"))
74+
def update_test_search(search):
75+
return search or ""
76+
77+
@app.callback(
78+
Output("test-location", "pathname"),
79+
Input("test-button", "n_clicks"),
80+
State("test-location", "pathname"),
81+
)
82+
def update_pathname(n_clicks, current_pathname):
83+
if n_clicks is not None:
84+
return "/new/pathname"
85+
86+
return current_pathname
87+
88+
dash_dcc.start_server(app)
89+
90+
dash_dcc.percy_snapshot("link -- location")
91+
92+
# Check that link updates pathname
93+
dash_dcc.find_element("#test-link").click()
94+
until(
95+
lambda: dash_dcc.driver.current_url.replace("http://localhost:8050", "")
96+
== "/test/pathname",
97+
3,
98+
)
99+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/test/pathname")
100+
101+
# Check that hash is updated in the Location
102+
dash_dcc.find_element("#test-link-hash").click()
103+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/test/pathname")
104+
dash_dcc.wait_for_text_to_equal("#test-hash", "#test")
105+
dash_dcc.percy_snapshot("link -- /test/pathname#test")
106+
107+
# Check that search is updated in the Location
108+
# note that this goes through href and therefore wipes the hash
109+
dash_dcc.find_element("#test-link-search").click()
110+
dash_dcc.wait_for_text_to_equal("#test-search", "?testQuery=testValue")
111+
dash_dcc.wait_for_text_to_equal("#test-hash", "")
112+
dash_dcc.percy_snapshot("link -- /test/pathname?testQuery=testValue")
113+
114+
# Check that pathname is updated through a Button click via props
115+
dash_dcc.find_element("#test-button").click()
116+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/new/pathname")
117+
dash_dcc.wait_for_text_to_equal("#test-search", "?testQuery=testValue")
118+
dash_dcc.percy_snapshot("link -- /new/pathname?testQuery=testValue")
119+
120+
# Check that pathname is updated through an a tag click via props
121+
dash_dcc.find_element("#test-a").click()
122+
123+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/test/pathname/a")
124+
dash_dcc.wait_for_text_to_equal("#test-search", "")
125+
dash_dcc.wait_for_text_to_equal("#test-hash", "")
126+
dash_dcc.percy_snapshot("link -- /test/pathname/a")
127+
128+
# Check that hash is updated through an a tag click via props
129+
dash_dcc.find_element("#test-a-hash").click()
130+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/test/pathname/a")
131+
dash_dcc.wait_for_text_to_equal("#test-search", "")
132+
dash_dcc.wait_for_text_to_equal("#test-hash", "#test-hash")
133+
dash_dcc.percy_snapshot("link -- /test/pathname/a#test-hash")
134+
135+
# Check that hash is updated through an a tag click via props
136+
dash_dcc.find_element("#test-a-query").click()
137+
dash_dcc.wait_for_text_to_equal("#test-pathname", "/test/pathname/a")
138+
dash_dcc.wait_for_text_to_equal("#test-search", "?queryA=valueA")
139+
dash_dcc.wait_for_text_to_equal("#test-hash", "")
140+
dash_dcc.percy_snapshot("link -- /test/pathname/a?queryA=valueA")

0 commit comments

Comments
 (0)