1
0

test_log.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. def test_log(screen: Screen):
  4. log = ui.log(max_lines=3)
  5. log.push('A')
  6. log.push('B')
  7. log.push('C')
  8. log.push('D')
  9. screen.open('/')
  10. assert screen.find_element(log).text == 'B\nC\nD'
  11. log.clear()
  12. screen.wait(0.5)
  13. assert screen.find_element(log).text == ''
  14. def test_log_with_newlines(screen: Screen):
  15. log = ui.log(max_lines=3)
  16. log.push('A')
  17. log.push('B')
  18. log.push('C\nD')
  19. screen.open('/')
  20. assert screen.find_element(log).text == 'B\nC\nD'
  21. def test_replace_log(screen: Screen):
  22. with ui.row() as container:
  23. ui.log().push('A')
  24. def replace():
  25. container.clear()
  26. with container:
  27. ui.log().push('B')
  28. ui.button('Replace', on_click=replace)
  29. screen.open('/')
  30. screen.should_contain('A')
  31. screen.click('Replace')
  32. screen.should_contain('B')
  33. screen.should_not_contain('A')
  34. def test_special_characters(screen: Screen):
  35. log = ui.log()
  36. log.push('50%')
  37. ui.button('push', on_click=lambda: log.push('100%'))
  38. screen.open('/')
  39. screen.should_contain('50%')
  40. screen.click('push')
  41. screen.should_contain('100%')