import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:nexo_messaging/nexo_messaging.dart'; import 'package:nexo_client/main.dart'; void main() { testWidgets('renders initial harness state', (WidgetTester tester) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); expect(find.text('Device token: pending'), findsOneWidget); expect(find.text('Last notification: none'), findsOneWidget); expect(find.text('Last opened: none'), findsOneWidget); expect(find.text('Last navigation: none'), findsOneWidget); expect(find.byKey(const Key('web-permission-status')), findsOneWidget); expect(find.byKey(const Key('web-display-status')), findsOneWidget); expect( find.widgetWithText(ElevatedButton, 'Refresh web permission'), findsOneWidget, ); expect( find.widgetWithText(ElevatedButton, 'Request web permission'), findsOneWidget, ); expect( find.widgetWithText(ElevatedButton, 'Show web smoke notification'), findsOneWidget, ); expect(find.byType(TextField), findsNothing); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets('renders web smoke controls', (WidgetTester tester) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); expect(find.byKey(const Key('web-permission-status')), findsOneWidget); expect(find.byKey(const Key('web-display-status')), findsOneWidget); expect( find.widgetWithText(ElevatedButton, 'Refresh web permission'), findsOneWidget, ); expect( find.widgetWithText(ElevatedButton, 'Request web permission'), findsOneWidget, ); expect( find.widgetWithText(ElevatedButton, 'Show web smoke notification'), findsOneWidget, ); final permissionStatus = tester.widget( find.byKey(const Key('web-permission-status')), ); expect(permissionStatus.data, contains('unknown')); final displayStatus = tester.widget( find.byKey(const Key('web-display-status')), ); expect(displayStatus.data, contains('none')); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets('updates web permission status from request', ( WidgetTester tester, ) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); await tester.tap( find.widgetWithText(ElevatedButton, 'Request web permission'), ); await tester.pumpAndSettle(); final statusWidget = tester.widget( find.byKey(const Key('web-permission-status')), ); expect(statusWidget.data, contains('unsupported')); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets('updates web display result on unsupported VM', ( WidgetTester tester, ) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); await tester.tap( find.widgetWithText(ElevatedButton, 'Show web smoke notification'), ); await tester.pump(); final displayWidget = tester.widget( find.byKey(const Key('web-display-status')), ); expect(displayWidget.data, contains('unsupported')); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets('opened event still drives click routing status', ( WidgetTester tester, ) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); NexoMessagingPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://nexo.example.com', 'channel_id': 'channel-123', 'is_crt_enabled': 'false', }); await tester.pump(); expect( find.text( '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://nexo.example.com/channel-123'), findsOneWidget, ); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets( 'updates opened and navigation state from plugin events (channel)', (WidgetTester tester) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); NexoMessagingPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://nexo.example.com', 'channel_id': 'channel-123', 'is_crt_enabled': 'false', }); await tester.pump(); expect( find.text( '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://nexo.example.com, channel_id: channel-123, root_id: null, is_crt_enabled: false', ), findsOneWidget, ); expect( find.text( 'Last navigation: channel:https://nexo.example.com/channel-123', ), findsOneWidget, ); await tester.pumpWidget(const SizedBox.shrink()); }, ); testWidgets( 'updates opened and navigation state from plugin events (thread/CRT)', (WidgetTester tester) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); NexoMessagingPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://nexo.example.com', 'channel_id': 'channel-123', 'root_id': 'thread-456', 'is_crt_enabled': 'true', }); await tester.pump(); expect( find.text( '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://nexo.example.com, channel_id: channel-123, root_id: thread-456, is_crt_enabled: true', ), findsOneWidget, ); expect( find.text( 'Last navigation: thread:https://nexo.example.com/thread-456', ), findsOneWidget, ); await tester.pumpWidget(const SizedBox.shrink()); }, ); testWidgets( 'updates opened and navigation state from plugin events (boolean CRT)', (WidgetTester tester) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); NexoMessagingPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://nexo.example.com', 'channel_id': 'channel-123', 'root_id': 'thread-456', 'is_crt_enabled': true, }); await tester.pump(); expect( find.text( '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://nexo.example.com/thread-456', ), findsOneWidget, ); await tester.pumpWidget(const SizedBox.shrink()); }, ); testWidgets('updates device token from plugin callback', ( WidgetTester tester, ) async { await tester.pumpWidget(const MyApp(initializePlugin: false)); NexoMessagingPlugin.instance.onDeviceTokenReady?.call( 'test-device-token-123', ); await tester.pump(); expect(find.text('Device token: test-device-token-123'), findsOneWidget); await tester.pumpWidget(const SizedBox.shrink()); }); }