test_json_editor.py 842 B

12345678910111213141516171819202122232425262728
  1. from nicegui import ui
  2. from nicegui.testing import Screen
  3. def test_json_editor_methods(screen: Screen):
  4. @ui.page('/')
  5. def page():
  6. editor = ui.json_editor({'content': {'json': {'a': 1, 'b': 2}}})
  7. async def get_data():
  8. data = await editor.run_editor_method('get')
  9. ui.label(f'Data: {data}')
  10. ui.button('Get Data', on_click=get_data)
  11. screen.open('/')
  12. screen.should_contain('text')
  13. screen.should_contain('tree')
  14. screen.should_contain('table')
  15. screen.click('Get Data')
  16. screen.should_contain("Data: {'json': {'a': 1, 'b': 2}}")
  17. def test_json_editor_validation(screen: Screen):
  18. ui.json_editor({'content': {'json': {'x': 0}}}, schema={'type': 'object', 'properties': {'x': {'type': 'string'}}})
  19. screen.open('/')
  20. screen.should_contain('must be string')