add failing test
diff --git a/pkgs/unified_analytics/lib/src/initializer.dart b/pkgs/unified_analytics/lib/src/initializer.dart
index 650388b..1e0ece1 100644
--- a/pkgs/unified_analytics/lib/src/initializer.dart
+++ b/pkgs/unified_analytics/lib/src/initializer.dart
@@ -77,14 +77,14 @@
required Directory homeDirectory,
required FileSystem fs,
}) {
- var firstRun = false;
+ var firstAnalyticsRun = false;
// When the config file doesn't exist, initialize it with the default tools
// and the current date
final configFile = fs.file(
p.join(homeDirectory.path, kDartToolDirectoryName, kConfigFileName));
if (!configFile.existsSync()) {
- firstRun = true;
+ firstAnalyticsRun = true;
createConfigFile(
configFile: configFile,
fs: fs,
@@ -120,5 +120,5 @@
createDismissedSurveyFile(dismissedSurveyFile: dismissedSurveyFile);
}
- return firstRun;
+ return firstAnalyticsRun;
}
diff --git a/pkgs/unified_analytics/test/unified_analytics_test.dart b/pkgs/unified_analytics/test/unified_analytics_test.dart
index 2e78df4..4f369b2 100644
--- a/pkgs/unified_analytics/test/unified_analytics_test.dart
+++ b/pkgs/unified_analytics/test/unified_analytics_test.dart
@@ -1272,4 +1272,81 @@
expect(parseDartSDKVersion(originalVersion), '3.3.0');
});
});
+
+ otherTest();
}
+
+
+void otherTest() {
+ late MemoryFileSystem fs;
+ late Directory home;
+
+ const homeDirName = 'home';
+ const toolsMessageVersion = 1;
+ const toolsMessage = 'toolsMessage';
+ const flutterChannel = 'flutterChannel';
+ const flutterVersion = 'flutterVersion';
+ const dartVersion = 'dartVersion';
+ const platform = DevicePlatform.macos;
+
+ setUp(() {
+ // Setup the filesystem with the home directory
+ final fsStyle =
+ io.Platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix;
+ fs = MemoryFileSystem.test(style: fsStyle);
+ home = fs.directory(homeDirName);
+
+ });
+
+ test(
+ 'running a second tool for the first time does not re-enable analytics',
+ () async {
+ // This is the first analytics instance that will be used to demonstrate
+ // that events will not be sent with the first run of analytics
+ final firstDartToolAnalytics = Analytics.fake(
+ tool: DashTool.dartTool,
+ homeDirectory: home,
+ flutterChannel: flutterChannel,
+ toolsMessageVersion: toolsMessageVersion,
+ toolsMessage: toolsMessage,
+ flutterVersion: flutterVersion,
+ dartVersion: dartVersion,
+ fs: fs,
+ platform: platform,
+ );
+ expect(firstDartToolAnalytics.shouldShowMessage, true);
+ expect(firstDartToolAnalytics.okToSend, isFalse);
+ firstDartToolAnalytics.clientShowedMessage();
+ expect(firstDartToolAnalytics.shouldShowMessage, false);
+
+ final secondDartToolAnalytics = Analytics.fake(
+ tool: DashTool.dartTool,
+ homeDirectory: home,
+ flutterChannel: flutterChannel,
+ toolsMessageVersion: toolsMessageVersion,
+ toolsMessage: toolsMessage,
+ flutterVersion: flutterVersion,
+ dartVersion: dartVersion,
+ fs: fs,
+ platform: platform,
+ );
+ expect(secondDartToolAnalytics.okToSend, isTrue);
+
+ await secondDartToolAnalytics.setTelemetry(false);
+
+ final flutterToolAnalytics = Analytics.fake(
+ tool: DashTool.flutterTool,
+ homeDirectory: home,
+ flutterChannel: flutterChannel,
+ toolsMessageVersion: toolsMessageVersion,
+ toolsMessage: toolsMessage,
+ flutterVersion: flutterVersion,
+ dartVersion: dartVersion,
+ fs: fs,
+ platform: platform,
+ );
+
+ expect(flutterToolAnalytics.shouldShowMessage, isTrue);
+ expect(flutterToolAnalytics.okToSend, isFalse);
+ });
+}
\ No newline at end of file