From 06e4dc05cf94f2980e49191797db8b3fa0ab3c38 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 1 Oct 2024 15:03:55 +0100 Subject: [PATCH] snapshot --- src/textual/app.py | 2 +- .../test_push_screen_on_mount.svg | 153 ++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 65 +++++++- 3 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_push_screen_on_mount.svg diff --git a/src/textual/app.py b/src/textual/app.py index a03a38b03c..e59c833059 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -2892,11 +2892,11 @@ async def invoke_ready_callback() -> None: await ready_result with self.batch_update(): - self.stylesheet.apply(self) try: try: await self._dispatch_message(events.Compose()) default_screen = self.screen + self.stylesheet.apply(self) await self._dispatch_message(events.Mount()) self.check_idle() finally: diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_push_screen_on_mount.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_push_screen_on_mount.svg new file mode 100644 index 0000000000..cabf9efab1 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_push_screen_on_mount.svg @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MyApp + + + + + + + + + + + + + + + +█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█ + + + + +Hello WorlAre you sure you want to quit? + + + + +█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█ + + + + + + + + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 0c7d56cd6c..75930c090c 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -8,11 +8,11 @@ from textual import events, on from textual.app import App, ComposeResult from textual.binding import Binding, Keymap -from textual.containers import Vertical +from textual.containers import Center, Grid, Middle, Vertical from textual.binding import Binding from textual.containers import Vertical, VerticalScroll from textual.pilot import Pilot -from textual.screen import Screen +from textual.screen import ModalScreen, Screen from textual.widgets import ( Button, Header, @@ -27,6 +27,7 @@ SelectionList, ) from textual.widgets import ProgressBar, Label, Switch +from textual.widgets import Static from textual.widgets.text_area import BUILTIN_LANGUAGES, Selection, TextAreaTheme # These paths should be relative to THIS directory. @@ -2103,9 +2104,9 @@ def action_toggle_console(self) -> None: def test_updates_with_auto_refresh(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5056 - + After hiding and unhiding the RichLog, you should be able to see 1.5 fully rendered placeholder widgets. - Prior to this fix, the bottom portion of the screen did not + Prior to this fix, the bottom portion of the screen did not refresh after the RichLog was hidden/unhidden while in the presence of the auto-refreshing ProgressBar widget. """ @@ -2134,3 +2135,59 @@ def action_toggle_widget(self, widget_type: str) -> None: app = MRE() assert snap_compare(app, press=["z", "z"]) + + +def test_push_screen_on_mount(snap_compare): + """Test pushing screen immediately on mount, which was not refreshing the base screen. + + Should show a panel over Hello World text + + """ + + class QuitScreen(ModalScreen[None]): + """Screen with a dialog to quit.""" + + DEFAULT_CSS = """ + QuitScreen { + align: center middle; + } + + #dialog { + grid-size: 2; + grid-gutter: 1 2; + grid-rows: 1fr 3; + padding: 0 1; + width: 60; + height: 11; + border: thick $primary 80%; + background: $surface; + } + + #question { + column-span: 2; + height: 1fr; + width: 1fr; + content-align: center middle; + } + + Button { + width: 100%; + } + """ + + def compose(self) -> ComposeResult: + yield Grid( + Label("Are you sure you want to quit?", id="question"), id="dialog" + ) + + class MyApp(App[None]): + def compose(self) -> ComposeResult: + s = "Hello World Foo Bar Baz" + yield Middle(Center(Static(s))) + + def on_mount(self) -> None: + self.push_screen(QuitScreen()) + + app = MyApp() + + assert snap_compare(app)