1
0

test_editor.py 896 B

12345678910111213141516171819202122232425262728293031
  1. from selenium.webdriver.common.keys import Keys
  2. from nicegui import ui
  3. from nicegui.testing import Screen
  4. def test_editor(screen: Screen):
  5. editor = ui.editor(placeholder='Type something here')
  6. ui.markdown().bind_content_from(editor, 'value', backward=lambda v: f'HTML code:\n```\n{v}\n```')
  7. screen.open('/')
  8. screen.find_element(editor).click()
  9. screen.type('Hello\nworld!')
  10. screen.wait(0.5)
  11. screen.should_contain('Hello<div>world!</div>')
  12. def test_setting_value_twice(screen: Screen):
  13. # https://github.com/zauberzeug/nicegui/issues/3217
  14. editor = ui.editor(value='X')
  15. ui.button('Reset').on_click(lambda: editor.set_value('X'))
  16. screen.open('/')
  17. screen.should_contain('X')
  18. screen.find_element(editor).click()
  19. screen.type(Keys.BACKSPACE + 'ABC')
  20. screen.should_contain('ABC')
  21. screen.click('Reset')
  22. screen.should_contain('X')