-
Notifications
You must be signed in to change notification settings - Fork 238
/
enable_disable_test.dart
72 lines (56 loc) · 2.14 KB
/
enable_disable_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import 'dart:async';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'utils/mock_lifecycle_provider.dart';
import 'utils/setup_utils.dart';
import 'utils/test_event.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('enable/disable', () {
final mockLifecycleProvider = MockLifecycleProvider();
late Stream<TestEvent> eventsStream;
setUp(() async {
await configureAnalytics(
appLifecycleProvider: mockLifecycleProvider,
);
eventsStream = await subscribeToEvents();
});
testWidgets(
'disable prevents events from being auto flushed and sessions from '
'being auto tracked',
(_) async {
await Amplify.Analytics.disable();
// Wait for all previous events to pass through
final streamSubscription = eventsStream.listen((event) {
fail('Analytics disabled but events were still sent!');
});
const customEventName = 'enable disable event name';
final customEvent = AnalyticsEvent(customEventName);
await Amplify.Analytics.recordEvent(event: customEvent);
// Ensure app background/foreground does not auto send event
mockLifecycleProvider.triggerOnBackgroundListener();
mockLifecycleProvider.triggerOnForegroundListener();
// Give time for events to propagate if they were sent to remote server
// to ensure the failure is not triggered
await Future<void>.delayed(const Duration(minutes: 1));
streamSubscription.cancel();
// Ensure data sent, if sent manually
await Amplify.Analytics.flushEvents();
await expectLater(
eventsStream,
emits(
isA<TestEvent>().having(
(e) => e.eventType,
'eventType',
customEventName,
),
),
);
},
timeout: const Timeout(Duration(minutes: 3)),
);
});
}