Skip to content

Commit 8a7b64c

Browse files
committed
Add redraw test.
1 parent b588e94 commit 8a7b64c

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { useState, useEffect } from "react";
2+
import PropTypes from "prop-types";
3+
4+
const DrawCounter = (props) => {
5+
const [count, setCount] = useState(0);
6+
useEffect(() => {
7+
setCount(count + 1);
8+
}, [props]);
9+
return <div id={props.id}>{count}</div>;
10+
};
11+
12+
DrawCounter.propTypes = {
13+
id: PropTypes.string,
14+
};
15+
export default DrawCounter;

@plotly/dash-test-components/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import MyPersistedComponentNested from './components/MyPersistedComponentNested'
77
import StyledComponent from './components/StyledComponent';
88
import WidthComponent from './components/WidthComponent';
99
import ComponentAsProp from './components/ComponentAsProp';
10+
import DrawCounter from './components/DrawCounter';
1011

1112
export {
1213
AsyncComponent,
@@ -18,4 +19,5 @@ export {
1819
StyledComponent,
1920
WidthComponent,
2021
ComponentAsProp,
22+
DrawCounter,
2123
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
from dash import Dash, Input, Output, html
3+
4+
import dash_test_components as dt
5+
6+
7+
def test_rdraw001_redraw(dash_duo):
8+
app = Dash()
9+
10+
app.layout = html.Div(
11+
[
12+
html.Div(
13+
dt.DrawCounter(id="counter"),
14+
id="redrawer",
15+
),
16+
html.Button("redraw", id="redraw"),
17+
]
18+
)
19+
20+
@app.callback(
21+
Output("redrawer", "children"),
22+
Input("redraw", "n_clicks"),
23+
prevent_initial_call=True,
24+
)
25+
def on_click(_):
26+
return dt.DrawCounter(id="counter")
27+
28+
dash_duo.start_server(app)
29+
30+
dash_duo.wait_for_text_to_equal("#counter", "1")
31+
dash_duo.find_element("#redraw").click()
32+
dash_duo.wait_for_text_to_equal("#counter", "2")
33+
time.sleep(1)
34+
dash_duo.wait_for_text_to_equal("#counter", "2")

0 commit comments

Comments
 (0)