test_expansion.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. def test_open_close_expansion(screen: Screen):
  4. with ui.expansion('Expansion') as e:
  5. ui.label('Content')
  6. ui.button('Open', on_click=e.open)
  7. ui.button('Close', on_click=e.close)
  8. screen.open('/')
  9. screen.should_contain('Expansion')
  10. screen.should_not_contain('Content')
  11. screen.click('Open')
  12. screen.wait(0.5)
  13. screen.should_contain('Content')
  14. screen.click('Close')
  15. screen.wait(0.5)
  16. screen.should_not_contain('Content')
  17. def test_caption(screen: Screen):
  18. with ui.expansion('Expansion', caption='Caption'):
  19. ui.label('Content')
  20. screen.open('/')
  21. screen.should_contain('Expansion')
  22. screen.should_contain('Caption')
  23. screen.should_not_contain('Content')
  24. screen.click('Expansion')
  25. screen.wait(0.5)
  26. screen.should_contain('Expansion')
  27. screen.should_contain('Caption')
  28. screen.should_contain('Content')
  29. def test_group(screen: Screen):
  30. with ui.expansion('Expansion A', group='group'):
  31. ui.label('Content A')
  32. with ui.expansion('Expansion B', group='group'):
  33. ui.label('Content B')
  34. with ui.expansion('Expansion C', group='group'):
  35. ui.label('Content C')
  36. screen.open('/')
  37. screen.should_contain('Expansion A')
  38. screen.should_contain('Expansion B')
  39. screen.should_contain('Expansion C')
  40. screen.should_not_contain('Content A')
  41. screen.should_not_contain('Content B')
  42. screen.should_not_contain('Content C')
  43. screen.click('Expansion A')
  44. screen.wait(0.5)
  45. screen.should_contain('Content A')
  46. screen.should_not_contain('Content B')
  47. screen.should_not_contain('Content C')
  48. screen.click('Expansion B')
  49. screen.wait(0.5)
  50. screen.should_not_contain('Content A')
  51. screen.should_contain('Content B')
  52. screen.should_not_contain('Content C')
  53. screen.click('Expansion C')
  54. screen.wait(0.5)
  55. screen.should_not_contain('Content A')
  56. screen.should_not_contain('Content B')
  57. screen.should_contain('Content C')