1
0
Эх сурвалжийг харах

adding table tests for adding rows and clicking

Rodja Trappe 2 жил өмнө
parent
commit
bb83498e07
1 өөрчлөгдсөн 32 нэмэгдсэн , 0 устгасан
  1. 32 0
      tests/test_table.py

+ 32 - 0
tests/test_table.py

@@ -18,3 +18,35 @@ def test_update_table(screen: Screen):
     table.options['rowData'][0]['age'] = 42
     table.update()
     screen.should_contain('42')
+
+
+def test_add_row(screen: Screen):
+    table = ui.table({
+        'columnDefs': [{'field': 'name'}, {'field': 'age'}],
+        'rowData': [],
+    })
+    ui.button('Update', on_click=table.update)
+
+    screen.open('/')
+    table.options['rowData'].append({'name': 'Alice', 'age': 18})
+    screen.click('Update')
+    screen.should_contain('Alice')
+    screen.should_contain('18')
+    table.options['rowData'].append({'name': 'Bob', 'age': 21})
+    screen.click('Update')
+    screen.should_contain('Alice')
+    screen.should_contain('18')
+    screen.should_contain('Bob')
+    screen.should_contain('21')
+
+
+def test_click_cell(screen: Screen):
+    table = ui.table({
+        'columnDefs': [{'field': 'name'}, {'field': 'age'}],
+        'rowData': [{'name': 'Alice', 'age': 18}],
+    })
+    table.on('cellClicked', lambda msg: ui.label(f'{msg["args"]["data"]["name"]} has been clicked!'))
+
+    screen.open('/')
+    screen.click('Alice')
+    screen.should_contain('Alice has been clicked!')