Files
faceclaw/tests/dismiss-all-notifications.test.cjs
T

70 lines
3.1 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const { loader } = require('./helpers/load-typescript.cjs');
test('Notifications menu dismisses all, including beyond the visible list, and leaves filters untouched', () => {
let options, active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) }));
let dismissals = 0, renders = 0, pops = 0;
const load = loader({}, {
'../../ui/notifications': { NotificationsListLayer: class {} },
'../../ui/notification-filter': { NotificationFilterLayer: class {} },
'../../native/notification-icons': {
ALL_NOTIFICATIONS: 0x7fffffff,
readActiveNotifications(max) { assert.equal(max, 0x7fffffff); return active; },
dismissAllNotifications() { dismissals++; active = []; return true; },
onAndroidNotificationsChanged: () => () => {},
},
'../../ui/shell/in-process-window': {
YieldAtRootLayer: class {},
createInProcessWindow(value) { options = value; return { requestRender() { renders++; } }; },
},
});
load('app/apps/notifications/notifications-app.ts').createNotificationsAppWindow({});
const items = options.menuItems();
assert.equal(items[0].label, 'Notification filter');
const action = items.find(x => x.label === 'Dismiss all notifications');
assert.equal(action.disabled(), false);
assert.equal(dismissals, 0);
action.onSelect({ stack: { pop() { pops++; } } });
assert.equal(dismissals, 1);
assert.equal(pops, 1);
assert.equal(renders, 1);
assert.equal(action.disabled(), true);
});
test('Android bulk action uses the native listener and propagates unavailable access', () => {
let calls = 0, allowed = false;
const load = loader({ global: { isAndroid: true }, com: { faceclaw: { app: {
FaceclawMediaNotificationListenerService: { dismissAllNotifications() { calls++; return allowed; } },
} } } }, {
'../graphics/image': {}, './frame-timings': {}, '../util/array-util': {},
'./notification-sources': {}, './image-files': { PHOTO_TONE: { gamma: 1 } }, './notification-types': { NOTIFICATION_ICON_SIZE: 24 },
});
const api = load('app/native/notification-icons.ts');
assert.equal(api.dismissAllNotifications(), false);
allowed = true;
assert.equal(api.dismissAllNotifications(), true);
assert.equal(calls, 2);
});
test('iOS snapshots all ANCS keys and continues when a notification cannot be dismissed', () => {
const load = loader({}, {
'../graphics/pebble-icons': {}, '../g2/ancs-client': {}, './notification-app-icons': {}, './notification-sources': {},
});
const api = load('app/native/notification-icons.ios.ts');
assert.equal(api.dismissAllNotifications(), false);
const active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) })), attempted = [];
api.bindIosNotifications({
read(max) { assert.equal(max, api.ALL_NOTIFICATIONS); return active; },
dismiss(key) {
attempted.push(key);
if (key === '1') return false;
active.splice(active.findIndex(x => x.key === key), 1);
return true;
},
});
assert.equal(api.dismissAllNotifications(), false);
assert.equal(attempted.length, 80);
assert.deepEqual(active, [{ key: '1' }]);
});