|
| 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