Skip to content

Commit 8f99028

Browse files
committed
Refactor alert dialog tests and update fixtures
Merged alert dialog body test into test_alert_dialog.py and removed test_alert_dialog_body.py. Updated screenshot assets and renamed files for consistency. Enhanced conftest.py with reusable app creation and added function-scoped fixture for tests. Added docstring to close_in_app_web_view method in url_launcher.py.
1 parent 1c63ae4 commit 8f99028

File tree

7 files changed

+82
-61
lines changed

7 files changed

+82
-61
lines changed

sdk/python/packages/flet/integration_tests/conftest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55
import flet.testing as ftt
66

77

8-
@pytest_asyncio.fixture(scope="module")
9-
async def flet_app(request):
8+
def create_flet_app(request):
109
params = getattr(request, "param", {})
11-
flet_app = ftt.FletTestApp(
10+
return ftt.FletTestApp(
1211
flutter_app_dir=(Path(__file__).parent / "../../../../../client").resolve(),
1312
test_path=request.fspath,
1413
flet_app_main=params.get("flet_app_main"),
1514
assets_dir=Path(__file__).resolve().parent / "assets",
1615
)
16+
17+
18+
@pytest_asyncio.fixture(scope="module")
19+
async def flet_app(request):
20+
flet_app = create_flet_app(request)
21+
await flet_app.start()
22+
yield flet_app
23+
await flet_app.teardown()
24+
25+
26+
@pytest_asyncio.fixture(scope="function")
27+
async def flet_app_function(request):
28+
flet_app = create_flet_app(request)
1729
await flet_app.start()
1830
yield flet_app
1931
await flet_app.teardown()
-1 Bytes
Loading

sdk/python/packages/flet/integration_tests/controls/test_alert_dialog.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import asyncio
2+
13
import pytest
4+
import pytest_asyncio
25

36
import flet as ft
47
import flet.testing as ftt
58

69

7-
@pytest.mark.asyncio(loop_scope="module")
10+
# Create a new flet_app instance for each test method
11+
@pytest_asyncio.fixture(scope="function", autouse=True)
12+
def flet_app(flet_app_function):
13+
return flet_app_function
14+
15+
16+
@pytest.mark.asyncio(loop_scope="function")
817
async def test_alert_dialog_basic(flet_app: ftt.FletTestApp, request):
918
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
1019
ad = ft.AlertDialog(
@@ -28,3 +37,54 @@ async def test_alert_dialog_basic(flet_app: ftt.FletTestApp, request):
2837
pixel_ratio=flet_app.screenshots_pixel_ratio
2938
),
3039
)
40+
41+
42+
@pytest.mark.asyncio(loop_scope="function")
43+
async def test_update_body(flet_app: ftt.FletTestApp, request):
44+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
45+
ad = ft.AlertDialog(
46+
key="ad",
47+
title=ft.Text("Test"),
48+
bgcolor=ft.Colors.YELLOW,
49+
actions_alignment=ft.MainAxisAlignment.END,
50+
actions=[
51+
ok := ft.TextButton(
52+
"OK",
53+
visible=True,
54+
),
55+
cancel := ft.TextButton(
56+
"Cancel",
57+
visible=True,
58+
),
59+
],
60+
)
61+
flet_app.page.enable_screenshots = True
62+
flet_app.page.window.width = 400
63+
flet_app.page.window.height = 600
64+
flet_app.page.show_dialog(ad)
65+
flet_app.page.update()
66+
await flet_app.tester.pump_and_settle()
67+
assert (await flet_app.tester.find_by_text("OK")).count == 1
68+
69+
flet_app.assert_screenshot(
70+
"update_body_1",
71+
await flet_app.page.take_screenshot(
72+
pixel_ratio=flet_app.screenshots_pixel_ratio
73+
),
74+
)
75+
76+
# change dialog color and hide "OK" button
77+
await asyncio.sleep(1)
78+
ad.bgcolor = ft.Colors.RED
79+
ok.visible = not ok.visible # hide button
80+
cancel.disabled = not cancel.disabled # disable button
81+
flet_app.page.update()
82+
await flet_app.tester.pump_and_settle()
83+
assert (await flet_app.tester.find_by_text("OK")).count == 0
84+
85+
flet_app.assert_screenshot(
86+
"update_body_2",
87+
await flet_app.page.take_screenshot(
88+
pixel_ratio=flet_app.screenshots_pixel_ratio
89+
),
90+
)

sdk/python/packages/flet/integration_tests/controls/test_alert_dialog_body.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

sdk/python/packages/flet/src/flet/controls/services/url_launcher.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ async def can_launch_url(self, url: Union[str, Url]) -> bool:
6565
)
6666

6767
async def close_in_app_web_view(self) -> None:
68+
"""
69+
Closes the in-app web view if it is currently open.
70+
71+
This method invokes the platform-specific functionality to close
72+
any web view that was previously opened within the application.
73+
"""
6874
await self._invoke_method("close_in_app_web_view")

0 commit comments

Comments
 (0)