|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:sentry/sentry.dart'; |
| 3 | +import 'package:sentry_flutter/src/integrations/flutter_framework_feature_flag_integration.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group(FlutterFrameworkFeatureFlagIntegration, () { |
| 7 | + late Fixture fixture; |
| 8 | + |
| 9 | + setUp(() async { |
| 10 | + fixture = Fixture(); |
| 11 | + |
| 12 | + await Sentry.init((options) { |
| 13 | + options.dsn = 'https://example.com/sentry-dsn'; |
| 14 | + }); |
| 15 | + |
| 16 | + // ignore: invalid_use_of_internal_member |
| 17 | + fixture.hub = Sentry.currentHub; |
| 18 | + // ignore: invalid_use_of_internal_member |
| 19 | + fixture.options = fixture.hub.options; |
| 20 | + }); |
| 21 | + |
| 22 | + tearDown(() { |
| 23 | + Sentry.close(); |
| 24 | + }); |
| 25 | + |
| 26 | + test('adds sdk integration', () { |
| 27 | + final sut = fixture.getSut('foo,bar,baz'); |
| 28 | + sut.call(fixture.hub, fixture.options); |
| 29 | + |
| 30 | + expect( |
| 31 | + fixture.options.sdk.integrations |
| 32 | + .contains('FlutterFrameworkFeatureFlag'), |
| 33 | + true); |
| 34 | + }); |
| 35 | + |
| 36 | + test('adds feature flags', () { |
| 37 | + final sut = fixture.getSut('foo,bar,baz'); |
| 38 | + sut.call(fixture.hub, fixture.options); |
| 39 | + |
| 40 | + // ignore: invalid_use_of_internal_member |
| 41 | + final featureFlags = fixture.hub.scope.contexts[SentryFeatureFlags.type] |
| 42 | + as SentryFeatureFlags?; |
| 43 | + |
| 44 | + expect(featureFlags, isNotNull); |
| 45 | + expect(featureFlags?.values.length, 3); |
| 46 | + expect(featureFlags?.values.first.flag, 'flutter:foo'); |
| 47 | + expect(featureFlags?.values.first.result, true); |
| 48 | + expect(featureFlags?.values[1].flag, 'flutter:bar'); |
| 49 | + expect(featureFlags?.values[1].result, true); |
| 50 | + expect(featureFlags?.values[2].flag, 'flutter:baz'); |
| 51 | + expect(featureFlags?.values[2].result, true); |
| 52 | + }); |
| 53 | + |
| 54 | + test('skips empty', () { |
| 55 | + final sut = fixture.getSut('foo,,bar'); |
| 56 | + sut.call(fixture.hub, fixture.options); |
| 57 | + |
| 58 | + // ignore: invalid_use_of_internal_member |
| 59 | + final featureFlags = fixture.hub.scope.contexts[SentryFeatureFlags.type] |
| 60 | + as SentryFeatureFlags?; |
| 61 | + |
| 62 | + expect(featureFlags, isNotNull); |
| 63 | + expect(featureFlags?.values.length, 2); |
| 64 | + expect(featureFlags?.values.first.flag, 'flutter:foo'); |
| 65 | + expect(featureFlags?.values.first.result, true); |
| 66 | + expect(featureFlags?.values[1].flag, 'flutter:bar'); |
| 67 | + expect(featureFlags?.values[1].result, true); |
| 68 | + }); |
| 69 | + |
| 70 | + test('skips empty variant', () { |
| 71 | + final sut = fixture.getSut(','); |
| 72 | + sut.call(fixture.hub, fixture.options); |
| 73 | + |
| 74 | + // ignore: invalid_use_of_internal_member |
| 75 | + final featureFlags = fixture.hub.scope.contexts[SentryFeatureFlags.type] |
| 76 | + as SentryFeatureFlags?; |
| 77 | + |
| 78 | + expect(featureFlags, isNull); |
| 79 | + }); |
| 80 | + |
| 81 | + test('prettifies', () { |
| 82 | + final sut = fixture.getSut('foo, bar'); |
| 83 | + sut.call(fixture.hub, fixture.options); |
| 84 | + |
| 85 | + // ignore: invalid_use_of_internal_member |
| 86 | + final featureFlags = fixture.hub.scope.contexts[SentryFeatureFlags.type] |
| 87 | + as SentryFeatureFlags?; |
| 88 | + |
| 89 | + expect(featureFlags, isNotNull); |
| 90 | + expect(featureFlags?.values.length, 2); |
| 91 | + expect(featureFlags?.values.first.flag, 'flutter:foo'); |
| 92 | + expect(featureFlags?.values.first.result, true); |
| 93 | + expect(featureFlags?.values[1].flag, 'flutter:bar'); |
| 94 | + expect(featureFlags?.values[1].result, true); |
| 95 | + }); |
| 96 | + }); |
| 97 | +} |
| 98 | + |
| 99 | +class Fixture { |
| 100 | + late Hub hub; |
| 101 | + late SentryOptions options; |
| 102 | + |
| 103 | + FlutterFrameworkFeatureFlagIntegration getSut(String features) { |
| 104 | + return FlutterFrameworkFeatureFlagIntegration(flags: features); |
| 105 | + } |
| 106 | +} |
0 commit comments