forked from plotly/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_basic_operations.py
444 lines (294 loc) · 11.9 KB
/
test_basic_operations.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import dash
from utils import read_write_modes
from dash.dash_table import DataTable
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
import pytest
url = "https://github.com/plotly/datasets/raw/master/" "26k-consumer-complaints.csv"
rawDf = pd.read_csv(url)
df = rawDf.to_dict("records")
def get_app(props=dict()):
app = dash.Dash(__name__)
baseProps = dict(
id="table",
columns=[{"name": i, "id": i} for i in rawDf.columns],
data=df,
editable=True,
filter_action="native",
fixed_columns={"headers": True},
fixed_rows={"headers": True},
page_action="native",
row_deletable=True,
row_selectable=True,
sort_action="native",
)
baseProps.update(props)
app.layout = DataTable(**baseProps)
return app
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst001_get_cell(test, props):
test.start_server(get_app(props))
target = test.table("table")
assert target.cell(0, 0).get_text() == "0"
target.paging.next.click()
assert target.cell(0, 0).get_text() == "250"
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst002_select_all_text(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 1).click()
assert target.cell(0, 1).get_text() == test.get_selected_text()
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/50
@pytest.mark.parametrize("props", [dict(editable=False), dict(editable=True)])
def test_tbst003_edit_on_enter(test, props):
test.start_server(get_app(props))
target = test.table("table")
initial_text = target.cell(249, 0).get_text()
target.cell(249, 0).click()
test.send_keys("abc" + Keys.ENTER)
if props.get("editable"):
assert target.cell(249, 0).get_text() == "abc"
else:
assert target.cell(249, 0).get_text() == initial_text
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/107
@pytest.mark.parametrize("props", [dict(editable=False), dict(editable=True)])
def test_tbst004_edit_on_tab(test, props):
test.start_server(get_app(props))
target = test.table("table")
initial_text = target.cell(249, 0).get_text()
target.cell(249, 0).click()
test.send_keys("abc" + Keys.TAB)
if props.get("editable"):
assert target.cell(249, 0).get_text() == "abc"
else:
assert target.cell(249, 0).get_text() == initial_text
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", [dict(editable=False), dict(editable=True)])
def test_tbst005_edit_last_row_on_click_outside(test, props):
test.start_server(get_app(props))
target = test.table("table")
initial_text = target.cell(249, 0).get_text()
target.cell(249, 0).click()
test.send_keys("abc")
target.cell(248, 0).click()
if props.get("editable"):
assert target.cell(249, 0).get_text() == "abc"
else:
assert target.cell(249, 0).get_text() == initial_text
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/141
def test_tbst006_focused_arrow_left(test):
test.start_server(get_app())
target = test.table("table")
target.cell(249, 1).click()
test.send_keys("abc" + Keys.LEFT)
assert target.cell(249, 1).get_text() == "abc"
assert target.cell(249, 0).is_focused()
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/141
def test_tbst007_active_focused_arrow_right(test):
test.start_server(get_app())
target = test.table("table")
target.cell(249, 0).click()
test.send_keys("abc" + Keys.RIGHT)
assert target.cell(249, 0).get_text() == "abc"
assert target.cell(249, 1).is_focused()
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/141
def test_tbst008_active_focused_arrow_up(test):
test.start_server(get_app())
target = test.table("table")
target.cell(249, 0).click()
test.send_keys("abc" + Keys.UP)
assert target.cell(249, 0).get_text() == "abc"
assert target.cell(248, 0).is_focused()
assert test.get_log_errors() == []
# https://github.com/plotly/dash-table/issues/141
def test_tbst009_active_focused_arrow_down(test):
test.start_server(get_app())
target = test.table("table")
target.cell(249, 0).click()
test.send_keys("abc" + Keys.DOWN)
assert target.cell(249, 0).get_text() == "abc"
assert target.cell(249, 0).is_focused()
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst010_active_with_dblclick(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 0).double_click()
assert target.cell(0, 0).is_active()
assert target.cell(0, 0).get_text() == test.get_selected_text()
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst011_delete_row(test, props):
test.start_server(get_app(props))
target = test.table("table")
text01 = target.cell(1, 0).get_text()
target.row(0).delete()
assert target.cell(0, 0).get_text() == text01
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst012_delete_sorted_row(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
text01 = target.cell(1, 0).get_text()
target.row(0).delete()
assert target.cell(0, 0).get_text() == text01
assert test.get_log_errors() == []
@pytest.mark.parametrize(
"props",
read_write_modes
+ [
dict(editable=False, row_deletable=False),
],
)
def test_tbst013_select_row(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.row(0).select()
assert target.row(0).is_selected()
assert test.get_log_errors() == []
@pytest.mark.parametrize(
"props",
read_write_modes
+ [
dict(editable=False, row_deletable=False),
],
)
def test_tbst014_selected_sorted_row(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
target.row(0).select()
assert target.row(0).is_selected()
assert test.get_log_errors() == []
@pytest.mark.parametrize(
"props",
read_write_modes
+ [
dict(editable=False, row_deletable=False),
],
)
def test_tbst015_selected_row_respects_sort(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.row(0).select()
assert target.row(0).is_selected()
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
assert not target.row(0).is_selected()
target.column(rawDf.columns[0]).sort() # DESC -> None
assert target.row(0).is_selected()
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst016_delete_cell(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 1).click()
test.send_keys(Keys.BACKSPACE)
test.send_keys(Keys.ENTER)
assert target.cell(0, 1).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.skip(reason="https://github.com/plotly/dash-table/issues/700")
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst017_delete_cell_updates_while_selected(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 1).click()
test.send_keys(Keys.BACKSPACE)
assert target.cell(0, 1).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst018_delete_multiple_cells(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 1).click()
with test.hold(Keys.SHIFT):
ActionChains(test.driver).send_keys(Keys.DOWN).send_keys(Keys.RIGHT).perform()
ActionChains(test.driver).send_keys(Keys.BACKSPACE).send_keys(Keys.ENTER).perform()
for row in range(2):
for col in range(1, 3):
assert target.cell(row, col).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.skip(reason="https://github.com/plotly/dash-table/issues/700")
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst019_delete_multiple_cells_while_selected(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.cell(0, 1).click()
with test.hold(Keys.SHIFT):
ActionChains(test.driver).send_keys(Keys.DOWN).send_keys(Keys.RIGHT).perform()
ActionChains(test.driver).send_keys(Keys.BACKSPACE).perform()
for row in range(2):
for col in range(1, 3):
assert target.cell(row, col).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst020_sorted_table_delete_cell(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
target.cell(0, 1).click()
test.send_keys(Keys.BACKSPACE)
test.send_keys(Keys.ENTER)
assert target.cell(0, 1).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.skip(reason="https://github.com/plotly/dash-table/issues/700")
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst021_sorted_table_delete_cell_updates_while_selected(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
target.cell(0, 1).click()
test.send_keys(Keys.BACKSPACE)
assert target.cell(0, 1).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst022_sorted_table_delete_multiple_cells(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
target.cell(0, 1).click()
with test.hold(Keys.SHIFT):
ActionChains(test.driver).send_keys(Keys.DOWN).send_keys(Keys.RIGHT).perform()
ActionChains(test.driver).send_keys(Keys.BACKSPACE).send_keys(Keys.ENTER).perform()
for row in range(2):
for col in range(1, 3):
assert target.cell(row, col).get_text() == ""
assert test.get_log_errors() == []
@pytest.mark.skip(reason="https://github.com/plotly/dash-table/issues/700")
@pytest.mark.parametrize("props", read_write_modes)
def test_tbst023_sorted_table_delete_multiple_cells_while_selected(test, props):
test.start_server(get_app(props))
target = test.table("table")
target.column(rawDf.columns[0]).sort() # None -> ASC
target.column(rawDf.columns[0]).sort() # ASC -> DESC
target.cell(0, 1).click()
with test.hold(Keys.SHIFT):
ActionChains(test.driver).send_keys(Keys.DOWN).send_keys(Keys.RIGHT).perform()
ActionChains(test.driver).send_keys(Keys.BACKSPACE).perform()
for row in range(2):
for col in range(1, 3):
assert target.cell(row, col).get_text() == ""
assert test.get_log_errors() == []
def test_tbst024_row_selectable_filter_action(test):
app = dash.Dash(__name__)
app.layout = DataTable(
id="test-table",
row_selectable="single",
filter_action="native",
)
test.start_server(app)
test.wait_for_element("#test-table")
assert test.get_log_errors() == []