This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathtest_sliders.py
243 lines (206 loc) · 7.85 KB
/
test_sliders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_core_components as dcc
def test_slsl001_always_visible_slider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Slider(
id="slider",
min=0,
max=20,
step=1,
value=5,
tooltip={"always_visible": True},
),
html.Div(id="out"),
]
)
@app.callback(Output("out", "children"), [Input("slider", "value")])
def update_output(value):
return "You have selected {}".format(value)
dash_dcc.start_server(app)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 5")
slider = dash_dcc.find_element("#slider")
dash_dcc.click_at_coord_fractions(slider, 0.5, 0.25)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 10")
dash_dcc.click_at_coord_fractions(slider, 0.75, 0.25)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 15")
def test_slsl002_always_visible_rangeslider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
style={"width": "400px"},
children=[
dcc.RangeSlider(
id="rangeslider",
min=0,
max=20,
step=1,
value=[5, 15],
tooltip={"always_visible": True},
),
html.Div(id="out"),
],
)
@app.callback(Output("out", "children"), [Input("rangeslider", "value")])
def update_output(rng):
return "You have selected {}-{}".format(*rng)
dash_dcc.start_server(app)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 5-15")
slider = dash_dcc.find_element("#rangeslider")
dash_dcc.click_at_coord_fractions(slider, 0.15, 0.25)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 2-15")
dash_dcc.click_at_coord_fractions(slider, 0.5, 0.25)
dash_dcc.wait_for_text_to_equal("#out", "You have selected 2-10")
def test_slsl003_out_of_range_marks_slider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Slider(
min=0, max=5, marks={i: "Label {}".format(i) for i in range(-1, 10)}
)
]
)
dash_dcc.start_server(app)
assert len(dash_dcc.find_elements("span.rc-slider-mark-text")) == 6
def test_slsl004_out_of_range_marks_rangeslider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.RangeSlider(
min=0, max=5, marks={i: "Label {}".format(i) for i in range(-1, 10)}
)
]
)
dash_dcc.start_server(app)
assert len(dash_dcc.find_elements("span.rc-slider-mark-text")) == 6
def test_slsl005_slider_tooltip(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div(
[
html.Div(
dcc.Slider(
min=0,
max=100,
value=65,
tooltip={"always_visible": True, "placement": "top"},
),
style=dict(height=100),
),
html.Div(
dcc.Slider(
min=0,
max=100,
value=65,
tooltip={"always_visible": True, "placement": "top"},
),
style=dict(height=100),
),
html.Div(
dcc.Slider(
min=0,
max=100,
value=65,
tooltip={"always_visible": True, "placement": "top"},
),
style=dict(height=100),
),
html.Div(
dcc.Slider(
min=0,
max=100,
value=65,
tooltip={"always_visible": True, "placement": "top"},
),
style=dict(height=100),
),
html.Div(
dcc.Slider(
id="test-slider",
min=0,
max=100,
value=65,
tooltip={"always_visible": True, "placement": "top"},
),
style=dict(height=100),
),
],
style=dict(maxHeight=300, overflowX="scroll"),
)
]
)
dash_dcc.start_server(app)
dash_dcc.wait_for_element("#test-slider")
dash_dcc.percy_snapshot(
"slider-make sure tooltips are only visible if parent slider is visible"
)
def test_slsl006_drag_value_slider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Slider(
id="slider",
min=0,
max=20,
step=1,
value=5,
tooltip={"always_visible": True},
),
html.Div(id="out-value"),
html.Div(id="out-drag-value"),
]
)
@app.callback(Output("out-drag-value", "children"), [Input("slider", "drag_value")])
def update_output(value):
return "You have dragged {}".format(value)
@app.callback(Output("out-value", "children"), [Input("slider", "value")])
def update_output(value):
return "You have selected {}".format(value)
dash_dcc.start_server(app)
slider = dash_dcc.find_element("#slider")
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 5")
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 5")
dash_dcc.click_and_hold_at_coord_fractions(slider, 0.25, 0.25)
dash_dcc.move_to_coord_fractions(slider, 0.75, 0.25)
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 15")
dash_dcc.move_to_coord_fractions(slider, 0.5, 0.25)
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 10")
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 5")
dash_dcc.release()
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 10")
def test_slsl007_drag_value_rangeslider(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.RangeSlider(
id="slider",
min=0,
max=20,
step=1,
value=(5, 15),
tooltip={"always_visible": True},
),
html.Div(id="out-value"),
html.Div(id="out-drag-value"),
]
)
@app.callback(Output("out-drag-value", "children"), [Input("slider", "drag_value")])
def update_output(value):
value = value or (None, None)
return "You have dragged {}-{}".format(*value)
@app.callback(Output("out-value", "children"), [Input("slider", "value")])
def update_output(value):
return "You have selected {}-{}".format(*value)
dash_dcc.start_server(app)
slider = dash_dcc.find_element("#slider")
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 5-15")
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 5-15")
dash_dcc.click_and_hold_at_coord_fractions(slider, 0.25, 0.25)
dash_dcc.move_to_coord_fractions(slider, 0.5, 0.25)
dash_dcc.wait_for_text_to_equal("#out-drag-value", "You have dragged 10-15")
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 5-15")
dash_dcc.release()
dash_dcc.wait_for_text_to_equal("#out-value", "You have selected 10-15")