This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtest_scrolling.py
More file actions
131 lines (100 loc) · 3.36 KB
/
Copy pathtest_scrolling.py
File metadata and controls
131 lines (100 loc) · 3.36 KB
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
import dash
import dash.testing.wait as wait
from dash_table import DataTable
import pandas as pd
import pytest
from selenium.webdriver.common.keys import Keys
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
base_props = dict(
id="table",
columns=[{"name": i, "id": i} for i in df.columns],
row_selectable="single",
row_deletable=True,
data=df.to_dict("records"),
editable=True,
fixed_rows={"headers": True, "data": 1},
style_cell=dict(width=150),
style_table=dict(width=500),
)
def get_margin(test):
return test.driver.execute_script(
"return parseFloat(getComputedStyle(document.querySelector('#table .cell-0-1')).marginLeft);"
)
def get_scroll(test):
return test.driver.execute_script(
"return document.querySelector('#table .row-1').scrollLeft;"
)
def scroll_by(test, value):
return test.driver.execute_script(
"document.querySelector('#table .row-1').scrollBy({}, 0);".format(value)
)
@pytest.mark.parametrize(
"fixed_rows",
[dict(fixed_rows=dict(headers=True)), dict(fixed_rows=dict(headers=True, data=1))],
)
@pytest.mark.parametrize(
"fixed_columns",
[
dict(),
dict(fixed_columns=dict(headers=True)),
dict(fixed_columns=dict(headers=True, data=1)),
],
)
@pytest.mark.parametrize(
"ops", [dict(), dict(row_selectable="single", row_deletable=True)]
)
def test_scrol001_fixed_alignment(test, fixed_rows, fixed_columns, ops):
props = {**base_props, **fixed_rows, **fixed_columns, **ops}
app = dash.Dash(__name__)
app.layout = DataTable(**props)
test.start_server(app)
target = test.table("table")
assert target.is_ready()
fixed_width = test.driver.execute_script(
"return parseFloat(getComputedStyle(document.querySelector('#table .cell-0-0')).width) || 0;"
)
assert -get_margin(test) == fixed_width
scroll_by(test, 200)
wait.until(
lambda: -get_margin(test) == fixed_width + 200, 3,
)
scroll_by(test, -200)
wait.until(
lambda: -get_margin(test) == fixed_width, 3,
)
@pytest.mark.parametrize(
"fixed_rows",
[dict(fixed_rows=dict(headers=True)), dict(fixed_rows=dict(headers=True, data=1))],
)
@pytest.mark.parametrize(
"fixed_columns",
[
dict(),
dict(fixed_columns=dict(headers=True)),
dict(fixed_columns=dict(headers=True, data=1)),
],
)
@pytest.mark.parametrize(
"ops", [dict(), dict(row_selectable="single", row_deletable=True)]
)
def test_scrol002_edit_navigate(test, fixed_rows, fixed_columns, ops):
props = {**base_props, **fixed_rows, **fixed_columns, **ops}
app = dash.Dash(__name__)
app.layout = DataTable(**props)
test.start_server(app)
target = test.table("table")
assert target.is_ready()
fixed_width = test.driver.execute_script(
"return parseFloat(getComputedStyle(document.querySelector('#table .cell-0-0')).width) || 0;"
)
scroll_by(test, 200)
# alignment is ok after editing a cell
target.cell(0, 3).click()
test.send_keys("abc" + Keys.ENTER)
wait.until(lambda: -get_margin(test) == fixed_width + get_scroll(test), 3)
# alignment is ok after navigating
test.send_keys(Keys.ARROW_DOWN)
test.send_keys(Keys.ARROW_UP)
wait.until(
lambda: -get_margin(test) == fixed_width + get_scroll(test), 3,
)