Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 56cfddc

Browse files
committed
test existence of undo/redo toolbar and buttons in all cases
1 parent e1941e1 commit 56cfddc

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_render.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ def click_redo(self):
224224
redo = self.wait_for_element_by_css_selector(redo_selector)
225225
redo.click()
226226

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+
227236
def test_undo_redo(self):
228237
app = Dash(__name__, show_undo_redo=True)
229238
app.layout = html.Div([dcc.Input(id='a'), html.Div(id='b')])
@@ -238,18 +247,44 @@ def set_b(a):
238247
a.send_keys('xyz')
239248

240249
self.wait_for_text_to_equal('#b', 'xyz')
250+
self.check_undo_redo_exist(True, False)
241251

242252
self.click_undo()
243253
self.wait_for_text_to_equal('#b', 'xy')
254+
self.check_undo_redo_exist(True, True)
244255

245256
self.click_undo()
246257
self.wait_for_text_to_equal('#b', 'x')
258+
self.check_undo_redo_exist(True, True)
247259

248260
self.click_redo()
249261
self.wait_for_text_to_equal('#b', 'xy')
262+
self.check_undo_redo_exist(True, True)
250263

251264
self.percy_snapshot(name='undo-redo')
252265

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+
253288
def test_array_of_falsy_child(self):
254289
app = Dash(__name__)
255290
app.layout = html.Div(id='nully-wrapper', children=[0])

0 commit comments

Comments
 (0)