|
1 | 1 | import pytest |
2 | 2 |
|
| 3 | +import flet as ft |
3 | 4 | import flet.testing as ftt |
4 | | - |
5 | | -# from examples.controls.checkbox import basic, handling_events, styled |
6 | | -from examples.tutorials.calculator import calc1 |
7 | | - |
8 | | -# @pytest.mark.asyncio(loop_scope="function") |
9 | | -# async def test_image_for_docs(flet_app_function: ftt.FletTestApp, request): |
10 | | -# flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT |
11 | | -# await flet_app_function.assert_control_screenshot( |
12 | | -# request.node.name, |
13 | | -# ft.Column( |
14 | | -# intrinsic_width=True, |
15 | | -# controls=[ |
16 | | -# ft.Checkbox(), |
17 | | -# ft.Checkbox(label="Checked", value=True), |
18 | | -# ft.Checkbox(label="Disabled", disabled=True), |
19 | | -# ], |
20 | | -# ), |
21 | | -# ) |
| 5 | +from examples.tutorials.calculator import calc1, calc2, calc3 |
22 | 6 |
|
23 | 7 |
|
24 | 8 | @pytest.mark.parametrize( |
|
27 | 11 | indirect=True, |
28 | 12 | ) |
29 | 13 | @pytest.mark.asyncio(loop_scope="function") |
30 | | -async def test_basic(flet_app_function: ftt.FletTestApp): |
31 | | - # button = await flet_app_function.tester.find_by_text("Submit") |
32 | | - # await flet_app_function.tester.tap(button) |
| 14 | +async def test_calc1(flet_app_function: ftt.FletTestApp): |
| 15 | + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT |
| 16 | + flet_app_function.page.enable_screenshots = True |
| 17 | + flet_app_function.resize_page(350, 850) |
| 18 | + flet_app_function.page.update() |
33 | 19 | await flet_app_function.tester.pump_and_settle() |
34 | 20 | flet_app_function.assert_screenshot( |
35 | 21 | "calc1", |
36 | | - await flet_app_function.take_page_controls_screenshot(), |
| 22 | + await flet_app_function.page.take_screenshot( |
| 23 | + pixel_ratio=flet_app_function.screenshots_pixel_ratio |
| 24 | + ), |
37 | 25 | ) |
38 | 26 |
|
39 | 27 |
|
40 | | -# @pytest.mark.parametrize( |
41 | | -# "flet_app_function", |
42 | | -# [{"flet_app_main": handling_events.main}], |
43 | | -# indirect=True, |
44 | | -# ) |
45 | | -# @pytest.mark.asyncio(loop_scope="function") |
46 | | -# async def test_handling_events(flet_app_function: ftt.FletTestApp): |
47 | | -# checkbox = await flet_app_function.tester.find_by_text( |
48 | | -# "Checkbox with 'change' event" |
49 | | -# ) |
50 | | -# await flet_app_function.tester.tap(checkbox) |
51 | | -# await flet_app_function.tester.pump_and_settle() |
52 | | -# await flet_app_function.tester.tap(checkbox) |
53 | | -# await flet_app_function.tester.pump_and_settle() |
54 | | -# await flet_app_function.tester.tap(checkbox) |
55 | | -# await flet_app_function.tester.pump_and_settle() |
56 | | -# scr = await flet_app_function.wrap_page_controls_in_screenshot() |
57 | | -# flet_app_function.assert_screenshot( |
58 | | -# "handling_events", |
59 | | -# await scr.capture(pixel_ratio=flet_app_function.screenshots_pixel_ratio), |
60 | | -# ) |
| 28 | +@pytest.mark.parametrize( |
| 29 | + "flet_app_function", |
| 30 | + [{"flet_app_main": calc2.main}], |
| 31 | + indirect=True, |
| 32 | +) |
| 33 | +@pytest.mark.asyncio(loop_scope="function") |
| 34 | +async def test_calc2(flet_app_function: ftt.FletTestApp): |
| 35 | + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT |
| 36 | + flet_app_function.page.enable_screenshots = True |
| 37 | + flet_app_function.resize_page(350, 350) |
| 38 | + flet_app_function.page.update() |
| 39 | + await flet_app_function.tester.pump_and_settle() |
| 40 | + flet_app_function.assert_screenshot( |
| 41 | + "calc2", |
| 42 | + await flet_app_function.page.take_screenshot( |
| 43 | + pixel_ratio=flet_app_function.screenshots_pixel_ratio |
| 44 | + ), |
| 45 | + ) |
61 | 46 |
|
62 | 47 |
|
63 | | -# @pytest.mark.parametrize( |
64 | | -# "flet_app_function", |
65 | | -# [{"flet_app_main": styled.main}], |
66 | | -# indirect=True, |
67 | | -# ) |
68 | | -# @pytest.mark.asyncio(loop_scope="function") |
69 | | -# async def test_styled(flet_app_function: ftt.FletTestApp): |
70 | | -# flet_app_function.assert_screenshot( |
71 | | -# "styled_checkboxes", |
72 | | -# await flet_app_function.take_page_controls_screenshot(), |
73 | | -# ) |
| 48 | +@pytest.mark.parametrize( |
| 49 | + "flet_app_function", |
| 50 | + [{"flet_app_main": calc3.main}], |
| 51 | + indirect=True, |
| 52 | +) |
| 53 | +@pytest.mark.asyncio(loop_scope="function") |
| 54 | +async def test_calc3(flet_app_function: ftt.FletTestApp): |
| 55 | + flet_app_function.page.theme_mode = ft.ThemeMode.LIGHT |
| 56 | + flet_app_function.page.enable_screenshots = True |
| 57 | + flet_app_function.resize_page(400, 350) |
| 58 | + flet_app_function.page.update() |
| 59 | + await flet_app_function.tester.pump_and_settle() |
| 60 | + flet_app_function.assert_screenshot( |
| 61 | + "calc3", |
| 62 | + await flet_app_function.page.take_screenshot( |
| 63 | + pixel_ratio=flet_app_function.screenshots_pixel_ratio |
| 64 | + ), |
| 65 | + ) |
0 commit comments