test_dependencies.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from nicegui import ui
  2. from .user import User
  3. def test_joystick_dependency(user: User):
  4. @ui.page('/')
  5. def page():
  6. ui.joystick()
  7. user.open('/')
  8. srcs = user.get_attributes('script', 'src')
  9. assert any(s.endswith('joystick.js') for s in srcs)
  10. assert any(s.endswith('nipplejs.min.js') for s in srcs)
  11. def test_keyboard_dependency_before_startup(user: User):
  12. @ui.page('/')
  13. def page():
  14. ui.keyboard()
  15. user.open('/')
  16. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  17. user.sleep(2) # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)
  18. def test_keyboard_dependency_after_startup(user: User):
  19. @ui.page('/')
  20. def page():
  21. ui.button('activate keyboard', on_click=lambda: ui.keyboard())
  22. user.open('/')
  23. assert not any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  24. user.click('activate keyboard')
  25. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  26. user.sleep(2) # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)