Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Mar 5, 2025
1 parent ed026de commit 5ff3d00
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions tests/gui/actions/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from flask import g

from taipy.gui import Gui, Markdown, notify
from taipy.gui import Gui, Markdown, close_notification, notify


def test_notify(gui: Gui, helpers):
Expand All @@ -27,13 +27,41 @@ def test_notify(gui: Gui, helpers):
gui.run(run_server=False)
flask_client = gui._server.test_client()
# WS client and emit
ws_client = gui._server._ws.test_client(gui._server.get_flask())
ws_client = gui._server._ws.test_client(gui._server.get_flask()) # type: ignore[arg-type]
cid = helpers.create_scope_and_get_sid(gui)
# Get the jsx once so that the page will be evaluated -> variable will be registered
flask_client.get(f"/taipy-jsx/test?client_id={cid}")
with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}):
g.client_id = cid
notify(gui._Gui__state, "Info", "Message") # type: ignore[attr-defined]
id = notify(gui._Gui__state, "Info", "Message", id="id") # type: ignore[attr-defined]
assert id == "id"
received_messages = ws_client.get_received()
helpers.assert_outward_ws_simple_message(
received_messages[0], "AL", {"nType": "Info", "message": "Message", "notificationId": "id"}
)


def test_close_notification(gui: Gui, helpers):
name = "World!" # noqa: F841
btn_id = "button1" # noqa: F841

# set gui frame
gui._set_frame(inspect.currentframe())

gui.add_page("test", Markdown("<|Hello {name}|button|id={btn_id}|>"))
gui.run(run_server=False)
flask_client = gui._server.test_client()
# WS client and emit
ws_client = gui._server._ws.test_client(gui._server.get_flask()) # type: ignore[arg-type]
cid = helpers.create_scope_and_get_sid(gui)
# Get the jsx once so that the page will be evaluated -> variable will be registered
flask_client.get(f"/taipy-jsx/test?client_id={cid}")
with gui.get_flask_app().test_request_context(f"/taipy-jsx/test/?client_id={cid}", data={"client_id": cid}):
g.client_id = cid
id = notify(gui._Gui__state, "Info", "Message", id="id") # type: ignore[attr-defined]
close_notification(gui._Gui__state, id) # type: ignore[attr-defined, arg-type]
received_messages = ws_client.get_received()
helpers.assert_outward_ws_simple_message(received_messages[0], "AL", {"nType": "Info", "message": "Message"})
helpers.assert_outward_ws_simple_message(
received_messages[0], "AL", {"nType": "Info", "message": "Message", "notificationId": "id"}
)
helpers.assert_outward_ws_simple_message(received_messages[1], "AL", {"nType": "", "notificationId": "id"})

0 comments on commit 5ff3d00

Please sign in to comment.