diff --git a/tests/test_events.py b/tests/test_events.py index 0398a254f..0226a5f1b 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -3,10 +3,65 @@ from selenium.webdriver.common.by import By from nicegui import ui +from nicegui.events import ClickEventArguments from .screen import Screen +def click_sync_no_args(): + ui.label('click_sync_no_args') + + +def click_sync_with_args(_: ClickEventArguments): + ui.label('click_sync_with_args') + + +async def click_async_no_args(): + await asyncio.sleep(0.1) + ui.label('click_async_no_args') + + +async def click_async_with_args(_: ClickEventArguments): + await asyncio.sleep(0.1) + ui.label('click_async_with_args') + + +def test_click_events(screen: Screen): + ui.button('click_sync_no_args', on_click=click_sync_no_args) + ui.button('click_sync_with_args', on_click=click_sync_with_args) + ui.button('click_async_no_args', on_click=click_async_no_args) + ui.button('click_async_with_args', on_click=click_async_with_args) + + screen.open('/') + screen.click('click_sync_no_args') + screen.click('click_sync_with_args') + screen.click('click_async_no_args') + screen.click('click_async_with_args') + screen.wait(0.5) + screen.should_contain('click_sync_no_args') + screen.should_contain('click_sync_with_args') + screen.should_contain('click_async_no_args') + screen.should_contain('click_async_with_args') + + +def test_generic_events(screen: Screen): + ui.label('click_sync_no_args').on('click', click_sync_no_args) + ui.label('click_sync_with_args').on('click', click_sync_with_args) + ui.label('click_async_no_args').on('click', click_async_no_args) + ui.label('click_async_with_args').on('click', click_async_with_args) + + screen.open('/') + screen.click('click_sync_no_args') + screen.click('click_sync_with_args') + screen.click('click_async_no_args') + screen.click('click_async_with_args') + screen.wait(0.5) + screen.should_contain('click_sync_no_args') + screen.should_contain('click_sync_with_args') + screen.should_contain('click_async_no_args') + screen.should_contain('click_async_with_args') + + def test_event_with_update_before_await(screen: Screen): @ui.page('/') def page():