1
0

test_element.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from nicegui import ui
  2. from .user import User
  3. def test_classes(user: User):
  4. label = ui.label('label')
  5. user.open('/')
  6. def assert_classes(classes: str) -> None:
  7. for i in range(20):
  8. if user.find('label').get_attribute('class') == classes:
  9. return
  10. user.sleep(0.01)
  11. else:
  12. raise AssertionError(f'Expected {classes}, got {user.find("label").get_attribute("class")}')
  13. assert_classes('')
  14. label.classes('one')
  15. assert_classes('one')
  16. label.classes('one')
  17. assert_classes('one')
  18. label.classes('two three')
  19. assert_classes('one two three')
  20. label.classes(remove='two')
  21. assert_classes('one three')
  22. label.classes(replace='four')
  23. assert_classes('four')
  24. def test_style(user: User):
  25. label = ui.label('label')
  26. def style() -> str:
  27. user.open('/')
  28. return user.find('label').get_attribute('style')
  29. assert style() == ''
  30. label.style('color: red')
  31. assert style() == 'color: red;'
  32. label.style('color: red')
  33. assert style() == 'color: red;'
  34. label.style('color: blue')
  35. assert style() == 'color: blue;'
  36. label.style('font-weight: bold')
  37. assert style() == 'color: blue; font-weight: bold;'
  38. label.style(remove='color: blue')
  39. assert style() == 'font-weight: bold;'
  40. label.style(replace='text-decoration: underline')
  41. assert style() == 'text-decoration: underline;'
  42. def test_props(user: User):
  43. input = ui.input('input')
  44. def props() -> str:
  45. user.open('/')
  46. element = user.selenium.find_element_by_tag_name('label')
  47. return [c.replace('q-field--', '') for c in element.get_attribute('class').split() if c.startswith('q-field--')]
  48. assert props() == ['standard', 'labeled']
  49. input.props('dark')
  50. assert props() == ['standard', 'labeled', 'dark']
  51. input.props('dark')
  52. assert props() == ['standard', 'labeled', 'dark']
  53. input.props(remove='dark')
  54. assert props() == ['standard', 'labeled']