Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions tests/test_column_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,10 @@ def test_toggle_column_visibility(dash_duo):
app = Dash(__name__)

app.layout = html.Div([
dcc.Dropdown(
dcc.Button(
"hide/show col b",
id="select-columns",
value=list(data.columns),
options=[{"label": col, "value": col} for col in data.columns],
multi=True,
n_clicks=0,
),
dag.AgGrid(
id="ag-grid",
Expand All @@ -545,18 +544,12 @@ def test_toggle_column_visibility(dash_duo):

@app.callback(
Output("ag-grid", "columnDefs"),
Input("select-columns", "value"),
Input("select-columns", "n_clicks"),
)
def toggle_column_visibility(selected_columns):
if not selected_columns:
return no_update
return [
{
"headerName": col_name,
"field": col_name,
"hide": col_name not in selected_columns,
}
for col_name in data.columns
def toggle_column_visibility(n):
return [
{"headerName": "a", "field": "a", "hide": False},
{"headerName": "b", "field": "b", "hide": n % 2 == 0},
]

dash_duo.start_server(app)
Expand All @@ -566,23 +559,20 @@ def toggle_column_visibility(selected_columns):

grid.wait_for_cell_text(0, 0, "1")

# Hide column 'b'
dropdown = dash_duo.find_element("#select-columns")
dropdown.click()
option_b = dash_duo.find_element('label:nth-child(2) > span.dash-options-list-option-wrapper > input')
option_b.click()
button = dash_duo.find_element("#select-columns")
button.click()
time.sleep(1)

# Only column 'a' should be visible

grid_headers = dash_duo.find_elements("div.ag-header-cell-label")
header_texts = [h.text for h in grid_headers]
assert "a" in header_texts
assert "b" not in header_texts
assert "a" in header_texts
assert "b" in header_texts

# Show both columns again
option_b.click()
# Col b not visable
button.click()
time.sleep(1)
grid_headers = dash_duo.find_elements("div.ag-header-cell-label")
header_texts = [h.text for h in grid_headers]
assert "a" in header_texts
assert "b" in header_texts
assert "b" not in header_texts
15 changes: 5 additions & 10 deletions tests/test_custom_aggFunc_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
import dash
from dash import html, dcc
from . import utils
from dash.testing.wait import until
import requests
import pandas as pd

df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)
data=df.to_dict("records")

def test_ca001_custom_aggFunc_functions(dash_duo):
app = dash.Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
# Row group by country and by year is enabled.
{
Expand Down Expand Up @@ -86,10 +85,6 @@ def test_ca001_custom_aggFunc_functions(dash_duo):
def test_ca002_custom_aggFunc_functions(dash_duo):
app = dash.Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
# Row group by country and by year is enabled.
{
Expand Down
32 changes: 12 additions & 20 deletions tests/test_custom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

from . import utils

df = px.data.election()
default_display_cols = ["district_id"]
other_cols = ["district", "winner"]

df = pd.concat([df, pd.DataFrame({"district": ["test"]})])

df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)
rowData = df.to_dict('records')

def test_fi002_custom_filter(dash_duo):
app = Dash(__name__)

df = px.data.election()
default_display_cols = ["district_id"]
other_cols = ["district", "winner"]

df = pd.concat([df, pd.DataFrame({"district": ["test"]})])

app.layout = html.Div(
[
dag.AgGrid(
Expand Down Expand Up @@ -68,10 +72,6 @@ def test_fi002_custom_filter(dash_duo):
def test_fi003_custom_filter(dash_duo):
app = Dash(__name__)

df = pd.read_json('https://www.ag-grid.com/example-assets/olympic-winners.json', convert_dates=False)

rowData = df.to_dict('records')

columnDefs = [
{'field': 'age', 'filter': 'agNumberColumnFilter'},
{'field': 'country', 'minWidth': 150},
Expand Down Expand Up @@ -128,10 +128,6 @@ def test_fi003_custom_filter(dash_duo):
def test_fi003_custom_filter_v34(dash_duo):
app = Dash(__name__)

df = pd.read_json('https://www.ag-grid.com/example-assets/olympic-winners.json', convert_dates=False)

rowData = df.to_dict('records')

columnDefs = [
{'field': 'age', 'filter': 'agNumberColumnFilter'},
{'field': 'country', 'minWidth': 150},
Expand Down Expand Up @@ -190,7 +186,6 @@ def test_fi003_custom_filter_v34(dash_duo):
def test_fi004_custom_filter(dash_duo):
app = Dash(__name__)

df = pd.read_json('https://www.ag-grid.com/example-assets/olympic-winners.json', convert_dates=False)

columnDefs = [
{
Expand Down Expand Up @@ -220,7 +215,7 @@ def test_fi004_custom_filter(dash_duo):
[
dag.AgGrid(
id="grid",
rowData=df.to_dict("records"),
rowData=rowData,
columnDefs=columnDefs,
columnSize="sizeToFit",
defaultColDef={"filter": True, "floatingFilter": True}
Expand Down Expand Up @@ -301,9 +296,6 @@ def test_fi005_custom_filter(dash_duo):
def test_fi006_custom_filter(dash_duo):
app = Dash(__name__)

df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)

columnDefs = [
{"field": "athlete",
Expand Down Expand Up @@ -346,7 +338,7 @@ def test_fi006_custom_filter(dash_duo):
id="date-filter-example",
enableEnterpriseModules=True,
columnDefs=columnDefs,
rowData=df.to_dict("records"),
rowData=rowData,
defaultColDef={"flex": 1, "minWidth": 150, "floatingFilter": True},
dashGridOptions={"animateRows": False}
),
Expand Down
9 changes: 4 additions & 5 deletions tests/test_selected_rows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dash_ag_grid as dag
from dash import Dash, html, dcc, Output, Input, no_update
import requests
from . import utils
import pandas as pd
import time
Expand All @@ -9,9 +8,9 @@
def test_sr001_selected_rows(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()
df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)

columnDefs = [
{"field": "athlete"},
Expand All @@ -33,7 +32,7 @@ def test_sr001_selected_rows(dash_duo):
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=data,
rowData=df.to_dict("records"),
columnSize="sizeToFit",
defaultColDef={"resizable": True, "sortable": True, "filter": True},
dashGridOptions={"rowSelection": "single"},
Expand Down
12 changes: 7 additions & 5 deletions tests/test_selection_buttons.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import dash_ag_grid as dag
from dash import Dash, html, dcc, Output, Input, no_update, ctx
import requests
from . import utils
import pandas as pd

df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
)
data=df.to_dict("records")



def test_sb001_selection_buttons(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
{"field": "athlete"},
{"field": "age"},
Expand Down
32 changes: 11 additions & 21 deletions tests/test_sizing_buttons.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import pytest
import dash_ag_grid as dag
from dash import Dash, html, dcc, Output, Input, no_update, ctx, State
import requests
from . import utils
import json
from dash.testing.wait import until
import time
import pandas as pd



df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/ag-grid/olympic-winners.csv"
).head(100)
data=df.to_dict("records")

def test_sb001_sizing_buttons(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
{"field": "athlete"},
{"field": "age"},
Expand All @@ -34,7 +36,7 @@ def test_sb001_sizing_buttons(dash_duo):
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=data[:100],
rowData=data,
columnSize="sizeToFit",
defaultColDef={
"resizable": True,
Expand Down Expand Up @@ -123,10 +125,6 @@ def selected(state, oldState, opts):
def test_sb002_sizing_buttons(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
{"field": "athlete"},
{"field": "age"},
Expand All @@ -146,7 +144,7 @@ def test_sb002_sizing_buttons(dash_duo):
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=data[:100],
rowData=data,
columnSize="autoSize",
defaultColDef={
"resizable": True,
Expand Down Expand Up @@ -235,10 +233,6 @@ def selected(state):
def test_sb003_sizing_buttons(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
{"field": "athlete"},
{"field": "age"},
Expand All @@ -258,7 +252,7 @@ def test_sb003_sizing_buttons(dash_duo):
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=data[:100],
rowData=data,
columnSize="sizeToFit",
defaultColDef={
"resizable": True,
Expand Down Expand Up @@ -346,10 +340,6 @@ def selected(state, oldState, opts):
def test_sb004_sizing_buttons(dash_duo):
app = Dash(__name__)

data = requests.get(
r"https://www.ag-grid.com/example-assets/olympic-winners.json"
).json()

columnDefs = [
{"field": "athlete"},
{"field": "age"},
Expand All @@ -369,7 +359,7 @@ def test_sb004_sizing_buttons(dash_duo):
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=data[:100],
rowData=data,
columnSize="autoSize",
defaultColDef={
"resizable": True,
Expand Down
Loading