Skip to content

Commit 0988888

Browse files
committed
adding test for temp component with ExternalWrapper
1 parent 9dd243d commit 0988888

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44

5-
const ExternalComponent = ({ id, text, input_id, extra_component }) => {
5+
const ExternalComponent = ({ id, text, input_id, extra_component, extra_component_temp }) => {
66
const ctx = window.dash_component_api.useDashContext();
77
const ExternalWrapper = window.dash_component_api.ExternalWrapper;
8-
98
return (
109
<div id={id}>
1110
{text && <ExternalWrapper
@@ -18,13 +17,15 @@ const ExternalComponent = ({ id, text, input_id, extra_component }) => {
1817
id: input_id
1918
}
2019
}}
21-
componentPath={[...ctx.componentPath, 'external']}
20+
componentPath={[JSON.stringify(ctx.componentPath), 'text']}
21+
temp={true}
2222
/>}
2323
{
2424
extra_component &&
2525
<ExternalWrapper
2626
component={extra_component}
27-
componentPath={[...ctx.componentPath, 'extra']}
27+
componentPath={[...ctx.componentPath, 'props', 'extra_component']}
28+
temp={extra_component_temp}
2829
/>}
2930
</div>
3031
)
@@ -39,6 +40,7 @@ ExternalComponent.propTypes = {
3940
namespace: PropTypes.string,
4041
props: PropTypes.object,
4142
}),
43+
extra_component_temp: PropTypes.bool,
4244
};
4345

4446
export default ExternalComponent;

tests/integration/renderer/test_external_component.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,51 @@ def click(*_):
5959
dash_duo.wait_for_text_to_equal("#out", "clicked")
6060

6161
assert dash_duo.get_logs() == []
62+
63+
def test_rext002_render_external_component_temp(dash_duo):
64+
app = Dash()
65+
app.layout = html.Div(
66+
[
67+
dcc.Tabs(
68+
[
69+
dcc.Tab(label="Tab 1", children=[
70+
ExternalComponent(
71+
id="ext",
72+
extra_component={
73+
"type": "Div",
74+
"namespace": "dash_html_components",
75+
"props": {
76+
"id": "extra",
77+
"children": [
78+
html.Div("extra children", id={"type": "extra", "index": 1})
79+
],
80+
},
81+
},
82+
extra_component_temp=True
83+
),
84+
]),
85+
dcc.Tab(label='Tab 2', children=[
86+
ExternalComponent(
87+
id="without-id",
88+
text="without-id",
89+
),
90+
])
91+
]
92+
),
93+
]
94+
)
95+
96+
dash_duo.start_server(app)
97+
dash_duo.wait_for_text_to_equal("#extra", "extra children")
98+
99+
dash_duo.find_element('.tab:nth-child(2)').click()
100+
assert dash_duo.find_element("#without-id > input").get_attribute('value') == "without-id"
101+
102+
dash_duo.find_element('.tab').click()
103+
dash_duo.find_element("#ext")
104+
assert len(dash_duo.find_elements('#ext > *')) == 0, "extra component should be removed"
105+
106+
dash_duo.find_element('.tab:nth-child(2)').click()
107+
assert dash_duo.find_element("#without-id > input").get_attribute('value') == "without-id"
108+
109+
assert dash_duo.get_logs() == []

0 commit comments

Comments
 (0)