浏览代码

adding tests for adding/removing chart series

Rodja Trappe 2 年之前
父节点
当前提交
b820115b41
共有 1 个文件被更改,包括 48 次插入1 次删除
  1. 48 1
      tests/test_chart.py

+ 48 - 1
tests/test_chart.py

@@ -9,7 +9,7 @@ def get_series_0(selenium):
     return selenium.find_elements(By.CSS_SELECTOR, '.highcharts-series-0 .highcharts-point')
 
 
-def test_change_chart_data(screen: Screen):
+def test_change_chart_series(screen: Screen):
     chart = ui.chart({
         'title': False,
         'chart': {'type': 'bar'},
@@ -34,3 +34,50 @@ def test_change_chart_data(screen: Screen):
     after = [bar.size['width'] for bar in get_series_0(screen.selenium)]
     assert before[0] < after[0]
     assert before[1] < after[1]
+
+
+def test_adding_chart_series(screen: Screen):
+    chart = ui.chart({
+        'title': False,
+        'chart': {'type': 'bar'},
+    }).classes('w-full h-64')
+
+    def update():
+        chart.options['xAxis'] = {'categories': ['A', 'B']}
+        chart.options['series'] = [
+            {'name': 'Alpha', 'data': [0.1, 0.2]},
+            {'name': 'Beta', 'data': [0.3, 0.4]},
+        ]
+        chart.update()
+
+    ui.button('Update', on_click=update)
+
+    screen.open('/')
+    screen.click('Update')
+    screen.wait(.5)
+    assert len(screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-point')) == 6
+
+
+def test_removing_chart_series(screen: Screen):
+    chart = ui.chart({
+        'title': False,
+        'chart': {'type': 'bar'},
+        'series': [
+            {'name': 'Alpha', 'data': [0.1, 0.2]},
+            {'name': 'Beta', 'data': [0.3, 0.4]},
+        ],
+    }).classes('w-full h-64')
+
+    def update():
+        chart.options['xAxis'] = {'categories': ['A', 'B']}
+        chart.options['series'] = [
+            {'name': 'Alpha', 'data': [0.1, 0.2]},
+        ]
+        chart.update()
+
+    ui.button('Update', on_click=update)
+
+    screen.open('/')
+    screen.click('Update')
+    screen.wait(.5)
+    assert len(screen.selenium.find_elements(By.CSS_SELECTOR, '.highcharts-point')) == 3