diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ca426f1..05165a611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - It is now possible to `await` a `DOMQuery.remove`. Note that this changes the return value of `DOMQuery.remove`, which uses to return `self`. https://github.com/Textualize/textual/issues/1094 +- Added Pilot.wait_for_animation ### Changed diff --git a/src/textual/pilot.py b/src/textual/pilot.py index 0d6f47b0e..b6b64359d 100644 --- a/src/textual/pilot.py +++ b/src/textual/pilot.py @@ -42,6 +42,10 @@ class Pilot: """ await asyncio.sleep(delay) + async def wait_for_animation(self) -> None: + """Wait for any animation to complete.""" + await self._app.animator.wait_for_idle() + async def exit(self, result: object) -> None: """Exit the app with the given result. diff --git a/tests/test_animation.py b/tests/test_animation.py new file mode 100644 index 000000000..5cfee395b --- /dev/null +++ b/tests/test_animation.py @@ -0,0 +1,33 @@ +from time import time +from textual.app import App, ComposeResult +from textual.widgets import Static + + +class AnimApp(App): + CSS = """ + #foo { + height: 1; + } + + """ + + def compose(self) -> ComposeResult: + yield Static("foo", id="foo") + + +async def test_animate_height() -> None: + """Test animating styles.height works.""" + + # Styles.height is a scalar, which makes it more complicated to animate + + app = AnimApp() + + async with app.run_test() as pilot: + static = app.query_one(Static) + assert static.size.height == 1 + static.styles.animate("height", 100, duration=0.5) + start = time() + await pilot.wait_for_animation() + elapsed = time() - start + assert elapsed > 0.5 + assert static.styles.height.value == 100