Skip to content

Commit 9a03928

Browse files
authored
Add Checkbox integration tests and update docs (#5680)
Introduced integration tests and golden images for Checkbox control, updated documentation to include new example images and improved formatting. Also refactored example scripts to use __main__ guard and enhanced screenshot handling in FletTestApp for intrinsic width support.
1 parent afce39c commit 9a03928

File tree

9 files changed

+73
-6
lines changed

9 files changed

+73
-6
lines changed

sdk/python/examples/controls/checkbox/__init__.py

Whitespace-only changes.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ def handle_checkbox_change(e: ft.Event[ft.Checkbox]):
1414
)
1515

1616

17-
ft.run(main)
17+
if __name__ == "__main__":
18+
ft.run(main)

sdk/python/examples/controls/checkbox/styled.py

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

2323

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

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---
2+
class_name: flet.Checkbox
3+
examples: ../../examples/controls/checkbox
4+
example_images: ../test-images/examples/material/golden/macos/checkbox
5+
---
6+
7+
{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic checkboxes") }}
8+
19
## Examples
210

311
[Live example](https://flet-controls-gallery.fly.dev/input/checkbox)
@@ -8,11 +16,10 @@
816
--8<-- "../../examples/controls/checkbox/basic.py"
917
```
1018

11-
![basic](../examples/controls/checkbox/media/basic.gif){width="80%"}
19+
![Basic checkbox]({{ example_images }}/basic.png){width="50%"}
1220
/// caption
1321
///
1422

15-
1623
### Handling events
1724

1825
```python
@@ -29,4 +36,8 @@
2936
--8<-- "../../examples/controls/checkbox/styled.py"
3037
```
3138

32-
::: flet.Checkbox
39+
![Styled checkboxes]({{ example_images }}/styled_checkboxes.png){width="50%"}
40+
/// caption
41+
///
42+
43+
{{ class_members(class_name) }}
48.3 KB
Loading
6.99 KB
Loading
25.1 KB
Loading
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
3+
import flet as ft
4+
import flet.testing as ftt
5+
from examples.controls.checkbox import (
6+
basic,
7+
styled,
8+
)
9+
10+
11+
@pytest.mark.asyncio(loop_scope="module")
12+
async def test_image_for_docs(flet_app: ftt.FletTestApp, request):
13+
flet_app.page.theme_mode = ft.ThemeMode.LIGHT
14+
await flet_app.assert_control_screenshot(
15+
request.node.name,
16+
ft.Column(
17+
intrinsic_width=True,
18+
controls=[
19+
ft.Checkbox(),
20+
ft.Checkbox(label="Checked", value=True),
21+
ft.Checkbox(label="Disabled", 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": styled.main}],
43+
indirect=True,
44+
)
45+
@pytest.mark.asyncio(loop_scope="function")
46+
async def test_custom_content(flet_app_function: ftt.FletTestApp):
47+
flet_app_function.assert_screenshot(
48+
"styled_checkboxes",
49+
await flet_app_function.take_page_controls_screenshot(),
50+
)

sdk/python/packages/flet/src/flet/testing/flet_test_app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ async def wrap_page_controls_in_screenshot(self, margin=10):
262262
Wraps provided controls in a Screenshot control.
263263
"""
264264
controls = list(self.page.controls)
265-
self.page.controls = [scr := ft.Screenshot(ft.Column(controls, margin=margin))]
265+
self.page.controls = [
266+
scr := ft.Screenshot(
267+
ft.Column(controls, margin=margin, intrinsic_width=True)
268+
)
269+
] # type: ignore
266270
self.page.update()
267271
await self.tester.pump_and_settle()
268272
return scr

0 commit comments

Comments
 (0)