diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 72fc4afec..fc01ad464 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -1985,6 +1985,161 @@ ''' # --- +# name: test_css_hot_reloading + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HotReloadingApp + + + + + + + + + + Hello, world! + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_css_property[align.py] ''' diff --git a/tests/snapshot_tests/snapshot_apps/hot_reloading_app.css b/tests/snapshot_tests/snapshot_apps/hot_reloading_app.css new file mode 100644 index 000000000..e69de29bb diff --git a/tests/snapshot_tests/snapshot_apps/hot_reloading_app.py b/tests/snapshot_tests/snapshot_apps/hot_reloading_app.py new file mode 100644 index 000000000..fa7bc1f82 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/hot_reloading_app.py @@ -0,0 +1,28 @@ +from pathlib import Path + +from textual.app import App, ComposeResult +from textual.containers import Container +from textual.widgets import Label + + +CSS_PATH = (Path(__file__) / "../hot_reloading_app.css").resolve() + +CSS_PATH.write_text( + """ +Container { + align: center middle; +} + +Label { + border: round $primary; + padding: 3; +} +""" +) + + +class HotReloadingApp(App[None]): + CSS_PATH = CSS_PATH + + def compose(self) -> ComposeResult: + yield Container(Label("Hello, world!")) diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 7c68f1405..f7b58d8c4 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -340,3 +340,15 @@ def test_scrollbar_thumb_height(snap_compare): assert snap_compare( SNAPSHOT_APPS_DIR / "scrollbar_thumb_height.py", ) + + +def test_css_hot_reloading(snap_compare): + async def run_before(pilot): + css_file = pilot.app.CSS_PATH + with open(css_file, "w") as f: + f.write("") # Clear all the CSS. + await pilot.app._on_css_change() + + assert snap_compare( + SNAPSHOT_APPS_DIR / "hot_reloading_app.py", run_before=run_before + )