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" )
710async def test_cupertino_alert_dialog_basic (flet_app : ftt .FletTestApp , request ):
811 flet_app .page .theme_mode = ft .ThemeMode .LIGHT
912 cad = ft .CupertinoAlertDialog (
10- title = ft .Text ("Cupertino Alert Dialog" ),
11- content = ft .Text ("Do you want to delete this file?" ),
12- )
13+ title = ft .Text ("Cupertino Alert Dialog" ),
14+ content = ft .Text ("Do you want to delete this file?" ),
15+ )
1316 flet_app .page .enable_screenshots = True
1417 flet_app .page .window .width = 400
1518 flet_app .page .window .height = 600
@@ -23,3 +26,51 @@ async def test_cupertino_alert_dialog_basic(flet_app: ftt.FletTestApp, request):
2326 pixel_ratio = flet_app .screenshots_pixel_ratio
2427 ),
2528 )
29+
30+
31+ @pytest .mark .asyncio (loop_scope = "module" )
32+ async def test_update_body (flet_app : ftt .FletTestApp , request ):
33+ flet_app .page .theme_mode = ft .ThemeMode .LIGHT
34+ ad = ft .CupertinoAlertDialog (
35+ key = "ad" ,
36+ title = ft .Text ("Test" ),
37+ actions = [
38+ ok := ft .TextButton (
39+ "OK" ,
40+ visible = True ,
41+ ),
42+ cancel := ft .TextButton (
43+ "Cancel" ,
44+ visible = True ,
45+ ),
46+ ],
47+ )
48+ flet_app .page .enable_screenshots = True
49+ flet_app .page .window .width = 400
50+ flet_app .page .window .height = 600
51+ flet_app .page .show_dialog (ad )
52+ flet_app .page .update ()
53+ await flet_app .tester .pump_and_settle ()
54+ assert (await flet_app .tester .find_by_text ("OK" )).count == 1
55+
56+ flet_app .assert_screenshot (
57+ "update_body_1" ,
58+ await flet_app .page .take_screenshot (
59+ pixel_ratio = flet_app .screenshots_pixel_ratio
60+ ),
61+ )
62+
63+ # change dialog color and hide "OK" button
64+ await asyncio .sleep (1 )
65+ ok .visible = not ok .visible # hide button
66+ cancel .disabled = not cancel .disabled # disable button
67+ flet_app .page .update ()
68+ await flet_app .tester .pump_and_settle ()
69+ assert (await flet_app .tester .find_by_text ("OK" )).count == 0
70+
71+ flet_app .assert_screenshot (
72+ "update_body_2" ,
73+ await flet_app .page .take_screenshot (
74+ pixel_ratio = flet_app .screenshots_pixel_ratio
75+ ),
76+ )
0 commit comments