Skip to content

Add regressions tests #2787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 19, 2024
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
15 changes: 15 additions & 0 deletions @plotly/dash-test-components/src/components/DrawCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";

const DrawCounter = (props) => {
const [count, setCount] = useState(0);
useEffect(() => {
setCount(count + 1);
}, [props]);
return <div id={props.id}>{count}</div>;
};

DrawCounter.propTypes = {
id: PropTypes.string,
};
export default DrawCounter;
4 changes: 4 additions & 0 deletions @plotly/dash-test-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import MyPersistedComponentNested from './components/MyPersistedComponentNested'
import StyledComponent from './components/StyledComponent';
import WidthComponent from './components/WidthComponent';
import ComponentAsProp from './components/ComponentAsProp';

import DrawCounter from './components/DrawCounter';
import AddPropsComponent from "./components/AddPropsComponent";
import ReceivePropsComponent from "./components/ReceivePropsComponent";


export {
AsyncComponent,
CollapseComponent,
Expand All @@ -20,6 +23,7 @@ export {
StyledComponent,
WidthComponent,
ComponentAsProp,
DrawCounter,
AddPropsComponent,
ReceivePropsComponent
};
33 changes: 31 additions & 2 deletions tests/integration/multi_page/test_pages_layout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import dash
from dash import Dash, Input, State, dcc, html
from dash import Dash, Input, State, dcc, html, Output
from dash.dash import _ID_LOCATION
from dash.exceptions import NoLayoutException

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


def test_pala006_pages_external_library(dash_duo):
import dash_test_components as dt

app = Dash(use_pages=True, pages_folder="")

@app.callback(
Output("out", "children"),
Input("button", "n_clicks"),
prevent_initial_call=True,
)
def on_click(n_clicks):
return f"Button has been clicked {n_clicks} times"

dash.register_page(
"page",
path="/",
layout=html.Div(
[
dt.DelayedEventComponent(id="button"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's dt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just tests components:
import dash_test_components as dt

html.Div("The button has not been clicked yet", id="out"),
]
),
)

dash_duo.start_server(app)
dash_duo.wait_for_element("#button").click()
dash_duo.wait_for_text_to_equal("#out", "Button has been clicked 1 times")


def get_app_title_description():
app = Dash(
__name__, use_pages=True, title="App Title", description="App Description"
Expand All @@ -252,7 +281,7 @@ def get_app_title_description():
return app


def test_pala006_app_title_discription(dash_duo, clear_pages_state):
def test_pala007_app_title_discription(dash_duo, clear_pages_state):
dash_duo.start_server(get_app_title_description())

assert dash.page_registry["home"]["title"] == "App Title"
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/renderer/test_redraw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import time
from dash import Dash, Input, Output, html

import dash_test_components as dt


def test_rdraw001_redraw(dash_duo):
app = Dash()

app.layout = html.Div(
[
html.Div(
dt.DrawCounter(id="counter"),
id="redrawer",
),
html.Button("redraw", id="redraw"),
]
)

@app.callback(
Output("redrawer", "children"),
Input("redraw", "n_clicks"),
prevent_initial_call=True,
)
def on_click(_):
return dt.DrawCounter(id="counter")

dash_duo.start_server(app)

dash_duo.wait_for_text_to_equal("#counter", "1")
dash_duo.find_element("#redraw").click()
dash_duo.wait_for_text_to_equal("#counter", "2")
time.sleep(1)
dash_duo.wait_for_text_to_equal("#counter", "2")