test_json_editor.py 605 B

123456789101112131415161718192021
  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}}")