more tests

This commit is contained in:
Will McGugan
2022-11-12 12:00:49 +00:00
parent a0ab6c99f1
commit b752ab5a04
2 changed files with 14 additions and 1 deletions

View File

@@ -41,6 +41,7 @@ class Pilot:
delay (float, optional): Seconds to pause. Defaults to 50ms.
"""
await asyncio.sleep(delay)
await asyncio.sleep(0)
async def wait_for_animation(self) -> None:
"""Wait for any animation to complete."""

View File

@@ -1,4 +1,6 @@
import asyncio
from time import time
from textual.app import App, ComposeResult
from textual.widgets import Static
@@ -25,9 +27,19 @@ async def test_animate_height() -> None:
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)
static.styles.animate("height", 100, duration=0.5, easing="linear")
start = time()
# Wait for half the animation
await pilot.pause(0.25)
# Check we reached the half way point
assert static.styles.height.value >= 50
elapsed = time() - start
# Check at least that much time has elapsed
assert 0.5 > elapsed > 0.25
# Wait for the animation to finished
await pilot.wait_for_animation()
elapsed = time() - start
# Check that the full time has elapsed
assert elapsed > 0.5
# Check the height reached the maximum
assert static.styles.height.value == 100