|
| 1 | +from textual.app import App |
| 2 | + |
| 3 | + |
| 4 | +class OnLoadDarkSwitch(App[None]): |
| 5 | + """App for testing toggling dark mode in on_load.""" |
| 6 | + |
| 7 | + def on_load(self) -> None: |
| 8 | + self.dark = not self.dark |
| 9 | + |
| 10 | + |
| 11 | +async def test_toggle_dark_on_load() -> None: |
| 12 | + """It should be possible to toggle dark mode in on_load.""" |
| 13 | + async with OnLoadDarkSwitch().run_test() as pilot: |
| 14 | + assert not pilot.app.dark |
| 15 | + |
| 16 | + |
| 17 | +class OnMountDarkSwitch(App[None]): |
| 18 | + """App for testing toggling dark mode in on_mount.""" |
| 19 | + |
| 20 | + def on_mount(self) -> None: |
| 21 | + self.dark = not self.dark |
| 22 | + |
| 23 | + |
| 24 | +async def test_toggle_dark_on_mount() -> None: |
| 25 | + """It should be possible to toggle dark mode in on_mount.""" |
| 26 | + async with OnMountDarkSwitch().run_test() as pilot: |
| 27 | + assert not pilot.app.dark |
| 28 | + |
| 29 | + |
| 30 | +class ActionDarkSwitch(App[None]): |
| 31 | + """App for testing toggling dark mode from an action.""" |
| 32 | + |
| 33 | + BINDINGS = [("d", "toggle", "Toggle Dark Mode")] |
| 34 | + |
| 35 | + def action_toggle(self) -> None: |
| 36 | + self.dark = not self.dark |
| 37 | + |
| 38 | + |
| 39 | +async def test_toggle_dark_in_action() -> None: |
| 40 | + """It should be possible to toggle dark mode with an action.""" |
| 41 | + async with OnMountDarkSwitch().run_test() as pilot: |
| 42 | + await pilot.press("d") |
| 43 | + await pilot.pause(2 / 100) |
| 44 | + assert not pilot.app.dark |
0 commit comments