1
0

test_leaflet.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import time
  2. from nicegui import ui
  3. from nicegui.testing import Screen
  4. def test_leaflet(screen: Screen):
  5. m = ui.leaflet(center=(51.505, -0.09), zoom=13)
  6. ui.label().bind_text_from(m, 'center', lambda center: f'Center: {center[0]:.3f}, {center[1]:.3f}')
  7. ui.label().bind_text_from(m, 'zoom', lambda zoom: f'Zoom: {zoom}')
  8. ui.button('Zoom in', on_click=lambda: m.set_zoom(m.zoom + 1))
  9. ui.button('Zoom out', on_click=lambda: m.set_zoom(m.zoom - 1))
  10. ui.button('Berlin', on_click=lambda: m.set_center((52.520, 13.405)))
  11. ui.button('London', on_click=lambda: m.set_center((51.505, -0.090)))
  12. screen.open('/')
  13. assert screen.find_all_by_class('leaflet-pane')
  14. assert screen.find_all_by_class('leaflet-control-container')
  15. deadline = time.time() + 3
  16. while not m.is_initialized and time.time() < deadline:
  17. screen.wait(0.1)
  18. screen.should_contain('Center: 51.505, -0.090')
  19. screen.should_contain('Zoom: 13')
  20. screen.click('Zoom in')
  21. screen.should_contain('Zoom: 14')
  22. screen.click('Zoom out')
  23. screen.should_contain('Zoom: 13')
  24. screen.click('Berlin')
  25. screen.should_contain('Center: 52.520, 13.405')
  26. screen.click('London')
  27. screen.should_contain('Center: 51.505, -0.090')