1
0
Эх сурвалжийг харах

#329 add tests for expansion and the very similar dialog element

Falko Schindler 2 жил өмнө
parent
commit
13555bb4a4

+ 47 - 0
tests/test_dialog.py

@@ -0,0 +1,47 @@
+from typing import List
+
+from selenium.webdriver.common.action_chains import ActionChains
+from selenium.webdriver.common.keys import Keys
+
+from nicegui import ui
+
+from .screen import Screen
+
+
+def test_open_close_dialog(screen: Screen):
+    with ui.dialog() as d, ui.card():
+        ui.label('Content')
+        ui.button('Close', on_click=d.close)
+    ui.button('Open', on_click=d.open)
+
+    screen.open('/')
+    screen.should_not_contain('Content')
+    screen.click('Open')
+    screen.wait(0.5)
+    screen.should_contain('Content')
+    screen.click('Close')
+    screen.wait(0.5)
+    screen.should_not_contain('Content')
+
+
+def test_await_dialog(screen: Screen):
+    with ui.dialog() as dialog, ui.card():
+        ui.label('Are you sure?')
+        with ui.row():
+            ui.button('Yes', on_click=lambda: dialog.submit('Yes'))
+            ui.button('No', on_click=lambda: dialog.submit('No'))
+
+    async def show() -> None:
+        results.append(await dialog)
+    results: List[str] = []
+    ui.button('Open', on_click=show)
+
+    screen.open('/')
+    screen.click('Open')
+    screen.click('Yes')
+    screen.click('Open')
+    screen.click('No')
+    screen.click('Open')
+    ActionChains(screen.selenium).send_keys(Keys.ESCAPE).perform()
+    screen.wait(0.5)
+    assert results == ['Yes', 'No', None]

+ 20 - 0
tests/test_expansion.py

@@ -0,0 +1,20 @@
+from nicegui import ui
+
+from .screen import Screen
+
+
+def test_open_close_expansion(screen: Screen):
+    with ui.expansion('Expansion') as e:
+        ui.label('Content')
+    ui.button('Open', on_click=e.open)
+    ui.button('Close', on_click=e.close)
+
+    screen.open('/')
+    screen.should_contain('Expansion')
+    screen.should_not_contain('Content')
+    screen.click('Open')
+    screen.wait(0.5)
+    screen.should_contain('Content')
+    screen.click('Close')
+    screen.wait(0.5)
+    screen.should_not_contain('Content')