mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Add tests for alive queries
This commit is contained in:
@@ -489,10 +489,12 @@ live_delivered_notifications(void) {
|
|||||||
UNUserNotificationCenter *center = get_notification_center_safely();
|
UNUserNotificationCenter *center = get_notification_center_safely();
|
||||||
if (!center) return false;
|
if (!center) return false;
|
||||||
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * notifications) {
|
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * notifications) {
|
||||||
NSMutableString *buffer = [[NSMutableString stringWithCapacity:1024] autorelease];
|
@autoreleasepool {
|
||||||
for (UNNotification *n in notifications) [buffer appendFormat:@"%@,", [[n request] identifier]];
|
NSMutableString *buffer = [NSMutableString stringWithCapacity:1024]; // autoreleased
|
||||||
const char *val = [buffer UTF8String];
|
for (UNNotification *n in notifications) [buffer appendFormat:@"%@,", [[n request] identifier]];
|
||||||
set_cocoa_pending_action(COCOA_NOTIFICATION_UNTRACKED, val ? val : "");
|
const char *val = [buffer UTF8String];
|
||||||
|
set_cocoa_pending_action(COCOA_NOTIFICATION_UNTRACKED, val ? val : "");
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ class DesktopIntegration(DesktopIntegration):
|
|||||||
self.close_succeeds = True
|
self.close_succeeds = True
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
|
||||||
|
def query_live_notifications(self, channel_id, client_id):
|
||||||
|
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:
|
def on_new_version_notification_activation(self, cmd) -> None:
|
||||||
self.new_version_activated = True
|
self.new_version_activated = True
|
||||||
|
|
||||||
@@ -102,7 +106,7 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
|
|||||||
n = di.notifications[which]
|
n = di.notifications[which]
|
||||||
di.close_notification(n['id'])
|
di.close_notification(n['id'])
|
||||||
|
|
||||||
def assert_events(focus=True, close=0, report='', close_response=''):
|
def assert_events(focus=True, close=0, report='', close_response='', live=''):
|
||||||
self.ae(ch.focus_events, [''] if focus else [])
|
self.ae(ch.focus_events, [''] if focus else [])
|
||||||
if report:
|
if report:
|
||||||
self.assertIn(f'99;i={report};', ch.responses)
|
self.assertIn(f'99;i={report};', ch.responses)
|
||||||
@@ -116,6 +120,12 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
|
|||||||
for r in ch.responses:
|
for r in ch.responses:
|
||||||
m = re.match(r'99;i=[a-z0-9]+:p=close;', r)
|
m = re.match(r'99;i=[a-z0-9]+:p=close;', r)
|
||||||
self.assertIsNone(m, f'Unexpectedly found close response: {r}')
|
self.assertIsNone(m, f'Unexpectedly found close response: {r}')
|
||||||
|
if live:
|
||||||
|
self.assertIn(f'99;i=live:p=alive;{live}', ch.responses)
|
||||||
|
else:
|
||||||
|
for r in ch.responses:
|
||||||
|
m = re.match(r'99;i=[a-z0-9]+:p=alive;', r)
|
||||||
|
self.assertIsNone(m, f'Unexpectedly found alive response: {r}')
|
||||||
self.ae(di.close_events, [close] if close else [])
|
self.ae(di.close_events, [close] if close else [])
|
||||||
|
|
||||||
h('test it', osc_code=9)
|
h('test it', osc_code=9)
|
||||||
@@ -210,6 +220,12 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
|
|||||||
assert_events(focus=True, report='c', close=True, close_response='c')
|
assert_events(focus=True, report='c', close=True, close_response='c')
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
|
h('i=a;title')
|
||||||
|
h('i=b;title')
|
||||||
|
h('i=live:p=alive;')
|
||||||
|
assert_events(focus=False, live='a,b')
|
||||||
|
reset()
|
||||||
|
|
||||||
h(';title')
|
h(';title')
|
||||||
self.ae(di.notifications, [n()])
|
self.ae(di.notifications, [n()])
|
||||||
activate()
|
activate()
|
||||||
|
|||||||
Reference in New Issue
Block a user