Unverified Commit 14aa4d0a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

fix analytics reporting test (#36556)

parent ebdc2cf7
......@@ -156,7 +156,6 @@ class Usage {
...?parameters,
_kLocalTimeParameter: systemClock.now().toString(),
};
_analytics.sendScreenView(command, parameters: paramsWithLocalTime);
}
......@@ -253,11 +252,13 @@ class LogToFileAnalytics extends AnalyticsMock {
super(true);
final File logFile;
final Map<String, String> _sessionValues = <String, String>{};
@override
Future<void> sendScreenView(String viewName, {Map<String, String> parameters}) {
parameters ??= <String, String>{};
parameters['viewName'] = viewName;
parameters.addAll(_sessionValues);
logFile.writeAsStringSync('screenView $parameters\n', mode: FileMode.append);
return Future<void>.value(null);
}
......@@ -271,4 +272,9 @@ class LogToFileAnalytics extends AnalyticsMock {
logFile.writeAsStringSync('event $parameters\n', mode: FileMode.append);
return Future<void>.value(null);
}
@override
void setSessionValue(String param, dynamic value) {
_sessionValues[param] = value.toString();
}
}
......@@ -4,20 +4,22 @@
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/commands/doctor.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/reporting/usage.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import '../src/common.dart';
......@@ -90,17 +92,16 @@ void main() {
when<bool>(mockFlutterConfig.getValue(flutterWebFeature.configSetting))
.thenReturn(true);
final Usage usage = Usage();
usage.suppressAnalytics = false;
usage.enabled = true;
final Future<Map<String, dynamic>> data = usage.onSend.first;
usage.sendCommand('test');
expect(await data, containsPair(enabledFlutterFeatures, 'enable-web'));
expect(fs.file('test').readAsStringSync(), contains('$enabledFlutterFeatures: enable-web'));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
Usage: () => Usage(configDirOverride: tempDir.path),
Config: () => mockFlutterConfig,
Platform: () => FakePlatform(environment: <String, String>{
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
}),
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('Usage records multiple features in experiment setting', () async {
......@@ -111,17 +112,16 @@ void main() {
when<bool>(mockFlutterConfig.getValue(flutterMacOSDesktopFeature.configSetting))
.thenReturn(true);
final Usage usage = Usage();
usage.suppressAnalytics = false;
usage.enabled = true;
final Future<Map<String, dynamic>> data = usage.onSend.first;
usage.sendCommand('test');
expect(await data, containsPair(enabledFlutterFeatures, 'enable-web,enable-linux-desktop,enable-macos-desktop'));
expect(fs.file('test').readAsStringSync(), contains('$enabledFlutterFeatures: enable-web,enable-linux-desktop,enable-macos-desktop'));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
Usage: () => Usage(configDirOverride: tempDir.path),
Config: () => mockFlutterConfig,
Platform: () => FakePlatform(environment: <String, String>{
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
}),
FileSystem: () => MemoryFileSystem(),
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment