forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_chart.py
94 lines (69 loc) · 2.6 KB
/
test_chart.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
85
86
87
88
89
90
91
92
93
94
from selenium.webdriver.common.by import By
from nicegui import ui
from .screen import Screen
def test_change_chart_series(screen: Screen):
chart = ui.chart({
'chart': {'type': 'bar'},
'xAxis': {'categories': ['A', 'B']},
'series': [
{'name': 'Alpha', 'data': [0.1, 0.2]},
{'name': 'Beta', 'data': [0.3, 0.4]},
],
}).classes('w-full h-64')
def update():
chart.options['series'][0]['data'][:] = [1, 1]
chart.update()
ui.button('Update', on_click=update)
def get_series_0():
return screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-series-0 .highcharts-point')
screen.open('/')
screen.wait(0.5)
before = [bar.size['width'] for bar in get_series_0()]
screen.click('Update')
screen.wait(0.5)
after = [bar.size['width'] for bar in get_series_0()]
assert before[0] < after[0]
assert before[1] < after[1]
def test_adding_chart_series(screen: Screen):
chart = ui.chart({
'chart': {'type': 'bar'},
'xAxis': {'categories': ['A', 'B']},
'series': [],
}).classes('w-full h-64')
def add():
chart.options['series'].append({'name': 'X', 'data': [0.1, 0.2]})
chart.update()
ui.button('Add', on_click=add)
screen.open('/')
screen.click('Add')
screen.wait(0.5)
assert len(screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-point')) == 3
def test_removing_chart_series(screen: Screen):
chart = ui.chart({
'chart': {'type': 'bar'},
'xAxis': {'categories': ['A', 'B']},
'series': [
{'name': 'Alpha', 'data': [0.1, 0.2]},
{'name': 'Beta', 'data': [0.3, 0.4]},
],
}).classes('w-full h-64')
def remove():
chart.options['series'].pop(0)
chart.update()
ui.button('Remove', on_click=remove)
screen.open('/')
screen.click('Remove')
screen.wait(0.5)
assert len(screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-point')) == 3
def test_extra(screen: Screen):
ui.chart({'chart': {'type': 'solidgauge'}}, extras=['solid-gauge'])
screen.open('/')
assert screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-pane')
def test_missing_extra(screen: Screen):
ui.chart({'chart': {'type': 'solidgauge'}})
screen.open('/')
assert not screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-pane')
def test_stock_chart(screen: Screen):
ui.chart({}, type='stockChart', extras=['stock'])
screen.open('/')
assert screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-range-selector-buttons')