Add test for filtering

This commit is contained in:
Kovid Goyal
2024-07-28 09:15:18 +05:30
parent 67410c317f
commit 59c175f312
2 changed files with 18 additions and 1 deletions

View File

@@ -685,11 +685,15 @@ class NotificationManager:
return False
return True
@property
def filter_rules(self) -> Iterator[str]:
return iter(get_options().filter_notification.keys())
def is_notification_filtered(self, cmd: NotificationCommand) -> bool:
if self.filter_script(cmd):
self.log(f'Notification {cmd.title!r} filtered out by script')
return True
for rule in get_options().filter_notification:
for rule in self.filter_rules:
if cmd.matches_rule(rule):
self.log(f'Notification {cmd.title!r} filtered out by filter_notification rule: {rule}')
return True

View File

@@ -69,6 +69,13 @@ class Channel(Channel):
self.responses.append(osc_escape_code)
class NotificationManager(NotificationManager):
@property
def filter_rules(self):
yield from ('title:filterme',)
def do_test(self: 'TestNotifications', tdir: str) -> None:
di = DesktopIntegration(None)
ch = Channel()
@@ -162,6 +169,12 @@ def do_test(self: 'TestNotifications', tdir: str) -> None:
self.ae(di.notifications, [n()])
reset()
# test filtering
h(';title')
h(';filterme please')
self.ae(di.notifications, [n()])
reset()
# test closing interactions with reporting and activation
h('i=c;title')
self.ae(di.notifications, [n()])