import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mattermost_push_plugin/mattermost_push_plugin.dart'; import 'package:mattermost_push_plugin_example/main.dart'; void main() { testWidgets('renders initial harness state', (WidgetTester tester) async { await tester.pumpWidget(const MyApp()); 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); await tester.pumpWidget(const SizedBox.shrink()); }); testWidgets('updates opened and navigation state from plugin events (channel)', ( WidgetTester tester, ) async { await tester.pumpWidget(const MyApp()); MattermostPushPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://mm.example.com', 'channel_id': 'channel-123', 'is_crt_enabled': 'false', }); await tester.pump(); expect( find.text( 'Last notification: type: opened, server_url: https://mm.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', ), findsOneWidget, ); expect( find.text('Last navigation: channel:https://mm.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()); MattermostPushPlugin.instance.handleNativeEvent(const { 'type': PushNotificationType.opened, 'server_url': 'https://mm.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://mm.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', ), findsOneWidget, ); expect( find.text('Last navigation: thread:https://mm.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()); MattermostPushPlugin.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()); }); }