Add a unit test for removal ordering via Widget.remove

This commit is contained in:
Dave Pearson
2022-11-10 20:34:51 +00:00
parent d378eb4291
commit 9748850657

View File

@@ -108,3 +108,19 @@ async def test_remove_move_focus():
assert len(pilot.app.screen.walk_children(with_self=False)) == 6
assert pilot.app.focused is not None
assert pilot.app.focused == buttons[9]
async def test_remove_order():
"""The removal of a top-level widget should cause bottom-first removal."""
removals: list[str] = []
class Removable(Container):
def on_unmount( self, _ ):
removals.append(self.id if self.id is not None else "unknown")
async with App().run_test() as pilot:
await pilot.app.mount(
Removable(Removable(Removable(id="grandchild"), id="child"), id="parent")
)
await pilot.app.screen.children[0].remove()
assert removals == ["grandchild", "child", "parent"]