68 lines
2.1 KiB
Dart
68 lines
2.1 KiB
Dart
// SPDX-FileCopyrightText: 2026 FocusFlow contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/// Tests Fake Adapter behavior for the Scheduler Notifications package.
|
|
library;
|
|
|
|
import 'package:scheduler_notifications/notifications.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'notification_adapter_contract.dart';
|
|
|
|
/// Entry point for this executable Dart file.
|
|
/// It wires the local command, test, or application behavior needed by this repository without exposing additional public API.
|
|
void main() {
|
|
runNotificationAdapterContractTests('fake', () {
|
|
final adapter = FakeNotificationAdapter();
|
|
return NotificationAdapterContractHarness(
|
|
adapter: adapter,
|
|
scheduledRequests: () => adapter.scheduledRequests.values.toList(),
|
|
cancelledIds: () => adapter.cancelledIds,
|
|
dispose: adapter.close,
|
|
);
|
|
});
|
|
|
|
test('fake adapter stores schedules and cancellations', () async {
|
|
final adapter = FakeNotificationAdapter();
|
|
addTearDown(adapter.close);
|
|
final request = NotificationRequest(
|
|
id: ' reminder-1 ',
|
|
title: 'Start task',
|
|
body: 'Time to begin.',
|
|
scheduledDateTimeUtc: DateTime.utc(2026, 1, 1, 9),
|
|
payloadJson: '{"taskId":"task-1"}',
|
|
);
|
|
|
|
await adapter.schedule(request);
|
|
expect(adapter.scheduledRequests.keys, ['reminder-1']);
|
|
expect(
|
|
adapter.scheduledRequests['reminder-1']!.scheduledDateTimeUtc.isUtc,
|
|
isTrue,
|
|
);
|
|
|
|
await adapter.cancel(' reminder-1 ');
|
|
expect(adapter.scheduledRequests, isEmpty);
|
|
expect(adapter.cancelledIds, ['reminder-1']);
|
|
});
|
|
|
|
test('fake adapter emits feedback events', () async {
|
|
final adapter = FakeNotificationAdapter();
|
|
addTearDown(adapter.close);
|
|
final event = NotificationFeedback(
|
|
id: 'reminder-1',
|
|
type: NotificationFeedbackType.clicked,
|
|
payloadJson: '{"taskId":"task-1"}',
|
|
);
|
|
|
|
expectLater(
|
|
adapter.feedback,
|
|
emits(predicate<NotificationFeedback>((feedback) {
|
|
return feedback.id == 'reminder-1' &&
|
|
feedback.type == NotificationFeedbackType.clicked &&
|
|
feedback.payloadJson == '{"taskId":"task-1"}';
|
|
})),
|
|
);
|
|
|
|
adapter.emitFeedback(event);
|
|
});
|
|
}
|