|
1 | 1 | import 'dart:async';
|
2 | 2 |
|
3 | 3 | import 'package:flutter/foundation.dart';
|
| 4 | + |
4 | 5 | // backcompatibility for Flutter < 3.3
|
5 | 6 | // ignore: unnecessary_import
|
6 | 7 | import 'package:flutter/material.dart';
|
| 8 | +import 'package:flutter_localizations/flutter_localizations.dart'; |
7 | 9 | import 'package:flutter_test/flutter_test.dart';
|
8 | 10 | import 'package:package_info_plus/package_info_plus.dart';
|
9 | 11 | import 'package:sentry_flutter/sentry_flutter.dart';
|
@@ -104,6 +106,38 @@ void main() {
|
104 | 106 | expect(culture?.timezone, isNotNull);
|
105 | 107 | });
|
106 | 108 |
|
| 109 | + testWidgets( |
| 110 | + 'GIVEN MaterialApp WHEN setting locale and sentryNavigatorKey THEN enrich event culture with selected locale', |
| 111 | + (WidgetTester tester) async { |
| 112 | + GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); |
| 113 | + |
| 114 | + await tester.pumpWidget(MaterialApp( |
| 115 | + navigatorKey: navigatorKey, |
| 116 | + home: Material(), |
| 117 | + localizationsDelegates: const [ |
| 118 | + GlobalMaterialLocalizations.delegate, |
| 119 | + GlobalCupertinoLocalizations.delegate, |
| 120 | + ], |
| 121 | + supportedLocales: const [ |
| 122 | + Locale('en', 'US'), |
| 123 | + Locale('de', 'DE'), |
| 124 | + ], |
| 125 | + locale: const Locale('de', 'DE'), |
| 126 | + )); |
| 127 | + |
| 128 | + final enricher = fixture.getSut( |
| 129 | + binding: () => tester.binding, |
| 130 | + optionsBuilder: (options) { |
| 131 | + options.navigatorKey = navigatorKey; |
| 132 | + return options; |
| 133 | + }, |
| 134 | + ); |
| 135 | + |
| 136 | + final event = await enricher.apply(SentryEvent()); |
| 137 | + |
| 138 | + expect(event?.contexts.culture?.locale, 'de-DE'); |
| 139 | + }); |
| 140 | + |
107 | 141 | testWidgets('app context in foreground', (WidgetTester tester) async {
|
108 | 142 | final enricher = fixture.getSut(
|
109 | 143 | binding: () => tester.binding,
|
@@ -380,16 +414,19 @@ class Fixture {
|
380 | 414 | PlatformChecker? checker,
|
381 | 415 | bool hasNativeIntegration = false,
|
382 | 416 | bool reportPackages = true,
|
| 417 | + SentryFlutterOptions Function(SentryFlutterOptions)? optionsBuilder, |
383 | 418 | }) {
|
384 | 419 | final platformChecker = checker ??
|
385 | 420 | MockPlatformChecker(
|
386 | 421 | hasNativeIntegration: hasNativeIntegration,
|
387 | 422 | );
|
| 423 | + |
388 | 424 | final options = SentryFlutterOptions(
|
389 | 425 | dsn: fakeDsn,
|
390 | 426 | checker: platformChecker,
|
391 | 427 | )..reportPackages = reportPackages;
|
392 |
| - return FlutterEnricherEventProcessor(options); |
| 428 | + final customizedOptions = optionsBuilder?.call(options) ?? options; |
| 429 | + return FlutterEnricherEventProcessor(customizedOptions); |
393 | 430 | }
|
394 | 431 |
|
395 | 432 | PageRoute<dynamic> route(RouteSettings? settings) => PageRouteBuilder<void>(
|
|
0 commit comments