Skip to content

Commit 94123b3

Browse files
committed
adding test for reordering children and making sure the setProps still goes to the right place
1 parent 3702683 commit 94123b3

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import time
2+
from dash import Dash, Input, Output, html, dcc, State, ALL
3+
4+
5+
class Section:
6+
def __init__(self, idx):
7+
self.idx = idx
8+
self.options = ["A", "B", "C"]
9+
10+
@property
11+
def section_id(self):
12+
return {"type": "section-container", "id": self.idx}
13+
14+
@property
15+
def dropdown_id(self):
16+
return {"type": "dropdown", "id": self.idx}
17+
18+
@property
19+
def swap_btn_id(self):
20+
return {"type": "swap-btn", "id": self.idx}
21+
22+
def get_layout(self) -> html.Div:
23+
layout = html.Div(
24+
id=self.section_id,
25+
children=[
26+
html.H1(f"I am section {self.idx}"),
27+
html.Button(
28+
"SWAP",
29+
id=self.swap_btn_id,
30+
n_clicks=0,
31+
className=f"swap_button_{self.idx}",
32+
),
33+
dcc.Dropdown(
34+
self.options,
35+
id=self.dropdown_id,
36+
multi=True,
37+
value=[],
38+
className=f"dropdown_{self.idx}",
39+
),
40+
],
41+
)
42+
return layout
43+
44+
45+
def test_roc001_reorder_children(dash_duo):
46+
app = Dash()
47+
48+
app.layout = html.Div(
49+
id="main-app", children=[*[Section(idx=i).get_layout() for i in range(2)]]
50+
)
51+
52+
@app.callback(
53+
Output("main-app", "children"),
54+
Input({"type": "swap-btn", "id": ALL}, "n_clicks"),
55+
State("main-app", "children"),
56+
prevent_initial_call=True,
57+
)
58+
def swap_button_action(n_clicks, children):
59+
if any(n > 0 for n in n_clicks):
60+
return children[::-1]
61+
62+
dash_duo.start_server(app)
63+
64+
for i in range(2):
65+
dash_duo.wait_for_text_to_equal("h1", f"I am section {i}")
66+
dash_duo.wait_for_text_to_equal(
67+
f".dropdown_{i} .Select-multi-value-wrapper", "Select..."
68+
)
69+
dash_duo.find_element(f".dropdown_{i}").click()
70+
dash_duo.find_element(f".dropdown_{i} .VirtualizedSelectOption").click()
71+
dash_duo.wait_for_text_to_equal(
72+
f".dropdown_{i} .Select-multi-value-wrapper", "×A\n "
73+
)
74+
dash_duo.find_element(f".dropdown_{i}").click()
75+
dash_duo.find_element(f".dropdown_{i} .VirtualizedSelectOption").click()
76+
dash_duo.wait_for_text_to_equal(
77+
f".dropdown_{i} .Select-multi-value-wrapper", "×A\n ×B\n "
78+
)
79+
dash_duo.find_element(f".dropdown_{i}").click()
80+
dash_duo.find_element(f".dropdown_{i} .VirtualizedSelectOption").click()
81+
dash_duo.wait_for_text_to_equal(
82+
f".dropdown_{i} .Select-multi-value-wrapper", "×A\n ×B\n ×C\n "
83+
)
84+
dash_duo.find_element(f".swap_button_{i}").click()

0 commit comments

Comments
 (0)