Skip to content

Commit 44eadb0

Browse files
committed
update slider docs and add integration test
1 parent 48044f9 commit 44eadb0

10 files changed

Lines changed: 81 additions & 7 deletions

File tree

sdk/python/examples/controls/slider/basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ def main(page: ft.Page):
1010
)
1111

1212

13-
ft.run(main)
13+
if __name__ == "__main__":
14+
ft.run(main)

sdk/python/examples/controls/slider/custom_label.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ def main(page: ft.Page):
1010
)
1111

1212

13-
ft.run(main)
13+
if __name__ == "__main__":
14+
ft.run(main)

sdk/python/examples/controls/slider/handling_events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def slider_changed(e: ft.Event[ft.Slider]):
99
page.add(
1010
ft.Text("Slider with 'on_change' event:"),
1111
ft.Slider(
12+
key="slider",
1213
min=0,
1314
max=100,
1415
divisions=10,
@@ -19,4 +20,5 @@ def slider_changed(e: ft.Event[ft.Slider]):
1920
)
2021

2122

22-
ft.run(main)
23+
if __name__ == "__main__":
24+
ft.run(main)

sdk/python/examples/controls/slider/random_values.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ def handle_slider_change(e: ft.Event[ft.Slider]):
2323
slider.update()
2424

2525

26-
ft.run(main)
26+
if __name__ == "__main__":
27+
ft.run(main)

sdk/python/packages/flet/docs/controls/slider.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
class_name: flet.Slider
33
examples: ../../examples/controls/slider
4-
example_images: ../examples/controls/slider/media
4+
example_images: ../test-images/examples/material/golden/macos/slider
55
---
66

7-
{{ class_summary(class_name) }}
7+
<!-- {{ class_summary(class_name) }} -->
8+
{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Default and disabled sliders") }}
89

910
## Examples
1011

11-
[Live example](https://flet-controls-gallery.fly.dev/input/slider)
12+
[Live example](https://flet-controls-gallery.fly.dev/input/slider/basic)
1213

1314
### Basic Example
1415

13 KB
Loading
18.3 KB
Loading
16.4 KB
Loading
4.48 KB
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import pytest
2+
3+
import flet as ft
4+
import flet.testing as ftt
5+
from examples.controls.slider import (
6+
custom_label,
7+
basic,
8+
handling_events,
9+
random_values,
10+
)
11+
12+
13+
@pytest.mark.asyncio(loop_scope="function")
14+
async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request):
15+
flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT
16+
await flet_app_function.assert_control_screenshot(
17+
request.node.name,
18+
ft.Column(
19+
[
20+
ft.Slider(label="Defualt Slider"),
21+
ft.Slider(label="Disabled Slider", disabled=True),
22+
]
23+
),
24+
)
25+
26+
27+
@pytest.mark.parametrize(
28+
"flet_app_function",
29+
[{"flet_app_main": basic.main}],
30+
indirect=True,
31+
)
32+
@pytest.mark.asyncio(loop_scope="function")
33+
async def test_basic(flet_app_function: ftt.FletTestApp):
34+
flet_app_function.assert_screenshot(
35+
"basic",
36+
await flet_app_function.take_page_controls_screenshot(),
37+
)
38+
39+
40+
@pytest.mark.parametrize(
41+
"flet_app_function",
42+
[{"flet_app_main": custom_label.main}],
43+
indirect=True,
44+
)
45+
@pytest.mark.asyncio(loop_scope="function")
46+
async def test_custom_label(flet_app_function: ftt.FletTestApp):
47+
flet_app_function.assert_screenshot(
48+
"custom_label",
49+
await flet_app_function.take_page_controls_screenshot(),
50+
)
51+
52+
53+
@pytest.mark.parametrize(
54+
"flet_app_function",
55+
[{"flet_app_main": handling_events.main}],
56+
indirect=True,
57+
)
58+
@pytest.mark.asyncio(loop_scope="function")
59+
async def test_handling_events(flet_app_function: ftt.FletTestApp):
60+
scr = await flet_app_function.wrap_page_controls_in_screenshot()
61+
button = await flet_app_function.tester.find_by_key("slider")
62+
await flet_app_function.tester.tap(button)
63+
64+
await flet_app_function.tester.pump_and_settle()
65+
flet_app_function.assert_screenshot(
66+
"handling_events",
67+
await scr.capture(pixel_ratio=flet_app_function.screenshots_pixel_ratio),
68+
)

0 commit comments

Comments
 (0)