Skip to content

Commit 9580fe3

Browse files
committed
Add themed NavigationBar integration tests for macOS
Renamed navigation_bar.png to basic.png and added new golden images for themed NavigationBar states. Updated test_navigation_bar.py to include separate tests for basic and themed NavigationBar, verifying appearance under different theme settings and user interactions.
1 parent e8adc7e commit 9580fe3

5 files changed

Lines changed: 78 additions & 2 deletions

File tree

sdk/python/packages/flet/integration_tests/controls/golden/macos/navigation_bar/navigation_bar.png renamed to sdk/python/packages/flet/integration_tests/controls/golden/macos/navigation_bar/basic.png

File renamed without changes.
9.6 KB
Loading
10.5 KB
Loading
6.12 KB
Loading

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

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import pytest
2+
import pytest_asyncio
23

34
import flet as ft
45
import flet.testing as ftt
56

67

7-
@pytest.mark.asyncio(loop_scope="module")
8-
async def test_navigation_bar(flet_app: ftt.FletTestApp, request):
8+
# Create a new flet_app instance for each test method
9+
@pytest_asyncio.fixture(scope="function", autouse=True)
10+
def flet_app(flet_app_function):
11+
return flet_app_function
12+
13+
14+
@pytest.mark.asyncio(loop_scope="function")
15+
async def test_basic(flet_app: ftt.FletTestApp, request):
916
await flet_app.assert_control_screenshot(
1017
request.node.name,
1118
ft.NavigationBar(
@@ -20,3 +27,72 @@ async def test_navigation_bar(flet_app: ftt.FletTestApp, request):
2027
]
2128
),
2229
)
30+
31+
32+
@pytest.mark.asyncio(loop_scope="function")
33+
async def test_theme(flet_app: ftt.FletTestApp):
34+
flet_app.page.theme = ft.Theme(
35+
navigation_bar_theme=ft.NavigationBarTheme(
36+
bgcolor=ft.Colors.GREEN_200,
37+
shadow_color=ft.Colors.ORANGE_500,
38+
elevation=50,
39+
indicator_color=ft.Colors.GREEN,
40+
overlay_color=ft.Colors.YELLOW_300,
41+
height=200,
42+
label_text_style=ft.TextStyle(color=ft.Colors.ORANGE_900, size=20),
43+
indicator_shape=ft.RoundedRectangleBorder(
44+
radius=ft.BorderRadius.all(10),
45+
side=ft.BorderSide(color=ft.Colors.PURPLE, width=3),
46+
),
47+
label_behavior=ft.NavigationBarLabelBehavior.ONLY_SHOW_SELECTED,
48+
label_padding=ft.Padding.all(20),
49+
)
50+
)
51+
52+
flet_app.page.enable_screenshots = True
53+
flet_app.page.window.width = 400
54+
flet_app.page.window.height = 600
55+
56+
scr_1 = ft.Screenshot(
57+
ft.NavigationBar(
58+
key="nb",
59+
elevation=100,
60+
destinations=[
61+
ft.NavigationBarDestination(icon=ft.Icons.EXPLORE, label="Explore"),
62+
ft.NavigationBarDestination(key="add", icon=ft.Icon(ft.Icons.ADD)),
63+
ft.NavigationBarDestination(
64+
icon=ft.Icons.PHONE_ENABLED,
65+
label="Explore",
66+
),
67+
],
68+
)
69+
)
70+
flet_app.page.add(scr_1)
71+
flet_app.page.update()
72+
await flet_app.tester.pump_and_settle()
73+
74+
flet_app.assert_screenshot(
75+
"theme_1",
76+
await scr_1.capture(pixel_ratio=flet_app.screenshots_pixel_ratio),
77+
)
78+
79+
# hover to check overlay color
80+
add = await flet_app.tester.find_by_key("add")
81+
assert add.count == 1
82+
await flet_app.tester.mouse_hover(add)
83+
await flet_app.tester.pump_and_settle()
84+
85+
flet_app.assert_screenshot(
86+
"theme_2",
87+
await scr_1.capture(pixel_ratio=flet_app.screenshots_pixel_ratio),
88+
)
89+
90+
# click to check label behaviour
91+
await flet_app.tester.tap(add)
92+
flet_app.page.update()
93+
await flet_app.tester.pump_and_settle()
94+
95+
flet_app.assert_screenshot(
96+
"theme_3",
97+
await scr_1.capture(pixel_ratio=flet_app.screenshots_pixel_ratio),
98+
)

0 commit comments

Comments
 (0)