@@ -224,6 +224,15 @@ def click_redo(self):
224
224
redo = self .wait_for_element_by_css_selector (redo_selector )
225
225
redo .click ()
226
226
227
+ def check_undo_redo_exist (self , has_undo , has_redo ):
228
+ selector = '._dash-undo-redo span div:last-child'
229
+ els = self .driver .find_elements_by_css_selector (selector )
230
+ texts = (['undo' ] if has_undo else []) + (['redo' ] if has_redo else [])
231
+
232
+ self .assertEqual (len (els ), len (texts ))
233
+ for el , text in zip (els , texts ):
234
+ self .assertEqual (el .text , text )
235
+
227
236
def test_undo_redo (self ):
228
237
app = Dash (__name__ , show_undo_redo = True )
229
238
app .layout = html .Div ([dcc .Input (id = 'a' ), html .Div (id = 'b' )])
@@ -238,18 +247,44 @@ def set_b(a):
238
247
a .send_keys ('xyz' )
239
248
240
249
self .wait_for_text_to_equal ('#b' , 'xyz' )
250
+ self .check_undo_redo_exist (True , False )
241
251
242
252
self .click_undo ()
243
253
self .wait_for_text_to_equal ('#b' , 'xy' )
254
+ self .check_undo_redo_exist (True , True )
244
255
245
256
self .click_undo ()
246
257
self .wait_for_text_to_equal ('#b' , 'x' )
258
+ self .check_undo_redo_exist (True , True )
247
259
248
260
self .click_redo ()
249
261
self .wait_for_text_to_equal ('#b' , 'xy' )
262
+ self .check_undo_redo_exist (True , True )
250
263
251
264
self .percy_snapshot (name = 'undo-redo' )
252
265
266
+ self .click_undo ()
267
+ self .click_undo ()
268
+ self .wait_for_text_to_equal ('#b' , '' )
269
+ self .check_undo_redo_exist (False , True )
270
+
271
+ def test_no_undo_redo (self ):
272
+ app = Dash (__name__ )
273
+ app .layout = html .Div ([dcc .Input (id = 'a' ), html .Div (id = 'b' )])
274
+
275
+ @app .callback (Output ('b' , 'children' ), [Input ('a' , 'value' )])
276
+ def set_b (a ):
277
+ return a
278
+
279
+ self .startServer (app )
280
+
281
+ a = self .wait_for_element_by_css_selector ('#a' )
282
+ a .send_keys ('xyz' )
283
+
284
+ self .wait_for_text_to_equal ('#b' , 'xyz' )
285
+ toolbar = self .driver .find_elements_by_css_selector ('._dash-undo-redo' )
286
+ self .assertEqual (len (toolbar ), 0 )
287
+
253
288
def test_array_of_falsy_child (self ):
254
289
app = Dash (__name__ )
255
290
app .layout = html .Div (id = 'nully-wrapper' , children = [0 ])
0 commit comments