|
1 | 1 | import dash_ag_grid as dag |
2 | | -from dash import Dash, html, dcc, Input, Output, State |
| 2 | +from dash import Dash, html, dcc, Input, Output, State, Patch |
3 | 3 | import plotly.express as px |
4 | 4 | from . import utils |
5 | 5 | import json |
| 6 | +from selenium.webdriver.common.by import By |
| 7 | +from dash.testing.wait import until |
| 8 | + |
6 | 9 |
|
7 | 10 | df = px.data.medals_wide() |
8 | 11 |
|
@@ -84,3 +87,38 @@ def test_el002_event_listener(dash_duo): |
84 | 87 | # Test left click. |
85 | 88 | grid.get_cell(1, 2).click() |
86 | 89 | assert dash_duo.find_element('#log').text == "rawr" |
| 90 | + |
| 91 | +def test_el003_event_listener(dash_duo): |
| 92 | + app = Dash(__name__, suppress_callback_exceptions=True) |
| 93 | + app.layout = html.Div([ |
| 94 | + dag.AgGrid(id='grid', |
| 95 | + columnDefs=[{'field': 'test'}], |
| 96 | + rowData=[{'test': '1'}], |
| 97 | + eventListeners={'cellClicked': ['TestEvent(params, setEventData)']} |
| 98 | + ), |
| 99 | + html.Div(id='output', children=[]) |
| 100 | + ] |
| 101 | + ) |
| 102 | + |
| 103 | + @app.callback( |
| 104 | + Output('output', 'children'), |
| 105 | + Input('grid', 'eventData') |
| 106 | + ) |
| 107 | + def show_event_data(v): |
| 108 | + children = Patch() |
| 109 | + if v: |
| 110 | + children.append(html.Div(json.dumps(v))) |
| 111 | + return children |
| 112 | + |
| 113 | + dash_duo.start_server(app) |
| 114 | + |
| 115 | + grid = utils.Grid(dash_duo, "grid") |
| 116 | + grid.wait_for_cell_text(0, 0, "1") |
| 117 | + |
| 118 | + for i in range(5): |
| 119 | + grid.get_cell(0, 0).click() |
| 120 | + |
| 121 | + # Assert that the output element has children |
| 122 | + until(lambda: len(dash_duo.find_element("#output").find_elements(By.XPATH, "*")) == (i + 1), timeout=3) |
| 123 | + |
| 124 | + |
0 commit comments