53 lines
1.8 KiB
Dart
53 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:marianum_mobile/push/push_tap_router.dart';
|
|
import 'package:marianum_mobile/push/push_target.dart';
|
|
|
|
void main() {
|
|
group('resolvePushTarget', () {
|
|
test('newsletter pushes route by newsletterId', () {
|
|
expect(
|
|
resolvePushTarget({'source': 'connect', 'newsletterId': 'n1'}),
|
|
isA<NewsletterTarget>().having((t) => t.newsletterId, 'id', 'n1'),
|
|
);
|
|
});
|
|
|
|
test('chat pushes accept every token key in use', () {
|
|
for (final key in ['chatToken', 'token', 'roomToken']) {
|
|
expect(
|
|
resolvePushTarget({key: 'abc', 'nid': 5}),
|
|
isA<ChatTarget>().having((t) => t.chatToken, 'chatToken', 'abc'),
|
|
reason: key,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('empty ids and unrelated data name no target', () {
|
|
expect(resolvePushTarget({'newsletterId': ''}), isNull);
|
|
expect(resolvePushTarget({'type': 'widget-refresh'}), isNull);
|
|
expect(resolvePushTarget({'chatToken': 7}), isNull);
|
|
});
|
|
});
|
|
|
|
group('PushTapRouter.handleResponse', () {
|
|
setUp(() => PushTapRouter.pendingTarget.value = null);
|
|
|
|
NotificationResponse tap(String payload) => NotificationResponse(
|
|
notificationResponseType: NotificationResponseType.selectedNotification,
|
|
payload: payload,
|
|
);
|
|
|
|
test('publishes the target of a tapped notification', () {
|
|
PushTapRouter.handleResponse(tap(jsonEncode({'newsletterId': 'n1'})));
|
|
expect(PushTapRouter.pendingTarget.value, isA<NewsletterTarget>());
|
|
});
|
|
|
|
test('ignores broken payloads', () {
|
|
PushTapRouter.handleResponse(tap('not json'));
|
|
expect(PushTapRouter.pendingTarget.value, isNull);
|
|
});
|
|
});
|
|
}
|