Skip to content

Commit 0d96c02

Browse files
authored
Merge pull request #2787 from plotly/add-more-tests
Add regressions tests
2 parents 93b513d + d10670f commit 0d96c02

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import MyPersistedComponentNested from './components/MyPersistedComponentNested'
77
import StyledComponent from './components/StyledComponent';
88
import WidthComponent from './components/WidthComponent';
99
import ComponentAsProp from './components/ComponentAsProp';
10+
11+
import DrawCounter from './components/DrawCounter';
1012
import AddPropsComponent from "./components/AddPropsComponent";
1113
import ReceivePropsComponent from "./components/ReceivePropsComponent";
1214

15+
1316
export {
1417
AsyncComponent,
1518
CollapseComponent,
@@ -20,6 +23,7 @@ export {
2023
StyledComponent,
2124
WidthComponent,
2225
ComponentAsProp,
26+
DrawCounter,
2327
AddPropsComponent,
2428
ReceivePropsComponent
2529
};

tests/integration/multi_page/test_pages_layout.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import dash
3-
from dash import Dash, Input, State, dcc, html
3+
from dash import Dash, Input, State, dcc, html, Output
44
from dash.dash import _ID_LOCATION
55
from dash.exceptions import NoLayoutException
66

@@ -237,6 +237,35 @@ def test_pala005_routing_inputs(dash_duo, clear_pages_state):
237237
dash_duo.wait_for_text_to_equal("#contents", "Le hash dit: #123")
238238

239239

240+
def test_pala006_pages_external_library(dash_duo):
241+
import dash_test_components as dt
242+
243+
app = Dash(use_pages=True, pages_folder="")
244+
245+
@app.callback(
246+
Output("out", "children"),
247+
Input("button", "n_clicks"),
248+
prevent_initial_call=True,
249+
)
250+
def on_click(n_clicks):
251+
return f"Button has been clicked {n_clicks} times"
252+
253+
dash.register_page(
254+
"page",
255+
path="/",
256+
layout=html.Div(
257+
[
258+
dt.DelayedEventComponent(id="button"),
259+
html.Div("The button has not been clicked yet", id="out"),
260+
]
261+
),
262+
)
263+
264+
dash_duo.start_server(app)
265+
dash_duo.wait_for_element("#button").click()
266+
dash_duo.wait_for_text_to_equal("#out", "Button has been clicked 1 times")
267+
268+
240269
def get_app_title_description():
241270
app = Dash(
242271
__name__, use_pages=True, title="App Title", description="App Description"
@@ -252,7 +281,7 @@ def get_app_title_description():
252281
return app
253282

254283

255-
def test_pala006_app_title_discription(dash_duo, clear_pages_state):
284+
def test_pala007_app_title_discription(dash_duo, clear_pages_state):
256285
dash_duo.start_server(get_app_title_description())
257286

258287
assert dash.page_registry["home"]["title"] == "App Title"
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)