1
1
from multiprocessing import Value
2
2
import dash_html_components as html
3
3
import dash_core_components as dcc
4
- from dash import Dash
4
+ import dash_flow_example
5
+ import dash
5
6
from dash .dependencies import Input , Output
6
7
from dash .exceptions import PreventUpdate
7
8
from .IntegrationTests import IntegrationTests
@@ -18,7 +19,7 @@ def wait_for_element_by_id(id):
18
19
self .wait_for_element_by_id = wait_for_element_by_id
19
20
20
21
def test_simple_callback (self ):
21
- app = Dash (__name__ )
22
+ app = dash . Dash (__name__ )
22
23
app .layout = html .Div ([
23
24
dcc .Input (
24
25
id = 'input' ,
@@ -65,14 +66,14 @@ def update_output(value):
65
66
)
66
67
67
68
assert_clean_console (self )
68
-
69
+
69
70
def test_aborted_callback (self ):
70
71
"""Raising PreventUpdate prevents update and triggering dependencies"""
71
-
72
+
72
73
initial_input = 'initial input'
73
74
initial_output = 'initial output'
74
-
75
- app = Dash (__name__ )
75
+
76
+ app = dash . Dash (__name__ )
76
77
app .layout = html .Div ([
77
78
dcc .Input (id = 'input' , value = initial_input ),
78
79
html .Div (initial_output , id = 'output1' ),
@@ -81,7 +82,7 @@ def test_aborted_callback(self):
81
82
82
83
callback1_count = Value ('i' , 0 )
83
84
callback2_count = Value ('i' , 0 )
84
-
85
+
85
86
@app .callback (Output ('output1' , 'children' ), [Input ('input' , 'value' )])
86
87
def callback1 (value ):
87
88
callback1_count .value = callback1_count .value + 1
@@ -99,7 +100,7 @@ def callback2(value):
99
100
input_ .clear ()
100
101
input_ .send_keys ('x' )
101
102
output1 = self .wait_for_element_by_id ('output1' )
102
- output2 = self .wait_for_element_by_id ('output2' )
103
+ output2 = self .wait_for_element_by_id ('output2' )
103
104
104
105
# callback1 runs twice (initial page load and through send_keys)
105
106
self .assertEqual (callback1_count .value , 2 )
@@ -110,5 +111,43 @@ def callback2(value):
110
111
# double check that output1 and output2 children were not updated
111
112
self .assertEqual (output1 .text , initial_output )
112
113
self .assertEqual (output2 .text , initial_output )
113
-
114
+
114
115
assert_clean_console (self )
116
+
117
+ self .percy_snapshot (name = 'aborted' )
118
+
119
+ def test_flow_component (self ):
120
+ app = dash .Dash ()
121
+
122
+ app .layout = html .Div ([
123
+ dash_flow_example .ExampleReactComponent (
124
+ id = 'react' ,
125
+ value = 'my-value' ,
126
+ label = 'react component'
127
+ ),
128
+ dash_flow_example .ExampleFlowComponent (
129
+ id = 'flow' ,
130
+ value = 'my-value' ,
131
+ label = 'flow component'
132
+ ),
133
+ html .Hr (),
134
+ html .Div (id = 'output' )
135
+ ])
136
+
137
+ @app .callback (Output ('output' , 'children' ),
138
+ [Input ('react' , 'value' ), Input ('flow' , 'value' )])
139
+ def display_output (react_value , flow_value ):
140
+ return html .Div ([
141
+ 'You have entered {} and {}' .format (react_value , flow_value ),
142
+ html .Hr (),
143
+ html .Label ('Flow Component Docstring' ),
144
+ html .Pre (dash_flow_example .ExampleFlowComponent .__doc__ ),
145
+ html .Hr (),
146
+ html .Label ('React PropTypes Component Docstring' ),
147
+ html .Pre (dash_flow_example .ExampleReactComponent .__doc__ ),
148
+ html .Div (id = 'waitfor' )
149
+ ])
150
+
151
+ self .startServer (app )
152
+ self .wait_for_element_by_id ('waitfor' )
153
+ self .percy_snapshot (name = 'flowtype' )
0 commit comments