1+ import asyncio
2+
3+ import pytest
4+
15import flet as ft
26import flet .testing as ftt
3- import pytest
47
58
69@pytest .mark .asyncio (loop_scope = "module" )
@@ -27,3 +30,54 @@ async def test_alert_dialog_basic(flet_app: ftt.FletTestApp, request):
2730 pixel_ratio = flet_app .screenshots_pixel_ratio
2831 ),
2932 )
33+
34+
35+ @pytest .mark .asyncio (loop_scope = "module" )
36+ async def test_update_body (flet_app : ftt .FletTestApp , request ):
37+ flet_app .page .theme_mode = ft .ThemeMode .LIGHT
38+ ad = ft .AlertDialog (
39+ key = "ad" ,
40+ title = ft .Text ("Test" ),
41+ bgcolor = ft .Colors .YELLOW ,
42+ actions_alignment = ft .MainAxisAlignment .END ,
43+ actions = [
44+ ok := ft .TextButton (
45+ "OK" ,
46+ visible = True ,
47+ ),
48+ cancel := ft .TextButton (
49+ "Cancel" ,
50+ visible = True ,
51+ ),
52+ ],
53+ )
54+ flet_app .page .enable_screenshots = True
55+ flet_app .page .window .width = 400
56+ flet_app .page .window .height = 600
57+ flet_app .page .show_dialog (ad )
58+ flet_app .page .update ()
59+ await flet_app .tester .pump_and_settle ()
60+ assert (await flet_app .tester .find_by_text ("OK" )).count == 1
61+
62+ flet_app .assert_screenshot (
63+ "update_body_1" ,
64+ await flet_app .page .take_screenshot (
65+ pixel_ratio = flet_app .screenshots_pixel_ratio
66+ ),
67+ )
68+
69+ # change dialog color and hide "OK" button
70+ await asyncio .sleep (1 )
71+ ad .bgcolor = ft .Colors .RED
72+ ok .visible = not ok .visible # hide button
73+ cancel .disabled = not cancel .disabled # disable button
74+ flet_app .page .update ()
75+ await flet_app .tester .pump_and_settle ()
76+ assert (await flet_app .tester .find_by_text ("OK" )).count == 0
77+
78+ flet_app .assert_screenshot (
79+ "update_body_2" ,
80+ await flet_app .page .take_screenshot (
81+ pixel_ratio = flet_app .screenshots_pixel_ratio
82+ ),
83+ )
0 commit comments