Skip to content

Commit

Permalink
Flow integration test (#212)
Browse files Browse the repository at this point in the history
* add flowtype integration test

sanity check for #207

* white space

* add screenshot test to aborted example
  • Loading branch information
chriddyp authored Feb 22, 2018
1 parent 8478942 commit 44ac465
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dash_core_components>=0.4.0
dash_html_components>=0.5.0
dash_flow_example==0.0.3
dash_renderer
percy
selenium
Expand Down
57 changes: 48 additions & 9 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from multiprocessing import Value
import dash_html_components as html
import dash_core_components as dcc
from dash import Dash
import dash_flow_example
import dash
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from .IntegrationTests import IntegrationTests
Expand All @@ -18,7 +19,7 @@ def wait_for_element_by_id(id):
self.wait_for_element_by_id = wait_for_element_by_id

def test_simple_callback(self):
app = Dash(__name__)
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(
id='input',
Expand Down Expand Up @@ -65,14 +66,14 @@ def update_output(value):
)

assert_clean_console(self)

def test_aborted_callback(self):
"""Raising PreventUpdate prevents update and triggering dependencies"""

initial_input = 'initial input'
initial_output = 'initial output'
app = Dash(__name__)

app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(id='input', value=initial_input),
html.Div(initial_output, id='output1'),
Expand All @@ -81,7 +82,7 @@ def test_aborted_callback(self):

callback1_count = Value('i', 0)
callback2_count = Value('i', 0)

@app.callback(Output('output1', 'children'), [Input('input', 'value')])
def callback1(value):
callback1_count.value = callback1_count.value + 1
Expand All @@ -99,7 +100,7 @@ def callback2(value):
input_.clear()
input_.send_keys('x')
output1 = self.wait_for_element_by_id('output1')
output2 = self.wait_for_element_by_id('output2')
output2 = self.wait_for_element_by_id('output2')

# callback1 runs twice (initial page load and through send_keys)
self.assertEqual(callback1_count.value, 2)
Expand All @@ -110,5 +111,43 @@ def callback2(value):
# double check that output1 and output2 children were not updated
self.assertEqual(output1.text, initial_output)
self.assertEqual(output2.text, initial_output)

assert_clean_console(self)

self.percy_snapshot(name='aborted')

def test_flow_component(self):
app = dash.Dash()

app.layout = html.Div([
dash_flow_example.ExampleReactComponent(
id='react',
value='my-value',
label='react component'
),
dash_flow_example.ExampleFlowComponent(
id='flow',
value='my-value',
label='flow component'
),
html.Hr(),
html.Div(id='output')
])

@app.callback(Output('output', 'children'),
[Input('react', 'value'), Input('flow', 'value')])
def display_output(react_value, flow_value):
return html.Div([
'You have entered {} and {}'.format(react_value, flow_value),
html.Hr(),
html.Label('Flow Component Docstring'),
html.Pre(dash_flow_example.ExampleFlowComponent.__doc__),
html.Hr(),
html.Label('React PropTypes Component Docstring'),
html.Pre(dash_flow_example.ExampleReactComponent.__doc__),
html.Div(id='waitfor')
])

self.startServer(app)
self.wait_for_element_by_id('waitfor')
self.percy_snapshot(name='flowtype')

0 comments on commit 44ac465

Please sign in to comment.