Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 245ba00

Browse files
author
Marc-André Rivet
committed
multi table tests cypress -> selenium
1 parent 2c01ab5 commit 245ba00

File tree

3 files changed

+95
-50
lines changed

3 files changed

+95
-50
lines changed

tests/cypress/tests/standalone/select_row_column_test.ts

-50
This file was deleted.

tests/selenium/conftest.py

+27
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,28 @@ def get(self, row=0):
139139
def hide(self, row=0):
140140
self.get(row).find_element_by_css_selector(".column-header--hide").click()
141141

142+
@preconditions(_validate_row)
143+
def is_selected(self, row=0):
144+
return self.mixin.driver.execute_script(
145+
"""
146+
return document.querySelector('#{} {} tbody tr:nth-of-type({}) th.dash-header[data-dash-column="{}"]:not(.phantom-cell) .column-header--select input').checked;
147+
""".format(
148+
self.id, self.state, row + 1, self.col_id
149+
)
150+
)
151+
142152
@preconditions(_validate_row)
143153
def move_to(self, row=0):
144154
ac = ActionChains(self.mixin.driver)
145155
ac.move_to_element(self.get(row))
146156
return ac.perform()
147157

158+
@preconditions(_validate_row)
159+
def select(self, row=0):
160+
self.get(row).find_element_by_css_selector(
161+
".column-header--select input"
162+
).click()
163+
148164
@preconditions(_validate_row)
149165
def sort(self, row=0):
150166
self.get(row).find_element_by_css_selector(".column-header--sort").click()
@@ -325,6 +341,17 @@ def _wait_for_table(self, id, state=_ANY):
325341
def table(self, id):
326342
return DataTableFacade(id, self)
327343

344+
def get_table_ids(self):
345+
return self.driver.execute_script(
346+
"""
347+
return Array.from(
348+
document.querySelectorAll('.dash-spreadsheet-container')
349+
).map(
350+
e => e.parentElement.getAttribute('id')
351+
)
352+
"""
353+
)
354+
328355
def copy(self):
329356
with self.hold(Keys.CONTROL):
330357
self.send_keys("c")
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import dash
2+
from dash.testing import wait
3+
4+
from dash_table import DataTable
5+
from dash_html_components import Div
6+
7+
import pandas as pd
8+
9+
url = "https://github.com/plotly/datasets/raw/master/" "26k-consumer-complaints.csv"
10+
rawDf = pd.read_csv(url, nrows=100)
11+
df = rawDf.to_dict("records")
12+
13+
14+
def get_app(props=dict()):
15+
app = dash.Dash(__name__)
16+
17+
baseProps = dict(
18+
columns=[dict(name=i, id=i, selectable=True) for i in rawDf.columns],
19+
data=df,
20+
editable=True,
21+
filter_action="native",
22+
fixed_columns={"headers": True},
23+
fixed_rows={"headers": True},
24+
page_action="native",
25+
row_deletable=True,
26+
row_selectable=True,
27+
sort_action="native",
28+
)
29+
30+
baseProps.update(props)
31+
32+
app.layout = Div([DataTable(**baseProps), DataTable(**baseProps)])
33+
34+
return app
35+
36+
37+
def test_tbmu001_select_row(test):
38+
test.start_server(get_app())
39+
40+
wait.until(lambda: len(test.get_table_ids()) == 2, 3)
41+
ids = test.get_table_ids()
42+
43+
table1 = test.table(ids[0])
44+
table2 = test.table(ids[1])
45+
46+
table1.row(0).select()
47+
table2.row(1).select()
48+
49+
assert table1.row(0).is_selected()
50+
assert table2.row(1).is_selected()
51+
52+
assert test.get_log_errors() == []
53+
54+
55+
def test_tbmu002_select_column(test):
56+
test.start_server(get_app(dict(column_selectable="single")))
57+
58+
wait.until(lambda: len(test.get_table_ids()) == 2, 3)
59+
ids = test.get_table_ids()
60+
61+
table1 = test.table(ids[0])
62+
table2 = test.table(ids[1])
63+
64+
table1.column("Complaint ID").select()
65+
table2.column("Product").select()
66+
67+
assert table1.column("Complaint ID").is_selected()
68+
assert table2.column("Product").is_selected()

0 commit comments

Comments
 (0)