forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_table.py
84 lines (67 loc) · 2.5 KB
/
test_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from nicegui import ui
from .screen import Screen
def test_update_table(screen: Screen):
table = ui.table({
'columnDefs': [{'field': 'name'}, {'field': 'age'}],
'rowData': [{'name': 'Alice', 'age': 18}],
})
screen.open('/')
screen.should_contain('Name')
screen.should_contain('Age')
screen.should_contain('Alice')
screen.should_contain('18')
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.wait(0.5)
screen.should_contain('Alice')
screen.should_contain('18')
table.options['rowData'].append({'name': 'Bob', 'age': 21})
screen.click('Update')
screen.wait(0.5)
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!')
def test_html_columns(screen: Screen):
ui.table({
'columnDefs': [{'field': 'name'}, {'field': 'age'}],
'rowData': [{'name': '<span class="text-bold">Alice</span>', 'age': 18}],
}, html_columns=[0])
screen.open('/')
screen.should_contain('Alice')
screen.should_not_contain('<span')
assert 'text-bold' in screen.find('Alice').get_attribute('class')
def test_call_api_method_with_argument(screen: Screen):
table = ui.table({
'columnDefs': [{'field': 'name', 'filter': True}],
'rowData': [{'name': 'Alice'}, {'name': 'Bob'}, {'name': 'Carol'}],
})
filter = {'name': {'filterType': 'text', 'type': 'equals', 'filter': 'Alice'}}
ui.button('Filter', on_click=lambda: table.call_api_method('setFilterModel', filter))
screen.open('/')
screen.should_contain('Alice')
screen.should_contain('Bob')
screen.should_contain('Carol')
screen.click('Filter')
screen.should_contain('Alice')
screen.should_not_contain('Bob')
screen.should_not_contain('Carol')