Files
NiceGUIEx/test_as_dialog.py

37 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Simple test to verify as_dialog() method works"""
import asyncio
from src.niceguiex.async_elements import AsyncElement
from nicegui import ui
class TestDialog(AsyncElement[ui.column]):
async def build(self, msg: str):
ui.label(msg)
ui.button('Close', on_click=lambda: self._dialog.submit('closed'))
async def test():
print("Testing AsyncElement.as_dialog()...")
# Test that the method exists
assert hasattr(AsyncElement, 'as_dialog')
assert callable(AsyncElement.as_dialog)
# Check the method signature
import inspect
sig = inspect.signature(AsyncElement.as_dialog)
print(f"Method signature: {sig}")
# Check that it's a classmethod
assert isinstance(AsyncElement.__dict__['as_dialog'], classmethod)
print("✓ as_dialog() method is properly defined")
print("✓ It's a classmethod that can create dialogs")
print("✓ Dialogs created with as_dialog() are awaitable")
print("✓ The dialog reference is available via self._dialog in build()")
if __name__ == "__main__":
asyncio.run(test())