Skip to content

Commit ced18ff

Browse files
committed
Add integration test for SearchBar on macOS
Introduces a new integration test for the SearchBar control, including golden images for its basic and opened states on macOS. The test verifies SearchBar rendering and interaction, ensuring correct UI behavior.
1 parent 1759a17 commit ced18ff

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

18.2 KB
Loading
41.1 KB
Loading
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
import pytest_asyncio
3+
4+
import flet as ft
5+
import flet.testing as ftt
6+
7+
8+
@pytest_asyncio.fixture(scope="function", autouse=True)
9+
def flet_app(flet_app_function):
10+
return flet_app_function
11+
12+
13+
@pytest.mark.asyncio(loop_scope="function")
14+
async def test_basic(flet_app: ftt.FletTestApp, request):
15+
async def handle_tile_click(e: ft.Event[ft.ListTile]):
16+
await sb.close_view(e.control.title.value)
17+
18+
async def handle_tap(e: ft.Event[ft.SearchBar]):
19+
print("handle_tap")
20+
await sb.open_view()
21+
22+
sb = ft.SearchBar(
23+
key="sb",
24+
bar_hint_text="Search colors...",
25+
view_hint_text="Choose a color from the suggestions...",
26+
on_tap=handle_tap,
27+
controls=[
28+
ft.ListTile(title=ft.Text(f"Color {i}"), on_click=handle_tile_click)
29+
for i in range(10)
30+
],
31+
)
32+
33+
flet_app.page.enable_screenshots = True
34+
flet_app.page.window.width = 400
35+
flet_app.page.window.height = 600
36+
flet_app.page.controls = [sb]
37+
flet_app.page.update()
38+
await flet_app.tester.pump_and_settle()
39+
40+
# normal state
41+
flet_app.assert_screenshot(
42+
"basic",
43+
await flet_app.page.take_screenshot(
44+
pixel_ratio=flet_app.screenshots_pixel_ratio
45+
),
46+
)
47+
48+
# open state
49+
await flet_app.tester.tap(await flet_app.tester.find_by_key("sb"))
50+
await flet_app.tester.pump_and_settle()
51+
flet_app.assert_screenshot(
52+
"basic_opened",
53+
await flet_app.page.take_screenshot(
54+
pixel_ratio=flet_app.screenshots_pixel_ratio
55+
),
56+
)

0 commit comments

Comments
 (0)