Fix tests for buttons functionality

This commit is contained in:
Kovid Goyal 2024-07-31 15:21:57 +05:30
parent a144c267a3
commit 1f656eccbb
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 11 deletions

View file

@ -18,7 +18,7 @@ def log_notification(nc: NotificationCommand) -> None:
print('\n', file=log)
def on_notification_activated(nc: NotificationCommand) -> None:
def on_notification_activated(nc: NotificationCommand, which: int) -> None:
# do something when this notification is activated (clicked on)
# remember to assign this to the on_activation field in main()
pass

View file

@ -221,7 +221,7 @@ class NotificationCommand:
buttons: tuple[str, ...] = ()
# event callbacks
on_activation: Optional[Callable[['NotificationCommand'], None]] = None
on_activation: Optional[Callable[['NotificationCommand', int], None]] = None
on_close: Optional[Callable[['NotificationCommand'], None]] = None
on_update: Optional[Callable[['NotificationCommand', 'NotificationCommand'], None]] = None
@ -455,7 +455,7 @@ class DesktopIntegration:
def notify(self, nc: NotificationCommand, existing_desktop_notification_id: Optional[int]) -> int:
raise NotImplementedError('Implement me in subclass')
def on_new_version_notification_activation(self, cmd: NotificationCommand) -> None:
def on_new_version_notification_activation(self, cmd: NotificationCommand, which: int) -> None:
from .update_check import notification_activated
notification_activated()
@ -779,11 +779,10 @@ class NotificationManager:
if n.focus_requested:
self.channel.focus(n.channel_id, n.activation_token)
if n.report_requested:
ident = n.identifier or '0'
self.channel.send(n.channel_id, f'99;i={ident};{which or ""}')
self.channel.send(n.channel_id, f'99;i={n.identifier or "0"};{which or ""}')
if n.on_activation:
try:
n.on_activation(n)
n.on_activation(n, which)
except Exception as e:
self.log('Notification on_activation handler failed with error:', e)

View file

@ -37,8 +37,8 @@ class DesktopIntegration(DesktopIntegration):
ids = [n['id'] for n in self.notifications]
self.notification_manager.send_live_response(channel_id, client_id, tuple(ids))
def on_new_version_notification_activation(self, cmd) -> None:
self.new_version_activated = True
def on_new_version_notification_activation(self, cmd, which) -> None:
self.new_version_activated = which + 1
def close_notification(self, desktop_notification_id: int) -> bool:
self.close_events.append(desktop_notification_id)
@ -101,9 +101,9 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
def h(raw_data, osc_code=99, channel_id=1):
nm.handle_notification_cmd(channel_id, osc_code, raw_data)
def activate(which=0):
def activate(which=0, button=0):
n = di.notifications[which]
nm.notification_activated(n['id'])
nm.notification_activated(n['id'], button)
def close(which=0):
n = di.notifications[which]
@ -238,7 +238,7 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
# Test querying
h('i=xyz:p=?')
self.assertFalse(di.notifications)
qr = 'a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close,icon,alive:c=1:w=1'
qr = 'a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close,icon,alive,buttons:c=1:w=1'
self.ae(ch.responses, [f'99;i=xyz:p=?;{qr}'])
reset()
h('p=?')