Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 24, 2024
1 parent 67e9294 commit 0b07ab6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3029,14 +3029,7 @@ def simulate_key(self, key: str) -> None:
Args:
key: Key to simulate. May also be the name of a key, e.g. "space".
"""
event = events.Key(key, None)
self.post_message(event)

# async def dispatch_simulated_key() -> None:
# if not (await self._check_bindings(event.key, priority=True)):
# await dispatch_key(self, event)

# self.call_later(dispatch_simulated_key)
self.post_message(events.Key(key, None))

async def _check_bindings(self, key: str, priority: bool = False) -> bool:
"""Handle a key press.
Expand Down
1 change: 1 addition & 0 deletions src/textual/pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ async def _post_mouse_events(
# E.g., the click event is preceded by MouseDown/MouseUp to emulate how
# the driver works and emits a click event.
widget_at, _ = app.get_widget_at(*offset)
print(widget_at)
event = mouse_event_cls(**message_arguments)
# Bypass event processing in App.on_event. Because App.on_event
# is responsible for updating App.mouse_position, and because
Expand Down
58 changes: 58 additions & 0 deletions tests/footer/test_footer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widget import Widget
from textual.widgets import Button, Footer


async def test_footer_bindings() -> None:
app_binding_count = 0

class TestWidget(Widget, can_focus=True):
BINDINGS = [
Binding("b", "widget_binding", "Overridden Binding"),
]

DEFAULT_CSS = """
TestWidget {
border: tall $background;
width: 50%;
height: 50%;
content-align: center middle;
&:focus {
border: tall $accent;
}
}
"""

def action_widget_binding(self) -> None:
assert False, "should never be called since there is a priority binding"

class PriorityBindingApp(App):
BINDINGS = [
Binding("b", "app_binding", "Priority Binding", priority=True),
]

CSS = """
Screen {
align: center middle;
}
"""

def compose(self) -> ComposeResult:
yield TestWidget()
yield Button("Move Focus")
yield Footer()

def action_app_binding(self) -> None:
nonlocal app_binding_count
app_binding_count += 1

app = PriorityBindingApp()
async with app.run_test() as pilot:
await pilot.pause()
assert app_binding_count == 0
await pilot.click("Footer", offset=(1, 0))
assert app_binding_count == 1
await pilot.click("Footer")
assert app_binding_count == 2

0 comments on commit 0b07ab6

Please sign in to comment.