Port the notifications test to handle urgency

This commit is contained in:
Kovid Goyal 2024-05-16 21:45:15 +05:30
parent 865f662216
commit d9631cdedd
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -15,7 +15,7 @@ from kitty.fast_data_types import (
test_find_either_of_two_bytes,
test_utf8_decode_to_sentinel,
)
from kitty.notify import NotificationCommand, handle_notification_cmd, notification_activated, reset_registry
from kitty.notify import NotificationCommand, Urgency, handle_notification_cmd, notification_activated, reset_registry
from . import BaseTest, parse_bytes
@ -534,8 +534,8 @@ class TestParser(BaseTest):
del activations[:]
prev_cmd = NotificationCommand()
def notify(title, body, identifier):
notifications.append((title, body, identifier))
def notify(title, body, identifier, urgency=Urgency.Normal):
notifications.append((title, body, identifier, urgency))
def h(raw_data, osc_code=99, window_id=1):
nonlocal prev_cmd
@ -547,40 +547,40 @@ class TestParser(BaseTest):
activations.append((identifier, window_id, focus, report))
h('test it', osc_code=9)
self.ae(notifications, [('test it', '', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('test it', '', 'i0', Urgency.Normal)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [('0', 1, True, False)])
reset()
h('d=0:i=x;title')
h('d=0:u=2:i=x;title')
h('d=1:i=x:p=body;body')
self.ae(notifications, [('title', 'body', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('title', 'body', 'i0', Urgency.Critical)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [('x', 1, True, False)])
reset()
h('i=x:p=body:a=-focus;body')
self.ae(notifications, [('body', '', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('body', '', 'i0', Urgency.Normal)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [])
reset()
h('i=x:e=1;' + standard_b64encode(b'title').decode('ascii'))
self.ae(notifications, [('title', '', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('title', '', 'i0', Urgency.Normal)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [('x', 1, True, False)])
reset()
h('d=0:i=x:a=-report;title')
h('d=1:i=x:a=report;body')
self.ae(notifications, [('titlebody', '', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('titlebody', '', 'i0', Urgency.Normal)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [('x', 1, True, True)])
reset()
h(';title')
self.ae(notifications, [('title', '', 'i0')])
notification_activated(notifications[-1][-1], activated)
self.ae(notifications, [('title', '', 'i0', Urgency.Normal)])
notification_activated(notifications[-1][-2], activated)
self.ae(activations, [('0', 1, True, False)])
reset()