Skip to content

Commit d35a73b

Browse files
chriddypAkronix
authored andcommitted
add test of plotly#44
1 parent e9b8ff1 commit d35a73b

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/test_render.py

+71
Original file line numberDiff line numberDiff line change
@@ -1579,3 +1579,74 @@ def dropdown_2(value, session_id):
15791579
self.assertEqual(call_counts['dropdown_2'].value, 1)
15801580

15811581
assert_clean_console(self)
1582+
1583+
def test_callbacks_triggered_on_generated_output(self):
1584+
app = dash.Dash()
1585+
app.config['suppress_callback_exceptions'] = True
1586+
1587+
call_counts = {
1588+
'tab1': Value('i', 0),
1589+
'tab2': Value('i', 0)
1590+
}
1591+
1592+
app.layout = html.Div([
1593+
dcc.Dropdown(
1594+
id='outer-controls',
1595+
options=[{'label': i, 'value': i} for i in ['a', 'b']],
1596+
value='a'
1597+
),
1598+
dcc.RadioItems(
1599+
options=[
1600+
{'label': 'Tab 1', 'value': 1},
1601+
{'label': 'Tab 2', 'value': 2}
1602+
],
1603+
value=1,
1604+
id='tabs',
1605+
),
1606+
html.Div(id='tab-output')
1607+
])
1608+
1609+
1610+
@app.callback(Output('tab-output', 'children'), [Input('tabs', 'value')])
1611+
def display_content(value):
1612+
return html.Div([
1613+
html.Div(id='tab-{}-output'.format(value))
1614+
])
1615+
1616+
@app.callback(Output('tab-1-output', 'children'),
1617+
[Input('outer-controls', 'value')])
1618+
def display_tab1_output(value):
1619+
call_counts['tab1'].value += 1
1620+
return 'You have selected "{}"'.format(value)
1621+
1622+
@app.callback(Output('tab-2-output', 'children'),
1623+
[Input('outer-controls', 'value')])
1624+
def display_tab2_output(value):
1625+
call_counts['tab2'].value += 1
1626+
return 'You have selected "{}"'.format(value)
1627+
1628+
1629+
self.startServer(app)
1630+
self.wait_for_element_by_id('tab-output')
1631+
time.sleep(2)
1632+
1633+
self.assertEqual(call_counts['tab1'].value, 1)
1634+
self.assertEqual(call_counts['tab2'].value, 0)
1635+
wait_for(lambda: (
1636+
self.driver.find_element_by_id('tab-output').text ==
1637+
'You have selected "1"'
1638+
))
1639+
1640+
(self.driver.find_elements_by_css_selector(
1641+
'input[type="radio"]'
1642+
)[1]).click()
1643+
time.sleep(2)
1644+
1645+
wait_for(lambda: (
1646+
self.driver.find_element_by_id('tab-output').text ==
1647+
'You have selected "2"'
1648+
))
1649+
self.assertEqual(call_counts['tab1'].value, 1)
1650+
self.assertEqual(call_counts['tab2'].value, 1)
1651+
1652+
assert_clean_console(self)

0 commit comments

Comments
 (0)