Update client and messaging_flutter files
This commit is contained in:
parent
d9c41aa4c4
commit
7ed9a7be89
10 changed files with 75 additions and 75 deletions
|
|
@ -1,17 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:mattermost_push_plugin/mattermost_push_plugin.dart';
|
||||
import 'package:nexo_messaging/nexo_messaging.dart';
|
||||
import 'package:nexo_client/main.dart';
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
testWidgets('singleton instance is accessible', (WidgetTester tester) async {
|
||||
expect(MattermostPushPlugin.instance, isNotNull);
|
||||
expect(NexoMessagingPlugin.instance, isNotNull);
|
||||
expect(
|
||||
MattermostPushPlugin.notificationChannelName,
|
||||
'com.tokilabs.mattermost/notifications',
|
||||
NexoMessagingPlugin.notificationChannelName,
|
||||
'com.tokilabs.nexo.messaging/notifications',
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -20,10 +20,10 @@ void main() {
|
|||
) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
MattermostPushPlugin.instance.listenNativeChannelForTesting();
|
||||
await MattermostPushPlugin.instance.debugSendNativeEventForTesting(const {
|
||||
NexoMessagingPlugin.instance.listenNativeChannelForTesting();
|
||||
await NexoMessagingPlugin.instance.debugSendNativeEventForTesting(const {
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-integration',
|
||||
});
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ void main() {
|
|||
expect(find.textContaining('channel-integration'), findsWidgets);
|
||||
expect(
|
||||
find.text(
|
||||
'Last navigation: channel:https://mm.example.com/channel-integration',
|
||||
'Last navigation: channel:https://nexo.example.com/channel-integration',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
|
@ -46,10 +46,10 @@ void main() {
|
|||
) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
MattermostPushPlugin.instance.listenNativeChannelForTesting();
|
||||
await MattermostPushPlugin.instance.debugSendNativeEventForTesting(const {
|
||||
NexoMessagingPlugin.instance.listenNativeChannelForTesting();
|
||||
await NexoMessagingPlugin.instance.debugSendNativeEventForTesting(const {
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-integration',
|
||||
'root_id': 'root-integration',
|
||||
'is_crt_enabled': 'true',
|
||||
|
|
@ -61,7 +61,7 @@ void main() {
|
|||
expect(find.textContaining('root-integration'), findsWidgets);
|
||||
expect(
|
||||
find.text(
|
||||
'Last navigation: thread:https://mm.example.com/root-integration',
|
||||
'Last navigation: thread:https://nexo.example.com/root-integration',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mattermost_push_plugin/mattermost_push_plugin.dart';
|
||||
import 'package:nexo_messaging/nexo_messaging.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
|
|
@ -25,7 +25,7 @@ class _MyAppState extends State<MyApp> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final plugin = MattermostPushPlugin.instance;
|
||||
final plugin = NexoMessagingPlugin.instance;
|
||||
plugin.onDeviceTokenReady = (token) {
|
||||
if (!mounted) return;
|
||||
setState(() => _deviceToken = token);
|
||||
|
|
@ -52,7 +52,7 @@ class _MyAppState extends State<MyApp> {
|
|||
void dispose() {
|
||||
_notificationSubscription?.cancel();
|
||||
_openedSubscription?.cancel();
|
||||
final plugin = MattermostPushPlugin.instance;
|
||||
final plugin = NexoMessagingPlugin.instance;
|
||||
plugin.onDeviceTokenReady = null;
|
||||
plugin.onNavigateToChannel = null;
|
||||
plugin.onNavigateToThread = null;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import Foundation
|
|||
|
||||
import firebase_core
|
||||
import firebase_messaging
|
||||
import mattermost_push_plugin
|
||||
import nexo_messaging
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
|
||||
|
|
|
|||
|
|
@ -207,13 +207,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.13.0"
|
||||
mattermost_push_plugin:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../packages/messaging_flutter"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -222,6 +215,13 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.0"
|
||||
nexo_messaging:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../packages/messaging_flutter"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ dependencies:
|
|||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
mattermost_push_plugin:
|
||||
nexo_messaging:
|
||||
path: ../../packages/messaging_flutter
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mattermost_push_plugin/mattermost_push_plugin.dart';
|
||||
import 'package:nexo_messaging/nexo_messaging.dart';
|
||||
import 'package:nexo_client/main.dart';
|
||||
|
||||
void main() {
|
||||
|
|
@ -20,9 +20,9 @@ void main() {
|
|||
) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
MattermostPushPlugin.instance.handleNativeEvent(const {
|
||||
NexoMessagingPlugin.instance.handleNativeEvent(const {
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
'is_crt_enabled': 'false',
|
||||
});
|
||||
|
|
@ -30,18 +30,18 @@ void main() {
|
|||
|
||||
expect(
|
||||
find.text(
|
||||
'Last notification: type: opened, server_url: https://mm.example.com, channel_id: channel-123, is_crt_enabled: false',
|
||||
'Last notification: type: opened, server_url: https://nexo.example.com, channel_id: channel-123, is_crt_enabled: false',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
'Last opened: server_url: https://mm.example.com, channel_id: channel-123, root_id: null, is_crt_enabled: false',
|
||||
'Last opened: server_url: https://nexo.example.com, channel_id: channel-123, root_id: null, is_crt_enabled: false',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text('Last navigation: channel:https://mm.example.com/channel-123'),
|
||||
find.text('Last navigation: channel:https://nexo.example.com/channel-123'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
|
|
@ -53,9 +53,9 @@ void main() {
|
|||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
MattermostPushPlugin.instance.handleNativeEvent(const {
|
||||
NexoMessagingPlugin.instance.handleNativeEvent(const {
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
'root_id': 'thread-456',
|
||||
'is_crt_enabled': 'true',
|
||||
|
|
@ -64,18 +64,18 @@ void main() {
|
|||
|
||||
expect(
|
||||
find.text(
|
||||
'Last notification: type: opened, server_url: https://mm.example.com, channel_id: channel-123, root_id: thread-456, is_crt_enabled: true',
|
||||
'Last notification: type: opened, server_url: https://nexo.example.com, channel_id: channel-123, root_id: thread-456, is_crt_enabled: true',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
'Last opened: server_url: https://mm.example.com, channel_id: channel-123, root_id: thread-456, is_crt_enabled: true',
|
||||
'Last opened: server_url: https://nexo.example.com, channel_id: channel-123, root_id: thread-456, is_crt_enabled: true',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text('Last navigation: thread:https://mm.example.com/thread-456'),
|
||||
find.text('Last navigation: thread:https://nexo.example.com/thread-456'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ void main() {
|
|||
) async {
|
||||
await tester.pumpWidget(const MyApp());
|
||||
|
||||
MattermostPushPlugin.instance.onDeviceTokenReady?.call(
|
||||
NexoMessagingPlugin.instance.onDeviceTokenReady?.call(
|
||||
'test-device-token-123',
|
||||
);
|
||||
await tester.pump();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export 'src/mattermost_push_plugin.dart';
|
||||
export 'src/nexo_messaging_plugin.dart';
|
||||
export 'src/notification_opened_event.dart';
|
||||
export 'src/push_notification_type.dart';
|
||||
|
|
@ -8,14 +8,14 @@ import 'notification_opened_event.dart';
|
|||
import 'push_notification_type.dart';
|
||||
|
||||
const String _kNotificationChannelName =
|
||||
'com.tokilabs.mattermost/notifications';
|
||||
'com.tokilabs.nexo.messaging/notifications';
|
||||
const String _kActionChannelName =
|
||||
'com.tokilabs.mattermost/notification_actions';
|
||||
'com.tokilabs.nexo.messaging/notification_actions';
|
||||
const String _kDeviceTokenPrefix = 'android_rn';
|
||||
|
||||
class MattermostPushPlugin {
|
||||
MattermostPushPlugin._();
|
||||
static final MattermostPushPlugin instance = MattermostPushPlugin._();
|
||||
class NexoMessagingPlugin {
|
||||
NexoMessagingPlugin._();
|
||||
static final NexoMessagingPlugin instance = NexoMessagingPlugin._();
|
||||
|
||||
@visibleForTesting
|
||||
static const String notificationChannelName = _kNotificationChannelName;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
name: mattermost_push_plugin
|
||||
description: "Mattermost push notification Flutter plugin. Android-first; iOS/macOS scaffold only."
|
||||
name: nexo_messaging
|
||||
description: "Nexo messaging and notification Flutter plugin. Android-first; iOS/macOS scaffold only."
|
||||
version: 0.0.1
|
||||
publish_to: 'none'
|
||||
homepage:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mattermost_push_plugin/mattermost_push_plugin.dart';
|
||||
import 'package:nexo_messaging/nexo_messaging.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
|
@ -10,13 +10,13 @@ void main() {
|
|||
group('NotificationOpenedEvent.fromMap', () {
|
||||
test('parses server_url, channel_id, root_id, is_crt_enabled', () {
|
||||
final event = NotificationOpenedEvent.fromMap({
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
'root_id': 'root-456',
|
||||
'is_crt_enabled': 'true',
|
||||
});
|
||||
|
||||
expect(event.serverUrl, 'https://mm.example.com');
|
||||
expect(event.serverUrl, 'https://nexo.example.com');
|
||||
expect(event.channelId, 'channel-123');
|
||||
expect(event.rootId, 'root-456');
|
||||
expect(event.isCRTEnabled, isTrue);
|
||||
|
|
@ -24,7 +24,7 @@ void main() {
|
|||
|
||||
test('defaults isCRTEnabled to false when flag is absent or non-true', () {
|
||||
final missing = NotificationOpenedEvent.fromMap({
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
});
|
||||
expect(missing.isCRTEnabled, isFalse);
|
||||
|
|
@ -36,12 +36,12 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
group('MattermostPushPlugin.handleNativeEvent', () {
|
||||
late MattermostPushPlugin plugin;
|
||||
final actionChannel = MethodChannel(MattermostPushPlugin.actionChannelName);
|
||||
group('NexoMessagingPlugin.handleNativeEvent', () {
|
||||
late NexoMessagingPlugin plugin;
|
||||
final actionChannel = MethodChannel(NexoMessagingPlugin.actionChannelName);
|
||||
|
||||
setUp(() {
|
||||
plugin = MattermostPushPlugin.instance;
|
||||
plugin = NexoMessagingPlugin.instance;
|
||||
plugin.onNavigateToChannel = null;
|
||||
plugin.onNavigateToThread = null;
|
||||
plugin.onDeviceTokenReady = null;
|
||||
|
|
@ -57,12 +57,12 @@ void main() {
|
|||
|
||||
plugin.handleNativeEvent({
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
});
|
||||
|
||||
final event = await future;
|
||||
expect(event.serverUrl, 'https://mm.example.com');
|
||||
expect(event.serverUrl, 'https://nexo.example.com');
|
||||
expect(event.channelId, 'channel-123');
|
||||
});
|
||||
|
||||
|
|
@ -79,11 +79,11 @@ void main() {
|
|||
plugin.handleNativeEvent({
|
||||
'type': PushNotificationType.message,
|
||||
'userInteraction': true,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-xyz',
|
||||
});
|
||||
|
||||
expect(navServer, 'https://mm.example.com');
|
||||
expect(navServer, 'https://nexo.example.com');
|
||||
expect(navChannel, 'channel-xyz');
|
||||
},
|
||||
);
|
||||
|
|
@ -98,13 +98,13 @@ void main() {
|
|||
|
||||
plugin.handleNativeEvent({
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-123',
|
||||
'root_id': 'root-789',
|
||||
'is_crt_enabled': 'true',
|
||||
});
|
||||
|
||||
expect(navServer, 'https://mm.example.com');
|
||||
expect(navServer, 'https://nexo.example.com');
|
||||
expect(navRoot, 'root-789');
|
||||
});
|
||||
|
||||
|
|
@ -141,13 +141,13 @@ void main() {
|
|||
() async {
|
||||
String? channelToken;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(actionChannel, (call) async {
|
||||
if (call.method == 'saveDeviceToken') {
|
||||
final args = call.arguments as Map;
|
||||
channelToken = args['token'] as String?;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
.setMockMethodCallHandler(actionChannel, (call) async {
|
||||
if (call.method == 'saveDeviceToken') {
|
||||
final args = call.arguments as Map;
|
||||
channelToken = args['token'] as String?;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final completer = Completer<String>();
|
||||
plugin.onDeviceTokenReady = completer.complete;
|
||||
|
|
@ -168,21 +168,21 @@ void main() {
|
|||
() async {
|
||||
MethodCall? capturedCall;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(actionChannel, (call) async {
|
||||
capturedCall = call;
|
||||
return null;
|
||||
});
|
||||
.setMockMethodCallHandler(actionChannel, (call) async {
|
||||
capturedCall = call;
|
||||
return null;
|
||||
});
|
||||
|
||||
await plugin.debugSendNativeEventForTesting({
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-debug',
|
||||
});
|
||||
|
||||
expect(capturedCall?.method, 'debugSendNativeEvent');
|
||||
expect(capturedCall?.arguments, {
|
||||
'type': PushNotificationType.opened,
|
||||
'server_url': 'https://mm.example.com',
|
||||
'server_url': 'https://nexo.example.com',
|
||||
'channel_id': 'channel-debug',
|
||||
});
|
||||
},
|
||||
|
|
@ -192,12 +192,12 @@ void main() {
|
|||
group('Channel constants', () {
|
||||
test('notification and action channel names are preserved', () {
|
||||
expect(
|
||||
MattermostPushPlugin.notificationChannelName,
|
||||
'com.tokilabs.mattermost/notifications',
|
||||
NexoMessagingPlugin.notificationChannelName,
|
||||
'com.tokilabs.nexo.messaging/notifications',
|
||||
);
|
||||
expect(
|
||||
MattermostPushPlugin.actionChannelName,
|
||||
'com.tokilabs.mattermost/notification_actions',
|
||||
NexoMessagingPlugin.actionChannelName,
|
||||
'com.tokilabs.nexo.messaging/notification_actions',
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue