Skip to content
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

Flow integration test #212

Merged
merged 7 commits into from
Feb 22, 2018
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
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')