test_chart.py 994 B

123456789101112131415161718192021222324252627282930313233343536
  1. from selenium.webdriver.common.by import By
  2. from nicegui import ui
  3. from .screen import Screen
  4. def get_series_0(selenium):
  5. return selenium.find_elements(By.CSS_SELECTOR, '.highcharts-series-0 .highcharts-point')
  6. def test_change_chart_data(screen: Screen):
  7. chart = ui.chart({
  8. 'title': False,
  9. 'chart': {'type': 'bar'},
  10. 'xAxis': {'categories': ['A', 'B']},
  11. 'series': [
  12. {'name': 'Alpha', 'data': [0.1, 0.2]},
  13. {'name': 'Beta', 'data': [0.3, 0.4]},
  14. ],
  15. }).classes('w-full h-64')
  16. def update():
  17. chart.options['series'][0]['data'][:] = [1, 1]
  18. chart.update()
  19. ui.button('Update', on_click=update)
  20. screen.open('/')
  21. screen.wait(0.5)
  22. before = [bar.size['width'] for bar in get_series_0(screen.selenium)]
  23. screen.click('Update')
  24. screen.wait(0.5)
  25. after = [bar.size['width'] for bar in get_series_0(screen.selenium)]
  26. assert before[0] < after[0]
  27. assert before[1] < after[1]