nexo/apps/flutter-test/test/widget_test.dart

116 lines
3.6 KiB
Dart

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);
// Thin host contract: body contains exactly 4 status Text widgets
// and no product UI controls.
final listViewFinder = find.byType(ListView);
expect(listViewFinder, findsOneWidget);
final statusTexts = find.descendant(
of: listViewFinder,
matching: find.byType(Text),
);
expect(statusTexts, findsNWidgets(4));
expect(find.byType(ElevatedButton), findsNothing);
expect(find.byType(TextField), findsNothing);
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 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());
});
}