test_dependencies.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. user.sleep(2) # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)
  12. def test_keyboard_dependency_before_startup(user: User):
  13. @ui.page('/')
  14. def page():
  15. ui.keyboard()
  16. user.open('/')
  17. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  18. user.sleep(2) # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)
  19. def test_keyboard_dependency_after_startup(user: User):
  20. @ui.page('/')
  21. def page():
  22. ui.button('activate keyboard', on_click=lambda: ui.keyboard())
  23. user.open('/')
  24. assert not any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  25. user.click('activate keyboard')
  26. assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
  27. user.sleep(2) # NOTE we need to sleep here so the js timeout error is printed (start pytest with -s to see it)