Skip to content

Commit 7fc7a2c

Browse files
committed
Add themed SearchBar integration test for macOS
Introduces a new test for SearchBar theming in macOS, including screenshots for normal, hovered, and opened states. Verifies custom theme properties and interaction behaviors.
1 parent ced18ff commit 7fc7a2c

4 files changed

Lines changed: 73 additions & 0 deletions

File tree

58.3 KB
Loading
54.2 KB
Loading
44 KB
Loading

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,76 @@ async def handle_tap(e: ft.Event[ft.SearchBar]):
5454
pixel_ratio=flet_app.screenshots_pixel_ratio
5555
),
5656
)
57+
58+
59+
@pytest.mark.asyncio(loop_scope="function")
60+
async def test_theme(flet_app: ftt.FletTestApp, request):
61+
flet_app.page.theme = ft.Theme(
62+
search_bar_theme=ft.SearchBarTheme(
63+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
64+
text_capitalization=ft.TextCapitalization.SENTENCES,
65+
shadow_color=ft.Colors.YELLOW,
66+
overlay_color=ft.Colors.PURPLE,
67+
padding=ft.Padding(10, 20, 50, 20),
68+
elevation=100,
69+
text_style=ft.TextStyle(color=ft.Colors.RED, italic=True, size=30),
70+
hint_style=ft.TextStyle(color=ft.Colors.PINK, size=20, italic=True),
71+
shape=ft.RoundedRectangleBorder(
72+
radius=ft.BorderRadius.all(50),
73+
),
74+
border_side=ft.BorderSide(color=ft.Colors.PURPLE, width=2),
75+
)
76+
)
77+
78+
async def handle_tile_click(e: ft.Event[ft.ListTile]):
79+
await sb.close_view(e.control.title.value)
80+
81+
async def handle_tap(e: ft.Event[ft.SearchBar]):
82+
print("handle_tap")
83+
await sb.open_view()
84+
85+
sb = ft.SearchBar(
86+
key="sb",
87+
bar_hint_text="Search colors...",
88+
view_hint_text="Choose a color from the suggestions...",
89+
on_tap=handle_tap,
90+
controls=[
91+
ft.ListTile(title=ft.Text(f"Color {i}"), on_click=handle_tile_click)
92+
for i in range(10)
93+
],
94+
)
95+
96+
flet_app.page.enable_screenshots = True
97+
flet_app.page.window.width = 400
98+
flet_app.page.window.height = 600
99+
flet_app.page.controls = [sb]
100+
flet_app.page.update()
101+
await flet_app.tester.pump_and_settle()
102+
103+
# normal state
104+
flet_app.assert_screenshot(
105+
"theme",
106+
await flet_app.page.take_screenshot(
107+
pixel_ratio=flet_app.screenshots_pixel_ratio
108+
),
109+
)
110+
111+
# hover to check overlay color
112+
await flet_app.tester.mouse_hover(await flet_app.tester.find_by_key("sb"))
113+
await flet_app.tester.pump_and_settle()
114+
flet_app.assert_screenshot(
115+
"theme_hovered",
116+
await flet_app.page.take_screenshot(
117+
pixel_ratio=flet_app.screenshots_pixel_ratio
118+
),
119+
)
120+
121+
# open state
122+
await flet_app.tester.tap(await flet_app.tester.find_by_key("sb"))
123+
await flet_app.tester.pump_and_settle()
124+
flet_app.assert_screenshot(
125+
"theme_opened",
126+
await flet_app.page.take_screenshot(
127+
pixel_ratio=flet_app.screenshots_pixel_ratio
128+
),
129+
)

0 commit comments

Comments
 (0)