|
2 | 2 |
|
3 | 3 | import 'package:flutter/services.dart';
|
4 | 4 | import 'package:flutter_test/flutter_test.dart';
|
| 5 | +import 'package:mockito/mockito.dart'; |
5 | 6 | import 'package:package_info_plus/package_info_plus.dart';
|
6 | 7 | import 'package:sentry_flutter/sentry_flutter.dart';
|
7 | 8 | import 'package:sentry_flutter/src/integrations/load_contexts_integration.dart';
|
@@ -36,12 +37,61 @@ void main() {
|
36 | 37 | fixture.options.sdk.integrations.contains('loadContextsIntegration'),
|
37 | 38 | true);
|
38 | 39 | });
|
| 40 | + |
| 41 | + test('take breadcrumbs from native if scope sync is enabled', () async { |
| 42 | + fixture.options.enableScopeSync = true; |
| 43 | + |
| 44 | + final eventBreadcrumb = Breadcrumb(message: 'event'); |
| 45 | + var event = SentryEvent(breadcrumbs: [eventBreadcrumb]); |
| 46 | + |
| 47 | + final nativeBreadcrumb = Breadcrumb(message: 'native'); |
| 48 | + Map<String, dynamic> loadContexts = { |
| 49 | + 'breadcrumbs': [nativeBreadcrumb.toJson()] |
| 50 | + }; |
| 51 | + |
| 52 | + final future = Future.value(loadContexts); |
| 53 | + when(fixture.methodChannel.invokeMethod<dynamic>('loadContexts')) |
| 54 | + .thenAnswer((_) => future); |
| 55 | + _channel.setMockMethodCallHandler((MethodCall methodCall) async {}); |
| 56 | + |
| 57 | + final integration = LoadContextsIntegration(fixture.methodChannel); |
| 58 | + integration.call(fixture.hub, fixture.options); |
| 59 | + event = (await fixture.options.eventProcessors.first.apply(event))!; |
| 60 | + |
| 61 | + expect(event.breadcrumbs!.length, 1); |
| 62 | + expect(event.breadcrumbs!.first.message, 'native'); |
| 63 | + }); |
| 64 | + |
| 65 | + test('take breadcrumbs from event if scope sync is disabled', () async { |
| 66 | + fixture.options.enableScopeSync = false; |
| 67 | + |
| 68 | + final eventBreadcrumb = Breadcrumb(message: 'event'); |
| 69 | + var event = SentryEvent(breadcrumbs: [eventBreadcrumb]); |
| 70 | + |
| 71 | + final nativeBreadcrumb = Breadcrumb(message: 'native'); |
| 72 | + Map<String, dynamic> loadContexts = { |
| 73 | + 'breadcrumbs': [nativeBreadcrumb.toJson()] |
| 74 | + }; |
| 75 | + |
| 76 | + final future = Future.value(loadContexts); |
| 77 | + when(fixture.methodChannel.invokeMethod<dynamic>('loadContexts')) |
| 78 | + .thenAnswer((_) => future); |
| 79 | + _channel.setMockMethodCallHandler((MethodCall methodCall) async {}); |
| 80 | + |
| 81 | + final integration = LoadContextsIntegration(fixture.methodChannel); |
| 82 | + integration.call(fixture.hub, fixture.options); |
| 83 | + event = (await fixture.options.eventProcessors.first.apply(event))!; |
| 84 | + |
| 85 | + expect(event.breadcrumbs!.length, 1); |
| 86 | + expect(event.breadcrumbs!.first.message, 'event'); |
| 87 | + }); |
39 | 88 | });
|
40 | 89 | }
|
41 | 90 |
|
42 | 91 | class Fixture {
|
43 | 92 | final hub = MockHub();
|
44 | 93 | final options = SentryFlutterOptions(dsn: fakeDsn);
|
| 94 | + final methodChannel = MockMethodChannel(); |
45 | 95 |
|
46 | 96 | LoadReleaseIntegration getIntegration({PackageLoader? loader}) {
|
47 | 97 | return LoadReleaseIntegration(loader ?? loadRelease);
|
|
0 commit comments