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

add test and documentation

Rodja Trappe 1 жил өмнө
parent
commit
0289142ad7

+ 1 - 0
nicegui/elements/notification.py

@@ -43,6 +43,7 @@ class Notification(Element, component='notification.js'):
 
         Displays a notification on the screen.
         In contrast to `ui.notify`, this element allows to update the notification message and other properties once the notification is displayed.
+        With a timeout of `None`, the notification can be removed with `dismiss()`.
 
         :param message: content of the notification
         :param position: position on the screen ("top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom", "left", "right" or "center", default: "bottom")

+ 14 - 0
tests/test_notification.py

@@ -21,3 +21,17 @@ def test_close_button(screen: Screen):
     screen.wait(1.5)
     screen.should_not_contain('Hi!')
     assert len(b.client.layout.default_slot.children) == 1
+
+
+def test_dismiss(screen: Screen):
+    n = ui.notification('Hi!', timeout=None)
+    b = ui.button('Dismiss', on_click=n.dismiss)
+
+    screen.open('/')
+    screen.should_contain('Hi!')
+    assert len(b.client.layout.default_slot.children) == 2
+    screen.wait(1)
+    screen.click('Dismiss')
+    screen.wait(1.5)
+    screen.should_not_contain('Hi!')
+    assert len(b.client.layout.default_slot.children) == 1

+ 3 - 1
website/documentation/content/notification_documentation.py

@@ -8,13 +8,15 @@ def main_demo() -> None:
     import asyncio
 
     async def compute():
-        n = ui.notification()
+        n = ui.notification(timeout=None)
         for i in range(10):
             n.message = f'Computing {i/10:.0%}'
             n.spinner = True
             await asyncio.sleep(0.2)
         n.message = 'Done!'
         n.spinner = False
+        await asyncio.sleep(1)
+        n.dismiss()
 
     ui.button('Compute', on_click=compute)