Files
pipelines/app/test/features/attention/notify/notification_ledger_test.dart
T
alan 7718604268 feat(app): add the notification capability behind a platform seam
An abstract NotificationBridge with a dart:js_interop web implementation and
an honest unsupported stub; a NotificationController that reports only the
platform's permission word, asks only from an explicit gesture, never
re-prompts a denied answer, and notifies once per run+kind+finished marker
under its own persisted ledger key. One reusable native
NotificationPermissionTile for Settings, an isolated browser probe, and
focused tests. No shell/settings wiring.
2026-10-22 01:23:24 +01:00

90 lines
3.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/attention/notify/notification_ledger.dart';
import 'notification_test_support.dart';
void main() {
group('the identity carries the finished marker', () {
test('a recorded finish time distinguishes two failures of one run', () {
final first = transitionFor(7, finishedAt: '2026-10-22T09:10:00Z');
final second = transitionFor(7, finishedAt: '2026-10-22T11:30:00Z');
expect(notificationIdentity(first), '7:Failed@2026-10-22T09:10:00Z');
expect(notificationIdentity(second), '7:Failed@2026-10-22T11:30:00Z');
expect(notificationIdentity(first), isNot(notificationIdentity(second)));
});
test('a run without a finish time falls back to its creation time', () {
final entry = transitionFor(7, status: 'waiting', finishedAt: '');
expect(
notificationIdentity(entry),
'7:Decision@${attentionNow.subtract(const Duration(hours: 1)).toIso8601String()}',
);
});
test('the kind separates a decision from a failure of one run', () {
expect(
notificationIdentity(transitionFor(7)),
isNot(notificationIdentity(transitionFor(7, status: 'waiting'))),
);
});
});
group('the ledger records identities', () {
test('recording is idempotent and never mutates the original', () {
const base = NotificationLedger();
final once = base.recording('7:Failed@a');
final twice = once.recording('7:Failed@a');
expect(base.notified, isEmpty);
expect(once.hasNotified('7:Failed@a'), isTrue);
expect(twice.notified, {'7:Failed@a'});
});
test('asked is carried without touching the identities', () {
final asked = const NotificationLedger(
notified: {'a'},
).withAsked(true);
expect(asked.asked, isTrue);
expect(asked.notified, {'a'});
});
});
group('persistence is total', () {
test('a round trip keeps the asked flag and the identities', () {
final ledger = const NotificationLedger(
notified: {'b', 'a'},
).withAsked(true);
final decoded = decodeNotificationLedger(encodeNotificationLedger(ledger));
expect(decoded.asked, isTrue);
expect(decoded.notified, {'a', 'b'});
});
test('an unchanged ledger always encodes to the same bytes', () {
final first = encodeNotificationLedger(
const NotificationLedger(notified: {'b', 'a'}),
);
final second = encodeNotificationLedger(
const NotificationLedger(notified: {'a', 'b'}),
);
expect(first, second);
});
test('blank, malformed and wrong-typed values never throw', () {
expect(decodeNotificationLedger(null).notified, isEmpty);
expect(decodeNotificationLedger('').asked, isFalse);
expect(decodeNotificationLedger('not json').notified, isEmpty);
expect(decodeNotificationLedger('[]').notified, isEmpty);
expect(decodeNotificationLedger('"text"').notified, isEmpty);
expect(
decodeNotificationLedger('{"asked":"yes","notified":[1,null,"a",""]}')
.notified,
{'a'},
);
expect(
decodeNotificationLedger('{"asked":"yes"}').asked,
isFalse,
reason: 'only a real true counts as asked',
);
});
});
}