123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- from nicegui import ui
- from nicegui.testing import Screen
- def test_create_dynamically(screen: Screen):
- def create():
- ui.echart({
- 'xAxis': {'type': 'value'},
- 'yAxis': {'type': 'category', 'data': ['A', 'B', 'C']},
- 'series': [{'type': 'line', 'data': [0.1, 0.2, 0.3]}],
- })
- ui.button('Create', on_click=create)
- screen.open('/')
- screen.click('Create')
- assert screen.find_by_tag('canvas')
- def test_update(screen: Screen):
- def update():
- chart.options['xAxis'] = {'type': 'value'}
- chart.options['yAxis'] = {'type': 'category', 'data': ['A', 'B', 'C']}
- chart.options['series'] = [{'type': 'line', 'data': [0.1, 0.2, 0.3]}]
- chart.update()
- chart = ui.echart({})
- ui.button('Update', on_click=update)
- screen.open('/')
- assert not screen.find_all_by_tag('canvas')
- screen.click('Update')
- assert screen.find_by_tag('canvas')
- def test_nested_card(screen: Screen):
- with ui.card().style('height: 200px; width: 600px'):
- ui.echart({
- 'xAxis': {'type': 'value'},
- 'yAxis': {'type': 'category', 'data': ['A', 'B', 'C']},
- 'series': [{'type': 'line', 'data': [0.1, 0.2, 0.3]}],
- })
- screen.open('/')
- canvas = screen.find_by_tag('canvas')
- assert canvas.rect['height'] == 168
- assert canvas.rect['width'] == 568
- def test_nested_expansion(screen: Screen):
- with ui.expansion() as expansion:
- with ui.card().style('height: 200px; width: 600px'):
- ui.echart({
- 'xAxis': {'type': 'value'},
- 'yAxis': {'type': 'category', 'data': ['A', 'B', 'C']},
- 'series': [{'type': 'line', 'data': [0.1, 0.2, 0.3]}],
- })
- ui.button('Open', on_click=expansion.open)
- screen.open('/')
- screen.click('Open')
- canvas = screen.find_by_tag('canvas')
- assert canvas.rect['height'] == 168
- assert canvas.rect['width'] == 568
- def test_run_method(screen: Screen):
- echart = ui.echart({
- 'xAxis': {'type': 'value'},
- 'yAxis': {'type': 'category', 'data': ['A', 'B', 'C']},
- 'series': [{'type': 'line', 'data': [0.1, 0.2, 0.3]}],
- }).classes('w-[600px]')
- async def get_width():
- ui.label(f'Width: {await echart.run_chart_method("getWidth")}px')
- ui.button('Get Width', on_click=get_width)
- screen.open('/')
- screen.click('Get Width')
- screen.should_contain('Width: 600px')
|