Skip to content

Commit 060fe3c

Browse files
committed
add test
1 parent 34b7185 commit 060fe3c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
from dash import Dash, Input, Output, dcc, html
3+
from selenium.common.exceptions import TimeoutException
4+
from selenium.webdriver.common.keys import Keys
5+
from selenium.webdriver.common.action_chains import ActionChains
6+
import time
7+
8+
def test_ddde001_dropdown_debounce(dash_duo):
9+
app = Dash(__name__)
10+
app.layout = html.Div(
11+
[
12+
dcc.Dropdown(
13+
id="dropdown",
14+
options=[
15+
{"label": "New York City", "value": "NYC"},
16+
{"label": "Montreal", "value": "MTL"},
17+
{"label": "San Francisco", "value": "SF"},
18+
],
19+
value=["MTL", "SF"],
20+
multi=True,
21+
closeOnSelect=False,
22+
debounce=True,
23+
),
24+
html.Div(id="dropdown-value-out", style={"height": "10px", "width": "10px"}),
25+
]
26+
)
27+
28+
@app.callback(
29+
Output("dropdown-value-out", "children"),
30+
Input("dropdown", "value"),
31+
)
32+
def update_value(val):
33+
return ", ".join(val)
34+
35+
dash_duo.start_server(app)
36+
37+
assert dash_duo.find_element("#dropdown-value-out").text == "MTL, SF"
38+
39+
dash_duo.find_element("#dropdown").click()
40+
41+
# deselect first item
42+
selected = dash_duo.find_elements(".dash-dropdown-options input[checked]")
43+
selected[0].click()
44+
45+
# UI should update immediately (local state updated)
46+
assert dash_duo.find_element("#dropdown-value").text == "San Francisco"
47+
48+
# Callback output should not change while dropdown is still open
49+
assert dash_duo.find_element("#dropdown-value-out").text == "MTL, SF"
50+
51+
# Close the dropdown (ESC simulates user dismiss)
52+
actions = ActionChains(dash_duo.driver)
53+
actions.send_keys(Keys.ESCAPE).perform()
54+
time.sleep(0.1)
55+
56+
# After closing, the callback output should be updated
57+
assert dash_duo.find_element("#dropdown-value-out").text == "SF"
58+
59+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)