Skip to content

Commit 921702b

Browse files
committed
test
1 parent 9ed0987 commit 921702b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_widget_visibility.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import Label
3+
4+
5+
async def test_hide() -> None:
6+
"""Check that setting visibility produces Hide messages."""
7+
# https://github.com/Textualize/textual/issues/3460
8+
visibility: list[bool] = []
9+
10+
class ShowHideLabel(Label):
11+
def on_show(self) -> None:
12+
visibility.append(True)
13+
14+
def on_hide(self) -> None:
15+
visibility.append(False)
16+
17+
class ShowHideApp(App[None]):
18+
BINDINGS = [("space", "toggle_label")]
19+
20+
def compose(self) -> ComposeResult:
21+
yield ShowHideLabel("Here I am")
22+
23+
def action_toggle_label(self) -> None:
24+
self.query_one(ShowHideLabel).visible = not self.query_one(
25+
ShowHideLabel
26+
).visible
27+
28+
app = ShowHideApp()
29+
async with app.run_test() as pilot:
30+
assert visibility == [True]
31+
await pilot.press("space")
32+
assert visibility == [True, False]
33+
await pilot.press("space")
34+
assert visibility == [True, False, True]

0 commit comments

Comments
 (0)