Skip to content

Commit edd5b60

Browse files
Tweak tests to check unsetting works.
1 parent bd5c9ee commit edd5b60

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

tests/test_tabbed_content.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,33 @@ def compose(self) -> ComposeResult:
108108
with pytest.raises(ValueError):
109109
tabbed_content.active = "X"
110110

111-
# Check fail with empty tab
112-
with pytest.raises(ValueError):
113-
tabbed_content.active = ""
111+
112+
async def test_unsetting_tabbed_content_active():
113+
"""Check that setting `TabbedContent.active = ""` unsets active tab."""
114+
115+
messages = []
116+
117+
class TabbedApp(App[None]):
118+
def compose(self) -> ComposeResult:
119+
with TabbedContent(initial="bar"):
120+
with TabPane("foo", id="foo"):
121+
yield Label("Foo", id="foo-label")
122+
with TabPane("bar", id="bar"):
123+
yield Label("Bar", id="bar-label")
124+
with TabPane("baz", id="baz"):
125+
yield Label("Baz", id="baz-label")
126+
127+
def on_tabbed_content_cleared(self, event: TabbedContent.Cleared) -> None:
128+
messages.append(event)
129+
130+
app = TabbedApp()
131+
async with app.run_test() as pilot:
132+
tabbed_content = app.query_one(TabbedContent)
133+
assert bool(tabbed_content.active)
134+
tabbed_content.active = ""
135+
await pilot.pause()
136+
assert len(messages) == 1
137+
assert isinstance(messages[0], TabbedContent.Cleared)
114138

115139

116140
async def test_tabbed_content_initial():

tests/test_tabs.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,8 @@ def compose(self) -> ComposeResult:
316316
assert tabs.active_tab.id == "tab-2"
317317
assert tabs.active == tabs.active_tab.id
318318

319-
# TODO: This one is questionable. It seems Tabs has been designed so
320-
# that you can set the active tab to an empty string, and it remains
321-
# so, and just removes the underline; no other changes. So active
322-
# will be an empty string while active_tab will be a tab. This feels
323-
# like an oversight. Need to investigate and possibly modify this
324-
# behaviour unless there's a good reason for this.
325319
tabs.active = ""
326-
assert tabs.active_tab is not None
327-
assert tabs.active_tab.id == "tab-2"
320+
assert tabs.active_tab is None
328321

329322

330323
async def test_navigate_tabs_with_keyboard():

0 commit comments

Comments
 (0)