test_element.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from nicegui import ui
  2. from .user import User
  3. def test_classes(user: User):
  4. label = ui.label('Some label')
  5. def assert_classes(classes: str) -> None:
  6. assert user.selenium.find_element_by_xpath(f'//*[normalize-space(@class)="{classes}" and text()="Some label"]')
  7. user.open('/')
  8. assert_classes('')
  9. label.classes('one')
  10. assert_classes('one')
  11. label.classes('one')
  12. assert_classes('one')
  13. label.classes('two three')
  14. assert_classes('one two three')
  15. label.classes(remove='two')
  16. assert_classes('one three')
  17. label.classes(replace='four')
  18. assert_classes('four')
  19. def test_style(user: User):
  20. label = ui.label('Some label')
  21. def assert_style(style: str) -> None:
  22. assert user.selenium.find_element_by_xpath(f'//*[normalize-space(@style)="{style}" and text()="Some label"]')
  23. user.open('/')
  24. assert_style('')
  25. label.style('color: red')
  26. assert_style('color: red;')
  27. label.style('color: red')
  28. assert_style('color: red;')
  29. label.style('color: blue')
  30. assert_style('color: blue;')
  31. label.style('font-weight: bold')
  32. assert_style('color: blue; font-weight: bold;')
  33. label.style(remove='color: blue')
  34. assert_style('font-weight: bold;')
  35. label.style(replace='text-decoration: underline')
  36. assert_style('text-decoration: underline;')
  37. def test_props(user: User):
  38. input = ui.input()
  39. def assert_props(*props: str) -> None:
  40. class_conditions = [f'contains(@class, "q-field--{prop}")' for prop in props]
  41. assert user.selenium.find_element_by_xpath(f'//label[{" and ".join(class_conditions)}]')
  42. user.open('/')
  43. assert_props('standard', 'labeled')
  44. input.props('dark')
  45. assert_props('standard', 'labeled', 'dark')
  46. input.props('dark')
  47. assert_props('standard', 'labeled', 'dark')
  48. input.props(remove='dark')
  49. assert_props('standard', 'labeled')