@@ -88,50 +88,70 @@ def update_output(n_clicks):
88
88
89
89
def test_click_prev (self ):
90
90
call_count = Value ('i' , 0 )
91
+ timestamp_1 = Value ('d' , - 5 )
92
+ timestamp_2 = Value ('d' , - 5 )
91
93
92
94
app = dash .Dash ()
93
95
app .layout = html .Div ([
94
96
html .Div (id = 'container' ),
95
- html .Button ('Click' , id = 'button-1' , n_clicks = 0 , n_clicks_previous = 0 ),
96
- html .Button ('Click' , id = 'button-2' , n_clicks = 0 , n_clicks_previous = 0 )
97
+ html .Button ('Click' , id = 'button-1' , n_clicks = 0 , n_clicks_timestamp = - 1 ),
98
+ html .Button ('Click' , id = 'button-2' , n_clicks = 0 , n_clicks_timestamp = - 1 )
97
99
])
98
100
99
101
@app .callback (
100
102
Output ('container' , 'children' ),
101
103
[Input ('button-1' , 'n_clicks' ),
102
- Input ('button-1' , 'n_clicks_previous ' ),
104
+ Input ('button-1' , 'n_clicks_timestamp ' ),
103
105
Input ('button-2' , 'n_clicks' ),
104
- Input ('button-2' , 'n_clicks_previous ' )])
106
+ Input ('button-2' , 'n_clicks_timestamp ' )])
105
107
def update_output (* args ):
108
+ print (args )
106
109
call_count .value += 1
107
- return '{}, {}, {}, {}' .format (* args )
110
+ timestamp_1 .value = args [1 ]
111
+ timestamp_2 .value = args [3 ]
112
+ return '{}, {}' .format (args [0 ], args [2 ])
108
113
109
114
self .startServer (app )
110
115
111
116
self .wait_for_element_by_css_selector ('#container' )
112
117
time .sleep (2 )
113
- self .wait_for_text_to_equal (
114
- '#container' , '0, 0, 0, 0' )
118
+ self .wait_for_text_to_equal ('#container' , '0, 0' )
119
+ self .assertEqual (timestamp_1 .value , - 1 )
120
+ self .assertEqual (timestamp_2 .value , - 1 )
115
121
self .assertEqual (call_count .value , 1 )
116
122
self .snapshot ('button initialization 1' )
117
123
118
124
self .driver .find_element_by_css_selector ('#button-1' ).click ()
119
125
time .sleep (2 )
120
- self .wait_for_text_to_equal (
121
- '#container' , '0, 1, 0, 0' )
126
+ self .wait_for_text_to_equal ('#container' , '1, 0' )
127
+ print (timestamp_1 .value )
128
+ print ((time .time () - (24 * 60 * 60 )) * 1000 )
129
+ self .assertTrue (
130
+ timestamp_1 .value >
131
+ ((time .time () - (24 * 60 * 60 )) * 1000 ))
132
+ self .assertEqual (timestamp_2 .value , - 1 )
122
133
self .assertEqual (call_count .value , 2 )
123
134
self .snapshot ('button-1 click' )
135
+ prev_timestamp_1 = timestamp_1 .value
124
136
125
137
self .driver .find_element_by_css_selector ('#button-2' ).click ()
126
138
time .sleep (2 )
127
- self .wait_for_text_to_equal (
128
- '#container' , '1, 1, 0, 1' )
139
+ self .wait_for_text_to_equal ('#container' , '1, 1' )
140
+ self .assertEqual (timestamp_1 .value , prev_timestamp_1 )
141
+ self .assertTrue (
142
+ timestamp_2 .value >
143
+ ((time .time () - 24 * 60 * 60 ) * 1000 ))
129
144
self .assertEqual (call_count .value , 3 )
130
145
self .snapshot ('button-2 click' )
146
+ prev_timestamp_2 = timestamp_2 .value
131
147
132
148
self .driver .find_element_by_css_selector ('#button-2' ).click ()
133
149
time .sleep (2 )
134
- self .wait_for_text_to_equal (
135
- '#container' , '1, 1, 1, 2' )
150
+ self .wait_for_text_to_equal ('#container' , '1, 2' )
151
+ self .assertEqual (timestamp_1 .value , prev_timestamp_1 )
152
+ self .assertTrue (
153
+ timestamp_2 .value >
154
+ prev_timestamp_2 )
155
+ self .assertTrue (timestamp_2 .value > timestamp_1 .value )
136
156
self .assertEqual (call_count .value , 4 )
137
157
self .snapshot ('button-2 click again' )
0 commit comments