diff --git a/tests/snapshot_tests/snapshot_apps/component_classes_opacity.py b/tests/snapshot_tests/snapshot_apps/component_classes_opacity.py index c748affb97..32719cbc26 100644 --- a/tests/snapshot_tests/snapshot_apps/component_classes_opacity.py +++ b/tests/snapshot_tests/snapshot_apps/component_classes_opacity.py @@ -1,3 +1,5 @@ +from pathlib import Path + from textual.app import App, ComposeResult from textual.widgets import ( Checkbox, @@ -16,35 +18,41 @@ from textual.widgets.option_list import Option +CSS_PATH = (Path(__file__) / "../component_classes_opacity.tcss").resolve() +CSS_PATH.write_text( + """ +* { + max-height: 3; +} +Checkbox > .toggle--label, +DataTable > .datatable--header, +DirectoryTree > .directory-tree--file, +DirectoryTree > .directory-tree--folder, +Footer > .footer--description, +Footer > .footer--key, +Input > .input--placeholder, +Markdown > .code_inline, +Markdown > .em, +Markdown > .s, +Markdown > .strong, +OptionList > .option-list--option-highlighted, +ProgressBar Bar > .bar--bar, +RadioButton > .toggle--label, +SelectionList > .selection-list--button-highlighted, +Switch > .switch--slider, +Toast > .toast--title, +Tree > .tree--label { + text-opacity: 0%; + color: white; +} +""" +) + + class ComponentClassesOpacity(App[None]): BINDINGS = [("n", "notification", "random Notification")] - CSS = """ - * { - max-height: 3; - } - Checkbox > .toggle--label, - DataTable > .datatable--header, - DirectoryTree > .directory-tree--file, - DirectoryTree > .directory-tree--folder, - Footer > .footer--description, - Footer > .footer--key, - Input > .input--placeholder, - Markdown > .code_inline, - Markdown > .em, - Markdown > .s, - Markdown > .strong, - OptionList > .option-list--option-highlighted, - ProgressBar Bar > .bar--bar, - RadioButton > .toggle--label, - SelectionList > .selection-list--button-highlighted, - Switch > .switch--slider, - Toast > .toast--title, - Tree > .tree--label { - text-opacity: 0%; - color: white; - } - """ + CSS_PATH = CSS_PATH def compose(self) -> ComposeResult: yield Checkbox("this should be invisible") diff --git a/tests/snapshot_tests/snapshot_apps/component_classes_opacity.tcss b/tests/snapshot_tests/snapshot_apps/component_classes_opacity.tcss new file mode 100644 index 0000000000..0ce9f2b4aa --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/component_classes_opacity.tcss @@ -0,0 +1,25 @@ + +* { + max-height: 3; +} +Checkbox > .toggle--label, +DataTable > .datatable--header, +DirectoryTree > .directory-tree--file, +DirectoryTree > .directory-tree--folder, +Footer > .footer--description, +Footer > .footer--key, +Input > .input--placeholder, +Markdown > .code_inline, +Markdown > .em, +Markdown > .s, +Markdown > .strong, +OptionList > .option-list--option-highlighted, +ProgressBar Bar > .bar--bar, +RadioButton > .toggle--label, +SelectionList > .selection-list--button-highlighted, +Switch > .switch--slider, +Toast > .toast--title, +Tree > .tree--label { + text-opacity: 50%; + color:red; +} diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 08a60f36c6..66c6ea38c8 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -841,6 +841,30 @@ def test_component_classes_opacity(snap_compare) -> None: ) +# Right now, the snapshot test will show a bunch of faded red text when you inspect the snapshot +# but the markdown widget should show 4 sentences “this should be invisible” while it doesn't. +@pytest.mark.xfail( + reason="The Markdown component classes won't reload while #3464 is open, https://github.com/Textualize/textual/issues/3464" +) +def test_component_classes_opacity_reloading(snap_compare) -> None: + """Make sure that reloading CSS doesn't break""" + + async def run_before(pilot): + css_path = pilot.app.CSS_PATH + css_path.write_text( + css_path.read_text() + .replace("color: white;", "color:red;") + .replace("text-opacity: 0%;", "text-opacity: 50%;") + ) + await pilot.app._on_css_change() + + assert snap_compare( + SNAPSHOT_APPS_DIR / "component_classes_opacity.py", + terminal_size=(80, 30), + run_before=run_before, + ) + + def test_component_classes_opacity_2(snap_compare) -> None: """Regression test for